New submission from Marcel <mpv.vis...@gmail.com>:
After instantiation of a variable of a DataClass, it is possible to assign new attributes (that were not defined in defining the DataClass): data.new_attribute = 3.0 # does NOT raise Error! This gives unexpected behaviour: if you print the variable, then 'new_attribute' is not printed (since it is not in the definition of the DataClass). Assigning to an attribute is therefore not typo-safe (which users may expect from a DataClass). I would expect the behaviour of the DataClass be consistent and typo-safe. Attached is a file that demonstrates the bug (behaviour) and provides a 'SafeDataClass' by overriding the __setattr__ method. My suggestion would be to the adjust the library __setattr__ for the DataClass such that is will be typo-safe. ---------- components: Library (Lib) files: bug_demo_dataclass_typo_unsafe.py messages: 360752 nosy: marcelpvisser priority: normal severity: normal status: open title: DataClass typo-unsafe attribute creation & unexpected behaviour (dataclasses) type: behavior versions: Python 3.7, Python 3.8, Python 3.9 Added file: https://bugs.python.org/file48865/bug_demo_dataclass_typo_unsafe.py _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39462> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com