-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
False positive used-before-assignment
in pattern matching with a guard.
#5327
Comments
This bug is still present in:
Here my example code import sys
match sys.argv[1:]: # vvvvvvvvv Using variable 'direction' before assignment
case ["go", direction] if direction in ["up", "down", "left", "right"]:
print(f"going {direction}")
case command:
print(f"unknown command: {' '.join(command)}") |
Also hitting this false-positive, is there a plan to include this in an upcoming release? |
I too suffer from this issue |
I'm running into the same issue using:
My testcase: def describe(i: int) -> str:
match i:
case n if n % 2 == 0:
return "even"
case _:
return "odd" |
If the same variable is used as a match guard twice, pylint won't complain the second time. l = [7, 7]
match l:
case [_, n] if n >= 4: # E0601: Using variable 'n' before assignment
print("hi")
t = (4, "abc")
match t:
case (n, _) if n < 12: # not triggered here
print("hi") If the line version:
|
Bug description
When using pattern matching with a guard,
pylint
claims that the variable the guard uses is used before assignment.Example:
Configuration
No response
Command used
Pylint output
Expected behavior
Pattern matching with guards is correctly parsed and supported.
Pylint version
OS / Environment
Mac OSX Big Sur 11.6 (20G165)
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: