So, I am a bit new to Python, and also a bit new to OOP paradigm, and recently I've encountered something that seems a bit counter-intuitive. For instance, look at the code below (run on Python 3.9):
from collections.abc import Container
class OddContainer:
def __contains__(self, x):
if not isinstance(x, int) or not x%2:
return False
return True
if __name__ == '__main__':
x = OddContainer()
print(isinstance(x, Container))
The print here will output True, indicating that OddContainer is a subclass of Container, but OddContainer class did not explicitly specify its superclasses.
Can somebody tell me what exactly is going on here? Is it correct to say that any class that has a __contains__() method overloaded internally becomes subclass of the Container class, or is that a naive interpretation? If the former is correct, than are there any other cases where this inheritance through method overloading occurs?
Thanks in advance.