New submission from Hugo Ricateau <hugo.ricat...@gmail.com>:
Assume one has defined the following descriptor: ``` class Descriptor: def __set__(self, instance, value): print('SET') ``` On the one hand, for the class-instance pair, the behaviour is as follows: ``` class FirstClass: descriptor = Descriptor() def __init__(self): self.descriptor = None FirstClass().descriptor = None ``` results in "SET" being displayed twice; i.e. both assignations triggered the __set__ method of the descriptor. On the other hand, for the metaclass-class pair, the behaviour is the following: ``` class SecondClassMeta(type): descriptor = Descriptor() class SecondClass(metaclass=SecondClassMeta): descriptor = None SecondClass.descriptor = None ``` results in "SET" being displayed only once: the first assignation (the one in the class definition) did not triggered __set__. It looks to me like an undesirable asymmetry between the descriptors behaviour when in classes vs when in metaclasses. Is that intended? If it is, I think it should be highlighted in the descriptors documentation. Best ---------- components: Interpreter Core messages: 360623 nosy: Hugo Ricateau priority: normal severity: normal status: open title: Inhomogeneous behaviour for descriptors in between the class-instance and metaclass-class pairs type: behavior versions: Python 3.6, Python 3.7, Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39443> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com