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
Mypy does not see HasNothingButSlots as a valid subtype of of HasX, so complains about this code. Pyright, however, does see HasNothingButSlots as a valid subtype of HasX, so has no complaints.
Currently, the runtime agrees with mypy: calling isinstance(HasNothingButSlots(), HasX) evaluates to False (due to the fact that the x variable has not been initialised on the instance). If we implement any of the patches discussed in #1363, this will change, and the runtime will agree with pyright: isinstance(HasNothingButSlots(), HasX) will evaluate to True even if the x variable has not been initialised on the instance.
Who is correct: mypy or pyright?
The text was updated successfully, but these errors were encountered:
AlexWaygood
changed the title
How should structural subtyping work for objects with slots?
How should structural subtyping work for objects with slots but no variable declarations?
Mar 9, 2023
Consider the snippet below:
Mypy does not see
HasNothingButSlots
as a valid subtype of ofHasX
, so complains about this code. Pyright, however, does seeHasNothingButSlots
as a valid subtype ofHasX
, so has no complaints.Currently, the runtime agrees with mypy: calling
isinstance(HasNothingButSlots(), HasX)
evaluates toFalse
(due to the fact that thex
variable has not been initialised on the instance). If we implement any of the patches discussed in #1363, this will change, and the runtime will agree with pyright:isinstance(HasNothingButSlots(), HasX)
will evaluate toTrue
even if thex
variable has not been initialised on the instance.Who is correct: mypy or pyright?
The text was updated successfully, but these errors were encountered: