June 2019
Beginner to intermediate
770 pages
19h 24m
English
We can also do some management of the implementation of concrete methods with type hints and the typing module. A concrete class will be checked by mypy to be sure it matches the abstract class type hints. This is not as stringent as the checks made by the ABCMeta class, since they don't happen at runtime, but only when mypy is used. We can do this by using raise NotImplementedError in the body of an abstract class. This will create a runtime error if the application actually creates an instance of an abstract class.
The concrete subclasses define the methods normally. The presence of type hints means mypy can confirm that the subclass provides a proper definition that matches the superclass type hints. This ...
Read now
Unlock full access