Designing objects with type hints
The Python type hints provide considerable help in defining objects for a shelf. Throughout this chapter, we'll emphasize the use of the @dataclass decorator to create objects suitable for persistence.
The data class concept is helpful because it makes the attributes that define object state extremely clear. The attributes are not concealed inside method definitions. Without @dataclass, the attributes are often implied by the __init__() method. In some classes, however, attributes are defined dynamically, making the attributes inconsistent and leading to possible problems in recovering object state from a shelved representation.
The pickle module is used to do the serialization of the objects. For more information ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access