Loading topic
.read() method, you can call .read() on it. That flexibility is useful, but it has a cost. When many classes are supposed to share one set of methods, nothing in the language says which methods are required, and nothing compla6 min readABC helper class, the ABCMeta metaclass, and what each one adds to a class you write. It assumes you can define classes and use inheritance, know what a decorator is, and can read a try/except block. You should also know tha6 min readtry/except. It also assumes you know that ABC is the base class that gives a class abstract behavior. Here you will look at what @abstractmethod does to a function, how Python decides whic5 min read@abstractmethod on an ABC subclass. Here you will learn exactly when Python enforces the abstract-method contract, what the error tells you, and which edge cases bypass or surprise the check.4 min read@abstractmethod and the TypeError Python raises when you instantiate an incomplete subclass. It also assumes you can read basic try/except code.5 min read@property decorator, @abstractmethod, and what TypeError on instantiation means for an incomplete s5 min read@abstractmethod blocks instantiation of incomplete subclasses and how @classmethod and @staticmethod behave on ordinary classes. It covers how to combine them, what the abstract check does and does not cover, and the gotchas that follow.5 min read@abstractmethod blocks instantiation, and can read try/except. It covers how isinstance and issubclass behave when the second argument is an abstract base class (ABC), how that differs from plain classes, and where the ch5 min read__len__ and __getitem__, and have read the earlier chapters on @abstractmethod and the instantiation check. The collections.abc module is where the standard library applies those ideas. I4 min read@abstractmethod and that you know what isinstance and issubclass return for ordinary inheritance. An ABC normally gets its subclasses through inheritance. register is the second way: you declare that an existing class counts as a subclass witho4 min read@abstractmethod blocks instantiation and how isinstance and issubclass work with ABCs. It also assumes you have seen register, which makes a class a virtual subclass. __subclasshook__ is the third way a class can count as a subclass of an ABC. The class do4 min readABC and @abstractmethod work, including the instantiation check, register, and __subclasshook__. It also assumes you have seen type hints. You don't need to have used typing.Protocol before.5 min read@abstractmethod, you know how register and __subclasshook__ work, and you have seen typing.Protocol. It collects the mistakes that catch people in practice and ends with rules for deciding when an abstract base class (ABC) is the right tool.5 min read