I've been experimenting to deepen my understanding of Python's behavior in 
regard to metaclasses, descriptors, and other meta-programming stuff. In the 
process, I have come across a behavior that is presumably by design but cannot 
be inferred from anything I can find in the official documentation. Because of 
that, I can't be certain whether the behavior I'm seeing is by design or just 
happens to work this way in CPython.

What I'm seeing is that, if a class and its metaclass both have assigned 
descriptors to the same attribute name, then the descriptor in the metaclass is 
employed when interacting with the attribute of the class, and the descriptor 
in the class is employed when interacting with an instance of the class.

This allows things that would not otherwise be possible, such as having a 
setter fat the class level or having different getters for a class and its 
instances.
Does anyone know of anywhere in the Python docs or PEPs that have the 
information needed to predict this behavior?
-- 
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to