Message392065
This is just how Python works. The default values for .x and .y are set on the class A, not its instances. Here's the equivalent without dataclasses:
>>> class A:
... x = 0
... y = 1
...
>>> a = A()
>>> a.x
0
>>> a.y
1
>>> a.__dict__
{}
>>> A.__dict__
mappingproxy({'__module__': '__main__', 'x': 0, 'y': 1, '__dict__': <attribute '__dict__' of 'A' objects>, '__weakref__': <attribute '__weakref__' of 'A' objects>, '__doc__': None})
Note that the instance "a" has nothing in its __dict__, but the values A.x and A.y are none the less available through the instance "a".
The only way to avoid this would be for @dataclass to delete the values from A, but that's not a change I'd be willing to make.
Is this causing some actual problem in any code? |
|
Date |
User |
Action |
Args |
2021-04-27 12:46:28 | eric.smith | set | recipients:
+ eric.smith, superbobry |
2021-04-27 12:46:28 | eric.smith | set | messageid: <1619527588.69.0.386433738767.issue43953@roundup.psfhosted.org> |
2021-04-27 12:46:28 | eric.smith | link | issue43953 messages |
2021-04-27 12:46:28 | eric.smith | create | |
|