TypeGuard
has no effect when nested in the presence of other problems
#17138
Labels
bug
mypy got something wrong
Bug Report
A
TypeGuard
declared and used near the top of a function is sometimes rendered ineffective (i.e., there is no change to the type of the first argument to theTypeGuard
even when theTypeGuard
returns True), but only when there is an apparently-unrelated mypy-detectable problem later in the same function.The problem does not occur if the
TypeGuard
definition is not nested within an outer function, or if the apparently-unrelated problem is corrected.Because any erroneous errors triggered by this bug appear above the triggering problem in the error report, users will find it difficult to solve this issue if they approach the problem using a [run mypy, fix first issue, repeat] workflow.
To Reproduce
[mypy-play.net]
Expected Behavior
The
TypeGuard
invocation at line 16 should change the type ofarg
toint
when theif
statement's condition is truthy. Theassert_type()
on line 17 should pass.Actual Behavior
The
TypeGuard
has no effect on the type of its argument.Your Environment
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: