Eric V. Smith <e...@trueblade.com> added the comment:
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? ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue43953> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com