We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeIs
Bug Report
Applying TypeIs to narrow type of an iterable results in too optimistic reachability analysis.
To Reproduce
from collections.abc import Iterable from typing_extensions import TypeIs def is_iterable_int(val: Iterable[object]) -> TypeIs[Iterable[int]]: return all(isinstance(item, int) for item in val) bar: list[int] | list[str] if is_iterable_int(bar): reveal_type(bar) else: reveal_type(bar)
playground has more code, including TypeGuard comparison and non-iterable case that works correctly.
TypeGuard
Expected Behavior
I'd expected both branches to be reachable and to narrow type according to the spec: list[int] in if and list[str] in else, ideally.
list[int]
if
list[str]
else
Actual Behavior
main.py:11: note: Revealed type is "builtins.list[builtins.int]" main.py:13: error: Statement is unreachable [unreachable]
Your Environment
--warn-unreachable
mypy.ini
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Bug Report
Applying
TypeIs
to narrow type of an iterable results in too optimistic reachability analysis.To Reproduce
playground has more code, including
TypeGuard
comparison and non-iterable case that works correctly.Expected Behavior
I'd expected both branches to be reachable and to narrow type according to the spec:
list[int]
inif
andlist[str]
inelse
, ideally.Actual Behavior
Your Environment
--warn-unreachable
mypy.ini
(and other config files): N/AThe text was updated successfully, but these errors were encountered: