This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.smith
Recipients eric.smith, superbobry
Date 2021-04-27.12:46:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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
>>> a.y
>>> 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:28eric.smithsetrecipients: + eric.smith, superbobry
2021-04-27 12:46:28eric.smithsetmessageid: <>
2021-04-27 12:46:28eric.smithlinkissue43953 messages
2021-04-27 12:46:28eric.smithcreate