Skip to content
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

Misleading line number in match parse error #2658

Closed
TmLev opened this issue Nov 30, 2021 · 4 comments
Closed

Misleading line number in match parse error #2658

TmLev opened this issue Nov 30, 2021 · 4 comments
Labels
T: bug Something isn't working

Comments

@TmLev
Copy link

TmLev commented Nov 30, 2021

Describe the bug

Attempt to format match expression with comma results in parsing error with misleading line number in error message.

To Reproduce

MRE:

x = 1

match x:
    case 1 | 2:
        print("1 or 2")
    case _:
        print("Not 1 or 2")

match x, x + 1:
    case 1, 2:
        print("1 and 2")

Format command:

black --target-version py310 example.py

The resulting error is:

error: cannot format example.py: Cannot parse: 3:6: match x:
Oh no! 💥 💔 💥
1 file failed to reformat.

And no errors are appearing if the last match expression is removed:

x = 1

match x:
    case 1 | 2:
        print("1 or 2")
    case _:
        print("Not 1 or 2")

... OR x, x + 1 and 1, 2 are replaced with (x, x + 1) and (1, 2):

x = 1

match x:
    case 1 | 2:
        print("1 or 2")
    case _:
        print("Not 1 or 2")

match (x, x + 1):
    case (1, 2):
        print("1 and 2")

Expected behavior

No errors (?).

Environment

  • Black's version: black, 21.11b1 (compiled: no)
  • OS and Python version: Mac OS 11.4, Python 3.10.0
@TmLev TmLev added the T: bug Something isn't working label Nov 30, 2021
@TmLev TmLev changed the title Misleading line number on invalid match parse error Misleading line number on match parse error Nov 30, 2021
@TmLev TmLev changed the title Misleading line number on match parse error Misleading line number in match parse error Nov 30, 2021
@isidentical
Copy link
Collaborator

isidentical commented Nov 30, 2021

Seems similar to #2637 and #2648, can you check the same example with the latest black installed from main? (this should allow parsing multiple values, for the error reporting, I guess that is still in progress)

@TmLev
Copy link
Author

TmLev commented Dec 1, 2021

Yeah, everything works with the version from main.
Closing as duplicate?

@isidentical
Copy link
Collaborator

Yep both the syntax and the error messages (thanks to @JelleZijlstra on #2649) seem to be fixed now.

@TmLev
Copy link
Author

TmLev commented Dec 1, 2021

Okay, thanks.
Waiting for a new release.

@TmLev TmLev closed this as completed Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants