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
importrematch=re.match(r"(?P<grade>LD|MD|HD)(?P<material>AL|SS)", "HDSS")
match (match.group("grade"), match.group("material")):
case ("MD"|"HD", "SS"ascode):
print("You will get here")
And run it with these arguments:
$ black file.py --target-version py310 # or --target-version py311
The resulting error is:
cannot format foo.py: Cannot parse: 3:0: match (match.group("grade"), match.group("material")):
Expected behavior
Sure, the local variable name should be something else, but it's valid python and Python will run it perfectly fine. If Python is cool with it, then black should support it. (Even if it's poor taste in variable names; valid Python should not break black)
Environment
Black's version: 22.12.0
OS and Python version: docker run -it --rm python:3.11 bash
Workarounds
Black works if you use a different variable name:
the_match=re.match(r"(?P<grade>LD|MD|HD)(?P<material>AL|SS)", "HDSS")
match (the_match.group("grade"), the_match.group("material")):
case_:
pass
This simply proves the issue is with the variable name being match.
Black works also if you refactor the code to separate the local variable match and the keyword match:
match=re.match(r"(?P<grade>LD|MD|HD)(?P<material>AL|SS)", "HDSS")
grade, material=match.group("grade"), match.group("material")
match (grade, material): # local variable `match` not used herecase_:
pass
An interesting case where Black works with match in the same line is:
Describe the bug
Take this code:
And run it with these arguments:
$ black file.py --target-version py310 # or --target-version py311
The resulting error is:
Expected behavior
Sure, the local variable name should be something else, but it's valid python and Python will run it perfectly fine. If Python is cool with it, then black should support it. (Even if it's poor taste in variable names; valid Python should not break black)
Environment
docker run -it --rm python:3.11 bash
Workarounds
Black works if you use a different variable name:
This simply proves the issue is with the variable name being
match
.Black works also if you refactor the code to separate the local variable
match
and the keywordmatch
:An interesting case where Black works with
match
in the same line is:The text was updated successfully, but these errors were encountered: