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

bpo-34013: Move the Python 2 hints from the exception constructor to the parser #27392

Merged
merged 1 commit into from Jul 27, 2021

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Jul 27, 2021

@pablogsal
Copy link
Member Author

pablogsal commented Jul 27, 2021

CC: @ammaraskar this was the PR I had prepared. If you want, we could explore incorporate your suggestions here

@ammaraskar
Copy link
Member

ammaraskar commented Jul 27, 2021

Nice: image


My thinking for suggesting Did you mean print(...) (not sure if the one with end=' ' is worth the added rule) is that this is the type of mistake which beginners are likely to make while blindly following an outdated tutorial or copying a snippet. For those cases, it's almost better to be verbose and show close to what change they should make rather than just say "missing parentheses" which might be too jargony.

@pablogsal
Copy link
Member Author

pablogsal commented Jul 27, 2021

My thinking for suggesting Did you mean print(...) (not sure if the one with end=' ' is worth the added rule) is that this is the type of mistake which beginners are likely to make while blindly following an outdated tutorial or copying a snippet. For those cases, it's almost better to be verbose and show close to what change they should make rather than just say "missing parentheses" which might be too jargony.

I am a bit skeptical but I trust your juzguement. I have updated the PR with the changes you propose :)

_PyPegen_check_legacy_stmt(p, a) ? RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "Missing parentheses in call to '%U'.", a->v.Name.id) : NULL}

| a=NAME b=star_expressions {
_PyPegen_check_legacy_stmt(p, a) ? RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b,
Copy link
Member

@ammaraskar ammaraskar Jul 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do the carets for this end up? If they're at the end of the expression, LGTM.

Copy link
Member Author

@pablogsal pablogsal Jul 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>>> print a+b, c+d, f()
  File "<stdin>", line 1
    print a+b, c+d, f()
    ^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

>>> 3,4 , [print 3+4, 6+7, 8], 34
  File "<stdin>", line 1
    3,4 , [print 3+4, 6+7, 8], 34
           ^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

>>> print {3+4, 6+7, 8}, 45, 6
  File "<stdin>", line 1
    print {3+4, 6+7, 8}, 45, 6
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

>>> (print {3+4, 6+7, 8}, 45, 6), 5
  File "<stdin>", line 1
    (print {3+4, 6+7, 8}, 45, 6), 5
     ^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

Copy link
Member

@ammaraskar ammaraskar Jul 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect 👌

@pablogsal pablogsal merged commit ecc3c8e into python:main Jul 27, 2021
12 checks passed
@pablogsal pablogsal deleted the bpo-34013 branch Jul 27, 2021
@miss-islington
Copy link
Contributor

miss-islington commented Jul 27, 2021

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒🤖

@bedevere-bot
Copy link

bedevere-bot commented Jul 27, 2021

GH-27393 is a backport of this pull request to the 3.10 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 27, 2021
…the parser (pythonGH-27392)

(cherry picked from commit ecc3c8e)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
miss-islington added a commit that referenced this pull request Jul 27, 2021
…the parser (GH-27392)

(cherry picked from commit ecc3c8e)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants