
On 27/11/21 11:34 am, Eric V. Smith wrote:
Would adding something to the Iterator ABC really also add it to my class Foo?
No, your class would need changing to inherit from the Iterator ABC. This is a big problem in general with "just add it to the ABC" ideas. A huge number of existing classes don't inherit from the relevant ABC because there currently isn't any need to do so. Fundamentally, Python is not organised around the concept of ABCs the way some other languages such as Java are. Instead, it's organised around informal protocols. They're informal in the sense that there's no need to inherit from a particular class in order to conform -- you just implement the required methods and you're good to go. As a consequence, there is strong pressure to keep the number of required methods to a minimum. It also means that adding required methods to a protocol late in the life of the language is effectively impossible. -- Greg