June 2019
Beginner to intermediate
770 pages
19h 24m
English
Most of the time, we create an initial collection of attributes using the __init__() method of a class. Ideally, we provide names and default values for all the attributes in __init__().
While it's not required to provide all attributes in the __init__() method, it's the place mypy checks to gather the expected list of attributes of an object. An optional attribute can be used as part of an object's state, but there aren't easy ways to describe the absence of an attribute as a valid state for an object.
An optional attribute also pushes the edge of the envelope in terms of class definition. A class is defined by the unique collection of attributes. Attributes are best added (or removed) by creating a subclass ...
Read now
Unlock full access