[Python-ideas] Fwd: Define a method or function attribute outside of a class with the dot operator

Chris Angelico rosuav at gmail.com
Fri Feb 10 09:25:40 EST 2017

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.


More information about the Python-ideas mailing list