[Python-Dev] PEP487: Simpler customization of class creation

Nick Coghlan ncoghlan at gmail.com
Sun Jul 24 23:49:39 EDT 2016


On 25 July 2016 at 03:00, Guido van Rossum <gvanrossum at gmail.com> wrote:
> Yes.

OK, we can cover that in the documentation - if folks want to emulate
what happens during class construction after the fact, they'll need to
do:

    cls.name = attr
    attr.__set_name__(cls, "name")

Semantically, I agree that approach makes sense - by default,
descriptors created outside a class body won't have a defined owning
class or attribute name, and if you want to give them one, you'll have
to do it explicitly.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list