You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incompatible signature in method with restricted overload for a generic class #12151
When a method of a generic class has an overload for a particular type of the generic parameter, subclasses that don't have that particular value should be able to override the method without that overload, but currently aren't.
I don't think that's generally safe. What if the base class A contains the following?
x: Tdefother_method(self):
self.method(self.x)
Now if you call B().other_method(), the function B.method will get called with a None argument.
The problem is that when analyzing A, we don't know whether T has been bound to None, so the trick you're using to detect A[None] doesn't work in this case.
Sorry, forget what I said. My analysis was incorrect.
I think the issue is that mypy is validating the method implementation signature in the child class against the implementation signature in the parent class, but you want it to take into account the overload signatures in the child class as well.
Activity
erictraut commentedon Feb 8, 2022
I don't think that's generally safe. What if the base class
Acontains the following?Now if you call
B().other_method(), the functionB.methodwill get called with aNoneargument.The problem is that when analyzing
A, we don't know whetherThas been bound toNone, so the trick you're using to detectA[None]doesn't work in this case.vnmabus commentedon Feb 8, 2022
Sorry, but I don't get it. Surely
xshould have anintvalue inB, no?erictraut commentedon Feb 8, 2022
Sorry, forget what I said. My analysis was incorrect.
I think the issue is that mypy is validating the method implementation signature in the child class against the implementation signature in the parent class, but you want it to take into account the overload signatures in the child class as well.
vnmabus commentedon Feb 8, 2022
Yeah, I think that is something sensible to do. In fact, requiring me to provide the first overload is wrong.
erictraut commentedon Aug 13, 2023
I think this bug has been fixed. The latest version of mypy (1.5) no longer generates an error.
hauntsaninja commentedon Aug 13, 2023
I fixed this in #14882