![](https://secure.gravatar.com/avatar/d67ab5d94c2fed8ab6b727b62dc1b213.jpg?s=120&d=mm&r=g)
On Sun, 23 Jul 2023 at 09:15, Dom Grigonis <dom.grigonis@gmail.com> wrote:
This works ok:
``` def foo(bar=None): if bar is None: bar = A()
class A: pass ```
If PEP is aiming to replace the latter example, then it would be great if it kept all of its advantages. I.e. not having to change the definition order in the module, which could be preferred as it is for other reasons.
Well, yes, it would work, but I still wouldn't recommend it. This is confusing to read. But since the default would be evaluated at call time, it would behave exactly as you describe.
And also to come back to my previous notice that there is no way to enforce the default in case of function chain with cascading arguments. You said it is a known limitation. Is there no easy & sensible approach to not have it? E.g.:
a) Any object which has certain dunder attribute, which evaluates to True? b) NotGiven sentinel value which does exactly that. c) A special constant, which, if present, at lower level makes things behave the same way as the argument wasn’t provided at all. Such constant could be very useful outside the scope of this PEP as well. Could be a great place to introduce such constant? And to me it seems it could be a well justified one, given it actually is special and does not fall under umbrella of generic sentinel values.
It would be great if it was to retain all the benefits of the latter example. Then (at least from my POV) this PEP would be an excellent addition, and I am most likely be using it now if it existed.
There is no way to have a value that isn't a value, in Python. The concept doesn't make sense and would break all kinds of things. (That's why, when a special function like __getitem__ has to be able to return literally anything, it signals "nothing to return" by raising an exception.) The only way to not pass an argument in Python is to not pass it. That means, at best, something like *a or **kw, where the sequence/dict either has something or doesn't, depending on whether you want to pass the argument. None of this is changed by PEP 671 and I don't think there's a lot of point trying to, as it would only cause more problems elsewhere. ChrisA