flâneur — a map of the web's best reading

dataclasses — Data Classes — Python 3.12.6 documentation

docs.python.org · 5,478 words · saved by 1 readers

This module provides a decorator and functions for automatically adding generated special methods such as __init__() and __repr__() to user-defined classes. It was originally described in PEP 557. The member variables to use in these generated methods are defined using PEP 526 type annotations. For example, this code: will add, among other things, a __init__() that looks like: Note that this method is automatically added to the class: it is not directly specified in the InventoryItem definition shown above. Added in version 3.7. This function is a decorator that is used to add generated special methods to classes, as described below. The @dataclass decorator examines the class to find fields. A field is defined as a class variable that has a type annotation. With two exceptions described below, nothing in @dataclass examines the type specified in the variable annotation. The order of the fields in all of the generated methods is the order in which they appear in the class definition. T

dataclasses — Data Classes — Python 3.14.6 documentation Navigation index modules | next | previous | Python » 3.14.6 Documentation » The Python Standard Library » Python Runtime Services » dataclasses — Data Classes | Theme Auto Light Dark | dataclasses — Data Classes ¶ Source code: Lib/dataclasses.py This module provides a decorator and functions for automatically adding generated special methods such as __init__() and __repr__() to user-defined classes. It was originally described in PEP 557 . The member variables to use in these generated methods are defined using

Explore this link on the map →

related reading