Author Wombatz
Recipients Wombatz
Date 2016-11-25.02:48:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This behavior occurs at least in python-3.6.0b3 and python-3.6.0b4.

Modifying the class __dict__ inside the __set_name__ method of a descriptor that is used inside that class can lead to a bug that possibly prevents other descriptors from being initialized (the call to their __set_name__ is prevented).

That happens because internally the cpython interpreter iterates the class __dict__ when calling all the __set_name__ methods. Changing the class __dict__ while iterating it leads to undefined behavior. This is the line in the source code

See the attached file for an example where the bug can be observed. It defines a "desc" class that implements the __set_name__ method where it prints the name and modifies the class __dict__ of the containing class. Later a class is defined that has multiple instances of the "desc" class as class attributes. Depending on the number of attributes not all of them are initialized.

When you see the underlying C-Code the reason for this behavior is obvious but in python itself the problem might not be apparent.

To fix this bug the class __dict__ could be cashed and then the __set_name__ methods could be called while iterating over that copy.
Date User Action Args
2016-11-25 02:48:29Wombatzsetrecipients: + Wombatz
2016-11-25 02:48:29Wombatzsetmessageid: <>
2016-11-25 02:48:28Wombatzlinkissue28797 messages
2016-11-25 02:48:27Wombatzcreate