-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
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
Types not narrowed with constrained TypeVar and walrus #12190
Comments
Hmm, this should work, and I can't repro: Closing because I'm fairly confident mypy supports this, but feel free to re-open if you have a playground link like^ or a self-contained script that reproduces. |
Looks like it only happens with It works fine if I use |
if
with walrus operator
Thanks! |
I have a related issue with mypy==1.3.0, python 3.10.4. Given test_mypy.py containing: test = ['a', 'b', 'c']
if any((_t := itm) == 'c' for itm in test):
print(f'{_t=}')
else:
_t = None
print(_t) output: >mypy test_mypy.py
test_mypy.py:3: error: Name "_t" is used before definition [used-before-def]
Found 1 error in 1 file (checked 1 source file) Let me know if the problem is unique enough warrant its own issue (or if such an issue already exists) or if it's not a problem for some reason I'm not seeing... |
The issue I described doesn't seem to fit with the type-narrowing tag, so I'm opening a new one for this. |
This issue was fixed in #14135 |
Bug Report
It's not entirely clear to me if the existing issues regarding the walrus operator are about the same issue, feel free to close this if they are.
With the following code:
I get this error:
Even though it's impossible for
m
to beNone
, because we just checked its value in theif
.There are no errors with this code:
Your Environment
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: