'How list_iterator is sub-class of Iterator even though MROs are different?
I have the following code. From the output the MROs are different but still issubclass returns true. Can someone explain how Python finds they are equal?
My understanding is that MRO show the inheritance tree of classes. And classes with different inheritance tree (MRO) should not satisfy sub-class validation. I am using Python-3.9.5 on Windows-10
Code
from collections.abc import Iterator
it_type = type(iter([]))
print(it_type.__mro__)
print(Iterator.__mro__)
print(issubclass(it_type, Iterator))
Output
(<class 'list_iterator'>, <class 'object'>)
(<class 'collections.abc.Iterator'>, <class 'collections.abc.Iterable'>, <class 'object'>)
True
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
