September 2026
1051 pages
35h 4m
English
The principle of function decorators can be applied in a similar way as class decorators, with the only difference being that the object to be manipulated is not a function but a class.
From Chapter 19, Section 19.12, you already know about the data classes that are defined using a class decorator:
>>> import dataclasses>>> @dataclasses.dataclass... class SomeDataClass:... python: str... works: int... well: list>>> SomeDataClass("Test", 123, ["A", "B", "C"])SomeDataClass(python='Test', works=123, well=['A', 'B', 'C'])
Much like the previous examples on function decorators, this definition of a data class can also be formulated as follows:
>>> class AnotherDataClass:... python: str... works: int... well: list>>> AnotherDataClass ...
Read now
Unlock full access