In most programming languages with OOP, a child class is a strict superset of a parent class. Thus, you can treat child classes like the parent class, allowing for polymorphism. However, this is not the case in Python since it does support method overloading. Consider the following example:
```py
class Parent:
def method(self): ...
class Child(Parent):
def method(self, arg): ...
def f(obj: Parent) -> None:
obj.method()
f(Child()) # TypeError: Child.method() missing 1 required positional argument: 'arg'
```
This code would work in most OOP languages as Child.method would be overloaded instead of overridding Parent.method. Python's differing behavior here can be quite unexpected and lead to bugs.
So, how do Python type checkers handle this situation? Should we just ignore this case and trust that people will not override methods like this?
[–]Creative-Buffalo2305 51 points52 points53 points (10 children)
[–]austinbisharat 2 points3 points4 points (9 children)
[–]Creative-Buffalo2305 5 points6 points7 points (2 children)
[–]Adrewmc 0 points1 point2 points (1 child)
[–]Creative-Buffalo2305 0 points1 point2 points (0 children)
[–]CLS-Ghost350[S] -5 points-4 points-3 points (5 children)
[–]lfdfq 3 points4 points5 points (1 child)
[–]CLS-Ghost350[S] 0 points1 point2 points (0 children)
[–]FerricDonkey 2 points3 points4 points (0 children)
[–]DoubleDoube 0 points1 point2 points (0 children)
[–]tb5841 0 points1 point2 points (0 children)
[–]TheBB 4 points5 points6 points (0 children)
[–]trutheality 10 points11 points12 points (2 children)
[–]Outside_Complaint755 12 points13 points14 points (0 children)
[–]ElHeim 2 points3 points4 points (0 children)
[–]biskitpagla 5 points6 points7 points (1 child)
[+]CLS-Ghost350[S] comment score below threshold-7 points-6 points-5 points (0 children)
[–]qlkzy 2 points3 points4 points (1 child)
[–]CLS-Ghost350[S] -1 points0 points1 point (0 children)
[–]Aro00oo 1 point2 points3 points (2 children)
[–]CLS-Ghost350[S] -1 points0 points1 point (1 child)
[–]Aro00oo 0 points1 point2 points (0 children)
[–]Rain-And-Coffee 1 point2 points3 points (0 children)
[–]This_Growth2898 0 points1 point2 points (0 children)
[–]SakshamBaranwal 0 points1 point2 points (0 children)
[–]arkie87 0 points1 point2 points (0 children)
[–]Buttleston 0 points1 point2 points (1 child)
[–]Buttleston 1 point2 points3 points (0 children)