
Chris Angelico wrote:
On Wed, 27 Jul 2022 at 21:54, Mathew Elman mathew.elman@ocado.com wrote:
I don't see why you couldn't. I guess what they do depends if any of these have defaults? Which I think they do not in this case, right? If they were non vanilla dictionaries that had a default e.g. class SomeDict(dict): def __getitem__(self, item=None): return super().__getitem__(item) def __contains__(self, item=None): return super().__contains__(item)
So Undefined would trigger a default, but only if there is one? print(b[1]) would still print Undefined because print's first argument doesn't have a default. But print doesn't have a first argument - it accepts *args. So Undefined still counts as an argument, except when there's a default, at which point it counts as a non-argument?
Yes, I guess you could do it so that for var args it was treated as a non argument? so print(Undefined) == print() ? But that seems even more surprising...
a in c would be False. That is VERY surprising behaviour. For literally any other object, that would be True. But then, it would be surprising in other ways if Undefined behaved like a normal object. c[a] would return c[None], which would raise an error here because None isn't in the mapping Again, very surprising, if putting a value into a mapping doesn't result in that value being in the mapping.
Yes, compared with other objects, there would need to be some surprising behaviour because it isn't a concept in python already. You could fix this specific problem with mappings by changing Undefined to not be hashable, but that is definitely a bandaid.
Again, I am not pro this idea, just answering the questions you're asking as I see them :) Yeah. I think you're doing a great job of showing why this is a bad idea :)
I do think the desire to fix the "wrapper not needing to know the defaults of wrapped" problem is admirable. Is this the right approach? No, I think not.