IT IS AN OBJECT. Never said otherwise. `inspect.getcallargs` can seemingly be modified for such behaviour. I just wrote a decorator, which does what I proposed using `inspect` module for a chosen sentinel value. The issue is that it would be a bottleneck if used on any callable, which is continuously used. `inspect.getcallargs`, `signature`, `getfullargspec` are very expensive. If that can be done, theoretically it should be able to be done at lower level as well. After all, behaviour of it should be modelled after what is happening at the function call.
On 23 Jul 2023, at 06:58, Chris Angelico <rosuav@gmail.com> wrote:
On Sun, 23 Jul 2023 at 12:20, Dom Grigonis <dom.grigonis@gmail.com> wrote:
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.)
I accept that it might be difficult to implement. I see that it would break things at cpython. Will definitely break some of the stdlib. E.g. inspect stuff. It wouldn’t break any of the existing python code. So yes, might not be a minor change.
Could it be done nicely and easily by someone with relevant experience? I don’t know.
But I fail to see why it doesn’t make sense - that’s a strong statement.
It would be a value, just a value that is treated with exception in this particular case. There is definitely code at that level - resolving args, kwargs, dealing with “/" and “*” in relation to arguments provided, etc.
It would take effect only on keyword arguments with defaults, if so then fairly contained matter. It could be a default of a keyword argument itself, would have a type and everything as any other object.
Okay. You now have an object that you can't do anything with, because it can't be a function argument. So...
Show me how you would put this value into a dictionary.
Show me how you would find out the type of this value.
Show me how you would refer to this in an exception.
Show me how you would access an attribute of this object.
Show me how you would do ANYTHING WHATSOEVER with this object.
It does not make sense to have an object that isn't an object. And in Python, every value *is* an object.
ChrisA