-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
PEP 572 Walrus Operator Regex Assignment in Condition #8447
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
Closed
Labels
bug
mypy got something wrong
false-positive
mypy gave an error on correct code
priority-1-normal
topic-strict-optional
Comments
Yeah, type inference doesn't seem to work correctly here. As a workaround, you can remove the import re
TXT = "b"
if a := re.search(r"a", TXT): # <<-- removed the None check
string = a.string # No error here
print(f"{string}")
else:
print("not in there") |
msullivan
added a commit
that referenced
this issue
Feb 28, 2020
It is a pretty simple matter of pulling out the assignment target from the walrus. We don't bother handling things like `x := (y := z)` since I can't imagine they are common enough to be worth bothering but we could in the future if anyone cares. Fixes #8447.
Same issue as in #8236 |
msullivan
added a commit
that referenced
this issue
Feb 28, 2020
It is a pretty simple matter of pulling out the assignment target from the walrus. We don't bother handling things like `x := (y := z)` since I can't imagine they are common enough to be worth bothering but we could in the future if anyone cares. Fixes #8447.
msullivan
added a commit
that referenced
this issue
Mar 9, 2020
It is a pretty simple matter of pulling out the assignment target from the walrus. We don't bother handling things like `x := (y := z)` since I can't imagine they are common enough to be worth bothering but we could in the future if anyone cares. Fixes #8447.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
mypy got something wrong
false-positive
mypy gave an error on correct code
priority-1-normal
topic-strict-optional
Mypy version: 0.761
Python version: 3.8.1
#6899 implements
PEP 572
, or at least parts of it, as mentioned in the PR assignments can occur anywhere. Fails with an example similar to here withregex
.Minimal Example:
mypy message:
but the type of
a
is notOptional[Match[str]]
it'sMatch[str]
as a result of the if check.The text was updated successfully, but these errors were encountered: