The abc and typing modules
The core method of creating ABCs is defined in the abc module. This module includes the ABCMeta class, which provides several features.
First, the ABCMeta class ensures that abstract classes can't be instantiated. When a method uses the @asbtractmethod decorator, then a subclass that fails to provide this definition cannot be instantiated. A subclass that provides all of the required definitions for the abstract methods can be instantiated properly.
Second, it provides definitions for __instancecheck__() and __subclasscheck__(). These special methods implement the isinstance() and issubclass() built-in functions. They provide the checks to confirm that an object (or a class) belongs to the proper ABC. This includes ...
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