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
We know with certainty that variable a is of type A, so having a case to check whether it's an instance of B (which is not a subtype of A) makes no sense and indicates a type error. Yet the latest Mypy version (1.5.1) doesn't report it as one. In my opinion, it would be better if it did (and that would have been my expectation before I tested it), given that all necessary type information is explicit & static and doesn't even have to be inferred.
Objections I could think of
One could object that this isn't that different from a feature request asking that similarly "impossible" isinstance checks be treated as errors, but I would say they are different in that match/case is part of the syntax, while isinstance is "just a function" and giving its arguments special treatment (= extra type checking that takes into account its semantics) would seem odd.
Feature
It would be great if Mypy could detect and report as errors
case
patterns that are not possible given the type of the variable beingmatch
ed on.Pitch
Consider e.g.:
We know with certainty that variable
a
is of typeA
, so having acase
to check whether it's an instance ofB
(which is not a subtype ofA
) makes no sense and indicates a type error. Yet the latest Mypy version (1.5.1) doesn't report it as one. In my opinion, it would be better if it did (and that would have been my expectation before I tested it), given that all necessary type information is explicit & static and doesn't even have to be inferred.Objections I could think of
One could object that this isn't that different from a feature request asking that similarly "impossible"
isinstance
checks be treated as errors, but I would say they are different in thatmatch
/case
is part of the syntax, whileisinstance
is "just a function" and giving its arguments special treatment (= extra type checking that takes into account its semantics) would seem odd.Related issues
The text was updated successfully, but these errors were encountered: