Top "Python-dataclasses" questions

For questions concerning the Python dataclasses module (new in Python 3.7). Dataclasses are python classes but are specifically suited for storing data objects.

Data Classes vs typing.NamedTuple primary use cases

Long story short PEP-557 introduced data classes into Python standard library, that basically can fill the same role as collections.…

python namedtuple pep python-3.7 python-dataclasses
Why is `dataclasses.asdict(obj)` > 10x slower than `obj.__dict__()`

I am using Python 3.6 and the dataclasses backport package from ericvsmith. It seems that calling dataclasses.asdict(my_dataclass) is ~10…

python python-dataclasses
How to create an optional field in a dataclass that is inherited?

from typing import Optional @dataclass class Event: id: str created_at: datetime updated_at: Optional[datetime] #updated_at: datetime = field(…

python python-3.x python-dataclasses
How can dataclasses be made to work better with __slots__?

It was decided to remove direct support for __slots__ from dataclasses for Python 3.7. Despite this, __slots__ can still be used …

python python-3.x slots python-dataclasses
How does one ignore extra arguments passed to a data class?

I'd like to create a config dataclass in order to simplify whitelisting of and access to specific environment variables (typing …

python python-3.x python-dataclasses
How do I document a constructor for a class using Python dataclasses?

I have some existing Python 3.6 code that I'd like to move to Python 3.7 dataclasses. I have __init__ methods with nice …

python documentation python-3.7 docstring python-dataclasses