type: ignore for “incompatible with supertype” error in subclass should suffice for subsubclasses too #10197
Labels
feature
topic-inheritance
Inheritance and incompatible overrides
topic-type-ignore
# type: ignore comments
Mypy playground link
Mypy is correct to report an error for
B.foo
that necessitated atype: ignore
comment. However, having added thattype: ignore
forB.foo
, mypy should not also report an error forC.foo
. AlthoughC.foo
is inconsistent withA.foo
, it’s consistent withB.foo
, and I have already asked mypy to ignore the inconsistency betweenB.foo
andA.foo
.To put this another way, I recognize that mypy would fail to catch the runtime error in
a: A = C(); a.foo("str")
, but this would still be a runtime error ifC.foo
did not overrideB.foo
, so the blame should be assigned solely toB.foo
and not toC.foo
.This comes up in the typeshed stubs for
markdown.inlinepatterns
:These stubs correctly reflect the upstream API which uses
handleMatch
with a different signature in subclasses ofInlineProcessor
than in other subclasses ofPattern
. That wasn’t a great API design decision, but now that it’s made and thetype: ignore
was added toInlineProcessor.handleMatch
, ideally I shouldn’t have to repeat the sametype: ignore
in order to write a custom subclass ofInlineProcessor
whosehandleMatch
satisfies the signature ofInlineProcessor.handleMatch
.The text was updated successfully, but these errors were encountered: