|
|
|
|
|
by dfee
2951 days ago
|
|
The problem with dataclasses are: 1) they don’t support __slots__ and default values 2) type hints aren’t supported yet, and it doesn’t appear they’ll be added to the 3.6 backport The former issue will be resolved (maybe in 3.8?) but it will require either a metaclass approach or the @dataclass decorator to build a separate class. The good news is that dataclasses (the backport) work on PyPy 6.0.0. |
|
EDIT: From PEP 557: https://www.python.org/dev/peps/pep-0557/#support-for-automa...
“Support for automatically setting __slots__?
At least for the initial release, __slots__ will not be supported. __slots__ needs to be added at class creation time. The Data Class decorator is called after the class is created, so in order to add __slots__ the decorator would have to create a new class, set __slots__, and return it. Because this behavior is somewhat surprising, the initial version of Data Classes will not support automatically setting __slots__. There are a number of workarounds:
- Manually add __slots__ in the class definition.
- Write a function (which could be used as a decorator) that inspects the class using fields() and creates a new class with __slots__ set.”