The `dataclasses` library is a backport of the standard library `dataclasses` module, designed specifically for Python 3.6. It provides the `@dataclass` decorator and related utilities, enabling simpler creation of data-holding classes without boilerplate. Its current version is 0.8. As it targets a specific, older Python version, its release cadence is stable and infrequent, with no new feature development anticipated.
pip install dataclassesVerified import paths — ran on the pinned version, not inferred.
Define a simple data class using the `@dataclass` decorator. Note the `from __future__ import annotations` which is highly recommended for type hints in Python 3.6 to handle forward references and complex types gracefully. Mutable default values for fields should use `default_factory`.
Remove `dataclasses` from your project's dependencies when upgrading to Python 3.7 or newer. The standard library module will be used automatically.
Add `from __future__ import annotations` at the top of your module, or use string literal type hints for any forward references or complex generic types.
If these newer features are required, consider upgrading your Python environment to 3.10 or newer. There is no workaround to enable these features in the 3.6 backport.
Install the backport library using pip: `pip install dataclasses`
Rearrange your dataclass fields, or fields in parent classes, so that all fields without default values are defined before any fields with default values.
Use `dataclasses.field(default_factory=...)` to provide a zero-argument callable that returns a new mutable object for each instance. For example, `my_list: List[int] = field(default_factory=list)`.
Either ensure `init=True` (the default) for the dataclass or the field, or if `init=False` is necessary, explicitly initialize the field in a custom `__init__` or `__post_init__` method, calling the `default_factory` manually.
No dependency data recorded yet.