[Python-ideas] Eliminating special method lookup (was Re: Missing Core Feature: + - * / | & do not call __getattr__)
Brendan Barnwell
brenbarn at brenbarn.net
Sat Dec 5 00:55:43 EST 2015
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"? To me the term "magic methods" just means the
ones that are implicitly invoked by syntax (e.g., operator overloading),
and what those are is already documented.
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.
---
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is no
path, and leave a trail."
--author unknown
More information about the Python-ideas
mailing list