1.16 changed behavior of redefined variable to None #19280
Labels
bug
mypy got something wrong
topic-strict-optional
topic-type-narrowing
Conditional type narrowing / binder
https://github.com/mesonbuild/meson/blob/master/mesonbuild/cmake/fileapi.py
This file started triggering:
due to reuse of
for i in ......:
Reduction:
With mypy 1.16.0
It starts off as Path, gets redefined as Any (which works?), but then asserting the Any is a dict results in it migrating to None. With mypy 1.15, it never redefined to Any at all, so it became unreachable:
I can't really say either behavior is useful. I want variables to be block-scoped and reset their expected value. But at least the 1.15 behavior was comprehensible to me. The new behavior only works if I delete the assert, which seems terribly counterproductive.
The text was updated successfully, but these errors were encountered: