June 2019
Beginner to intermediate
770 pages
19h 24m
English
We can create objects where attributes are computed from a single, centralized __getattr__() method. When attribute values are computed by separate properties, the presence of many methods can be a convenient way to encapsulate a variety of algorithms. In some cases, however, it might be sensible to combine all of the computations into a single method. In this case, the names of the attributes are essentially invisible to mypy, since they aren't an obvious part of the Python source text.
A single computation method is shown in the following example:
class RTD_Solver: def __init__( self, *, rate: float = None, time: float = None, distance: float = None ) -> None: if rate: self.rate = rate if time: self ...
Read now
Unlock full access