python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.55k stars 2.84k forks source link

Fix incorrect "Incompatible types in capture pattern" error for narrowed types #18155

Open shenyih0ng opened 1 week ago

shenyih0ng commented 1 week ago

Fixes #16736

github-actions[bot] commented 1 week ago

Diff from mypy_primer, showing the effect of this PR on open source code:

Expression (https://github.com/cognitedata/Expression)
+ expression/extra/parser.py:263: error: Class "expression.collections.block.Block[Any]" has no attribute "_value"  [misc]
+ expression/extra/parser.py:264: error: Cannot determine type of "tail"  [has-type]
+ expression/extra/parser.py:265: error: Cannot determine type of "head"  [has-type]
github-actions[bot] commented 1 week ago

Diff from mypy_primer, showing the effect of this PR on open source code:

Expression (https://github.com/cognitedata/Expression)
+ expression/extra/parser.py:263: error: Class "expression.collections.block.Block[Any]" has no attribute "_value"  [misc]
+ expression/extra/parser.py:264: error: Cannot determine type of "tail"  [has-type]
+ expression/extra/parser.py:265: error: Cannot determine type of "head"  [has-type]
github-actions[bot] commented 1 week ago

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅