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

Markus Meskanen markusmeskanen at gmail.com
Fri Feb 10 11:09:25 EST 2017


But if people are gonna do it anyways with the tools provided (monkey
patching), why not provide them with better tools? And this wouldn't only
be for classes, but for setting instance attributes too (see the Menu
example in original mail).

- Markus

On Fri, Feb 10, 2017 at 5:38 PM, Steve Dower <steve.dower at python.org> wrote:

> 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.
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170210/49c97a88/attachment.html>


More information about the Python-ideas mailing list