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
When using the match-case block with a case case statement (syntax allowed since Python 3.10), Black fails to parse the code if the line length is set to a small number.
To Reproduce
Consider the following code:
matchtest:
casecaseifTrue:
pass
This code can be correctly formatted by Black when the line length is reduced to 14, as shown below (playground link)
matchtest:
case (
case
) ifTrue:
pass
However, when the line length is further decreased to 13 or below, Black will not be able to parse the code, (see playground link)
This issue can also be reproduced locally:
PS > cat temp.py
match test:
casecaseif True:
pass
PS > python -m black temp.py --line-length 13
error: cannot format temp.py: Cannot parse: 5:8: if True
Oh no! 💥 💔 💥
1 file failed to reformat.
PS > python -m black temp.py --line-length 1
error: cannot format temp.py: Cannot parse: 3:8: if True
Oh no! 💥 💔 💥
1 file failed to reformat.
Expected behavior
With line length set to be lower than 13, the output format should remain as
JelleZijlstra
changed the title
Crush on formatting case case syntax when line length set to be small
Crash on formatting case case syntax when line length set to be small
Mar 15, 2024
Describe the bug
When using the
match-case
block with acase case
statement (syntax allowed since Python 3.10), Black fails to parse the code if the line length is set to a small number.To Reproduce
Consider the following code:
This code can be correctly formatted by Black when the line length is reduced to 14, as shown below (playground link)
However, when the line length is further decreased to 13 or below, Black will not be able to parse the code, (see playground link)
This issue can also be reproduced locally:
Expected behavior
With line length set to be lower than 13, the output format should remain as
Environment
PS > black --version black, 24.2.0 (compiled: yes) Python (CPython) 3.10.7
The text was updated successfully, but these errors were encountered: