August 2018
Intermediate to advanced
332 pages
9h 12m
English
By using type annotations (as recommended previously in Chapter 1, Introduction, Code Formatting, and Tools), throughout our code, and configuring Mypy, we can quickly detect some basic errors early, and check basic compliance with LSP for free.
If one of the subclasses of the Event class were to override a method in an incompatible fashion, Mypy would notice this by inspecting the annotations:
class Event: ... def meets_condition(self, event_data: dict) -> bool: return Falseclass LoginEvent(Event): def meets_condition(self, event_data: list) -> bool: return bool(event_data)
When we run Mypy on this file, we will get an error message saying the following:
error: Argument 1 of "meets_condition" ...