[New-bugs-announce] [issue39443] Inhomogeneous behaviour for descriptors in between the class-instance and metaclass-class pairs
Hugo Ricateau
report at bugs.python.org
Fri Jan 24 10:17:34 EST 2020
New submission from Hugo Ricateau <hugo.ricateau at 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 <report at bugs.python.org>
<https://bugs.python.org/issue39443>
_______________________________________
More information about the New-bugs-announce
mailing list