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
type(var) is type(other) not considered enough #11952
First of all, thanks a lot for your work on mypy and the Python ecosystem in general!
I am sorry if this has been reported before (I would imagine it probably has, but searching for things like "type" and "is" is, well, difficult). It seems that mypy does not realize that type(a) is type(b) is at least as strong a guarantee (well, actually, stronger) than isinstance(a, type(b)).
To Reproduce
(Write your steps here:)
Run mypy --strict on the attached program (saving it with a .py extension beforehand).
Watch it complain about the _bad functions returning Any instead of the declared type.
Run the program to see that it, indeed, works.
Expected Behavior
No diagnostic messages from mypy.
Actual Behavior
Complaints about functions that check that type(result) is type(value).
Your Environment
Checked both with Python 3.9 + mypy 0.921 and Python 3.8 + mypy 0.910 on Debian testing. In both cases mypy was invoked with --strict --python-version 3.8 and no additional configuration.
Activity
AlexWaygood commentedon Mar 30, 2022
Reproduced — here's a mypy playground link for convenience: https://mypy-play.net/?mypy=latest&python=3.10&flags=strict&gist=14692aca9f6feb80977f6eb744b8e14d
Narrow for type expr comparisons to type exprs (#20639)