.. role:: python(code) :language: python .. index:: dataclasses Dataclasses ----------- When working with classes, a lot of boiler-plate code is often required: always :python:`__init__, __repr__`, often :python:`__eq__, __lt__` for comparisons, often :python:`__hash__` when instances are used in sets or as dict keys, sometimes 'neutral representation' :python:`astuple, asdict` as an export interface. `Dataclasses `_ does the job for you and are a huge time saver. .. note:: It seems at first glance that **class** attributes are defined. However, this syntax in the context of a dataclass is called a ``field``. It will actually create class instances with independent attributes. To explicitly define a class attribute, the :python:`typing.ClassVar` type is required. .. literalinclude:: ../../../../src/tools_methods/useful_modules/dataclasses_usage.py :name: dataclasses_usage :linenos: :caption: dataclasses_usage