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
When Self is used as a method parameter type (e.g. other: Self), mypy allows constructing unsound inheritance structures where it accepts a non-self value at runtime.
Concretely, consider a parent class which defines a method with a Self parameter, and a child class which overrides that method. The child class would also define the parameter type as Self, which would allow it to treat the object as an instance of itself. But the child can be assigned to a variable of the parent type, in which case a method call on the (static) parent variable with (dynamic) child value, mypy will accept values of the parent type for the method call.
An example based on the unsoundness proof from JelleZijlstra/unsoundness. Note how reveal_type shows that the inferred static type is str, while the runtime type is int.
I'm honestly not sure what the expected behavior should be. pyright rejects the method override. I think that's a sensible approach, but I can not judge what other consequences it might have.
I'm not 100% certain this is a mypy bug. I don't exclude the possibility that this is an issue with the typing spec, rather than with mypy specifically. But based on the fact that pyright does reject this, I'm assuming that labeling it as a bug is appropriate.
Actual Behavior
# from running mypy on the snippet
main.py:27: note: Revealed type is "str"
# from running the snippet
Runtime type is 'int'
Your Environment
Mypy version used: 1.20.2
Mypy command-line flags:
Mypy configuration options from mypy.ini (and other config files):
Activity
sanderr commentedon May 7, 2026
Thanks. I had searched for duplicates, but there were so many search results for applicable keywords that I didn't manage to find a match.