[IPython-dev] Metaclasses in traitlets and PEP 487

Martin Teichmann lkb.teichmann at gmail.com
Wed Feb 17 07:56:35 EST 2016


Hi Sylvain,

> My understanding is that the new `__set_owner__` method on the descriptor exactly corresponds to the `class_init` in our base Descriptor class, that is the part of the descriptor initialization that depends on the class (while `instance_init` is the part of the initialization that depends on the instance). However, it sometimes does a bit more than setting the name of the owner, like in the case of the default initializers. Hence I was wondering if the name was accurate. What do you think about simply reusing `__class_init__`?

There was some discussion on python-ideas about that name.
It is an extension to the descriptor protocol, which already has three
methods: __set__, __get__ and
__delete__. How should we name the new method?

I personally don't like __class_init__, I think it is actually
misleading, as it is called on an object, not a class.
Originally, I had it called __init_descriptor__. Others considered
that misleading, because in the
new metaclass there is also an __init_subclass__, and one might think
that __init_descriptor__ is also
called on the initialized class, but it is called on the descriptor.
This is where the name __set_owner__ came
from, as in __get__ the parameter is called owner. But given that not
only the owner is set, but also the
name of the descriptor, __set_owner__ also might not be the best choice.

Greetings

Martin



More information about the IPython-dev mailing list