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

Matt Gilson matt at getpattern.com
Mon Feb 13 14:50:09 EST 2017

For whatever weight my opinion holds, I'm +0 on this one.  In my
estimation, in an ideal world it seems like:

    class Foo(object):
         def bar(self):

    # Identical to:

    class Foo(object): pass

    def Foo.bar(self):

But I think that's going to be hard to achieve given implicit binding of
`super` (as some have already mentioned) and more mind-bendingly when
user-defined metaclasses are in play.  Indeed, with metaclasses, it seems
like it become impossible to actually guarantee the equality of the above
two blocks of code.  Maybe the PEP writers are OK with that, but that
should be decided at the outset...

Also note that if users start adopting this as their default mode of class
creation (rather than just *class extending*), code-folding in a lot of
IDEs won't handle it gracefully (at least not for quite a while).

On Mon, Feb 13, 2017 at 11:32 AM, Joseph Hackman <josephhackman at gmail.com>

> Generally speaking, I'm +1 on this idea, I think it would make code more
> readable, especially for tools like IDEs.
> I just wanted to ask: can someone point me to the reason Python doesn't
> support referencing a class inside it's own definition? It seems like that
> would solve some of the cases discussed here, and with Type hinting that
> seems like something that maybe should be considered?
> _______________________________________________
> 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/


[image: pattern-sig.png]


E: matt at getpattern.com // P: 603.892.7736

We’re looking for beta testers.  Go here
<https://www.getpattern.com/meetpattern> to sign up!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170213/d6c1362c/attachment.html>

More information about the Python-ideas mailing list