[Python-ideas] Eliminating special method lookup (was Re: Missing Core Feature: + - * / | & do not call __getattr__)
Andrew Barnert
abarnert at yahoo.com
Sat Dec 5 01:25:04 EST 2015
On Dec 4, 2015, at 21:55, Brendan Barnwell <brenbarn at brenbarn.net> wrote:
>
>> On 2015-12-04 12:02, Andrew Barnert wrote:
>> So, maybe the way to get from here to there is to explicitly document
>> the methods CPython treats as magic methods, and allow only allow
>> other implementations to do the same for (a subset of) the same, and
>> people can gradually tackle and remove parts of that list as people
>> come up with ideas, and if the list eventually becomes empty (or gets
>> to the point where it's 2 rare things that aren't important enough to
>> keep extra complexity in the language), then the whole notion of
>> special method lookup can finally go away.
>
> Presumably you mean "treats as magic methods for the purposes of this lookup short-circuiting"?
Yes; sorry it's not clear without the context, but that's what I meant.
> If that's what you mean, I agree that would be a good starting point. I am always nervous when the docs say the kind of thing they say for this, which is "implicit special method lookup generally also bypasses the __getattribute__() method even of the object’s metaclass". "Generally"? What does that mean? It seems to me that whether and when __getattribute__ is called should be a clearly-specified part of the semantics of magic methods, and it's somewhat disturbing that it doesn't seem to be.
Well, I think it may be a good thing that Python allows other implementations to not skip the normal lookup steps.
But yes, at the very least, there should be a list of exactly which methods are allowed to do that, rather than a vague description, and an implementation note mentioning exactly which ones do so in CPython.
More information about the Python-ideas
mailing list