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
{{ message }}
Repository navigation
Type narrowing for ellipsis via 'is ...' failing in 1.9.0 #17002
As of mypy 1.9.0, narrowing of unions containing EllipsisType via the expressions if x is ... or if x is Ellipsis no longer works. In both branches of the if statement, the type of x still contains EllipsisType instead of being narrowed.
This narrowed as expected in 1.8.0.
As a workaround, it appears that if instanceof(x, EllipsisType) still works as expected.
mypy 1.8.0 shows no errors because x was narrowed to int in the else clause:
Success: no issues found in 1 source file
Actual Behavior
mypy 1.9.0 reports an error instead:
tmp.py:8: error: Unsupported operand types for + ("EllipsisType" and "int") [operator]
tmp.py:8: note: Left operand is of type "int | EllipsisType"
Found 1 error in 1 file (checked 1 source file)
Your Environment
Mypy version used: 1.9.0
Mypy command-line flags: none
Mypy configuration options from mypy.ini (and other config files): none
Activity
JelleZijlstra commentedon Mar 9, 2024
Probably related to python/typeshed#11223. I suspect some of these need to be updated:
Fix type narrowing for types.EllipsisType
Fix type narrowing for types.EllipsisType (#17003)
hauntsaninja commentedon Mar 10, 2024
@dhirving Thank you for the issue. I'll add https://github.com/lsst/daf_butler to mypy_primer so we detect regressions against it
dhirving commentedon Mar 11, 2024
Thanks for the prompt fix! I replied to the ticket on mypy_primer as well -- we'd love to be included in the regression suite.
Add mypy GitHub Action workflow
Dogfood the just-built image for mypy
Dogfood the just-built image for mypy
Pin mypy below 2.0
Pin mypy below 2.0
Bake CI dev tools (mypy, pytest, stubs, xdist) into the image
Bake CI dev tools (mypy, pytest, stubs, xdist) into the image