[Python-ideas] Fwd: Define a method or function attributeoutside of a class with the dot operator
steve.dower at python.org
Fri Feb 10 10:38:18 EST 2017
Since votes seem to be being counted and used for debate purposes, I am -1 to anything that encourages or condones people adding functionality to classes outside of the class definition. (Monkeypatching in my mind neither condones or encourages, and most descriptions come with plenty of caveats about how it should be avoided.)
My favourite description of object-oriented programming is that it's like "reading a road map through a drinking(/soda/pop) straw". We do not need to tell people that it's okay to make this problem worse by providing first-class tools to do it.
Top-posted from my Windows Phone
From: "Chris Angelico" <rosuav at gmail.com>
Sent: 2/10/2017 8:27
To: "Python-Ideas" <python-ideas at python.org>
Subject: Re: [Python-ideas] Fwd: Define a method or function attributeoutside of a class with the dot operator
On Sat, Feb 11, 2017 at 1:16 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> But what do __name__ and __qualname__ get set to?
> What happens if you do this at class scope, rather than at module
> level or inside another function?
> What happens to the zero-argument super() support at class scope?
> What happens if you attempt to use zero-argument super() when *not* at
> class scope?
> These are *answerable* questions...
... and are exactly why I asked the OP to write up a PEP. This isn't
my proposal, so it's not up to me to make the decisions.
For what it's worth, my answers would be:
__name__ would be the textual representation of exactly what you typed
between "def" and the open parenthesis. __qualname__ would be built
the exact same way it currently is, based on that __name__.
Zero-argument super() would behave exactly the way it would if you
used a simple name. This just changes the assignment, not the creation
of the function. So if you're inside a class, you could populate a
lookup dictionary with method-like functions. Abuse this, and you're
only shooting your own foot.
Zero-argument super() outside of a class, just as currently, would be
an error. (Whatever kind of error it currently is.)
Maybe there are better answers to these questions, I don't know.
That's what the PEP's for.
Python-ideas mailing list
Python-ideas at python.org
Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas