Skip to content

dataclasses

Built-in record-class helpers. Works without Shared Library research. Generates concise user-class value objects; use TypedDict for JSON-shaped records.

dataclasses.dataclass(cls?, /, *, init=True, repr=True, eq=True, order=False, kw_only=False, unsafe_hash=False, frozen=False, slots=False, weakref_slot=False)

Section titled “dataclasses.dataclass(cls?, /, *, init=True, repr=True, eq=True, order=False, kw_only=False, unsafe_hash=False, frozen=False, slots=False, weakref_slot=False)”

Decorate a class to generate declaration-ordered construction, representation, value equality, and optional ordering. Supports both @dataclass and @dataclass(...), inherited fields, __post_init__, and explicit-method preservation. Generated behavior is controlled by init, repr, eq, order, and kw_only. Compatibility flags unsafe_hash, frozen, slots, and weakref_slot may be passed only as False; their True behavior and every unlisted standard-library option are rejected rather than ignored. Dataclass instances remain ordinary user objects and cannot cross JSON-shaped game API boundaries.

ParameterDescription
clsOptional class for functional or bare-decorator use
initGenerate __init__ (default True)
reprGenerate __repr__ (default True)
eqGenerate exact-class __eq__ (default True)
orderGenerate ordering methods (default False)
kw_onlyMake generated constructor fields keyword-only (default False)
unsafe_hash / frozen / slots / weakref_slotCompatibility flags; only False is supported

Returns: any

dataclasses.field(*, default?, default_factory?, init=True, repr=True, compare=True, kw_only?)

Section titled “dataclasses.field(*, default?, default_factory?, init=True, repr=True, compare=True, kw_only?)”

Configure one annotated dataclass field. Use default for an immutable or hashable shared value, or default_factory for a zero-argument factory that creates an independent value per instance; supplying both is an error. Mutable or otherwise unhashable direct defaults are rejected and must use default_factory. init controls constructor inclusion, repr controls generated display, compare controls equality and ordering, and kw_only controls that field’s constructor position. Field metadata/introspection, hash, and every unlisted standard-library option are not supported.

ParameterDescription
defaultOptional immutable or hashable shared value
default_factoryOptional zero-argument factory
initInclude this field in the generated constructor (default True)
reprInclude this field in generated representation (default True)
compareInclude this field in generated equality and ordering (default True)
kw_onlyMake this constructor field keyword-only

Returns: any

  • Writing Classes: dataclasses in context, with the full support and exclusion list