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
In the example, I expected the TypeGuard function to work no differently from the inlined type checks.
Actual Behavior
When using TypeGuard, the variable seems to be properly narrowed (revealed_type() within the branch is identical), but it seems somehow the result isn't recorded identically as the inlined checks. In the function using TypeGuard, the exhaustiveness check is not passing.
Your Environment
Mypy version used: 1.3.0
Mypy command-line flags: -
Mypy configuration options from mypy.ini (and other config files): -
Python version used: 3.11
The text was updated successfully, but these errors were encountered:
Mypy is correct here. TypeGuard does not perform narrowing in the negative (else) case. For the reasoning behind this, you can refer to PEP 647. There has been some discussion of adding a variant called StrictTypeGuard that is more limited than TypeGuard but allows negative type narrowing. This would require a new PEP, and it hasn't made it beyond the discussion phase yet.
Uh oh!
There was an error while loading. Please reload this page.
Bug Report
Narrowing with a
TypeGuard
function doesn't work in conjunction with exhaustiveness checking usingassert_never()
.To Reproduce
https://mypy-play.net/?mypy=latest&python=3.11&gist=b6bc8609a83ff0538459d658c74f23ea
Expected Behavior
In the example, I expected the
TypeGuard
function to work no differently from the inlined type checks.Actual Behavior
When using
TypeGuard
, the variable seems to be properly narrowed (revealed_type()
within the branch is identical), but it seems somehow the result isn't recorded identically as the inlined checks. In the function usingTypeGuard
, the exhaustiveness check is not passing.Your Environment
mypy.ini
(and other config files): -The text was updated successfully, but these errors were encountered: