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

Confusing parsing error message when trying to use True as keyword argument #89879

Closed
cfbolz mannequin opened this issue Nov 4, 2021 · 3 comments
Closed

Confusing parsing error message when trying to use True as keyword argument #89879

cfbolz mannequin opened this issue Nov 4, 2021 · 3 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@cfbolz
Copy link
Mannequin

cfbolz mannequin commented Nov 4, 2021

BPO 45716
Nosy @cfbolz, @aroberge, @lysnikolaou, @pablogsal
PRs
  • bpo-45716: Improve the error message when using True/False/None as keywords in a call #29413
  • [3.10] bpo-45716: Improve the error message when using True/False/None as keywords in a call (GH-29413) #29428
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-11-05.13:57:15.486>
    created_at = <Date 2021-11-04.17:45:48.986>
    labels = ['interpreter-core']
    title = 'Confusing parsing error message when trying to use True as keyword argument'
    updated_at = <Date 2021-11-16.22:31:49.761>
    user = 'https://github.com/cfbolz'

    bugs.python.org fields:

    activity = <Date 2021-11-16.22:31:49.761>
    actor = 'pablogsal'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-11-05.13:57:15.486>
    closer = 'pablogsal'
    components = ['Parser']
    creation = <Date 2021-11-04.17:45:48.986>
    creator = 'Carl.Friedrich.Bolz'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 45716
    keywords = ['patch']
    message_count = 3.0
    messages = ['405741', '405798', '406439']
    nosy_count = 4.0
    nosy_names = ['Carl.Friedrich.Bolz', 'aroberge', 'lys.nikolaou', 'pablogsal']
    pr_nums = ['29413', '29428']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue45716'
    versions = []

    @cfbolz
    Copy link
    Mannequin Author

    cfbolz mannequin commented Nov 4, 2021

    A bit of a nitpick, but the following SyntaxError message is a bit confusing:

    >>> f(True=1)
      File "<stdin>", line 1
        f(True=1)
          ^^^^^
    SyntaxError: expression cannot contain assignment, perhaps you meant "=="?

    The problem with that line is not that it contains an assignment, it's almost a valid keyword argument after all. The problem is that the name of the keyword is True, which is no longer a name you can assign to. It would be better to produce the same error as with __debug__:

    >>> f(__debug__=1)
      File "<stdin>", line 1
    SyntaxError: cannot assign to __debug__

    The latter error message is however produced by the compiler, not the parser I think?

    @ericvsmith ericvsmith added interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Nov 4, 2021
    @pablogsal
    Copy link
    Member

    New changeset e2d6563 by Pablo Galindo Salgado in branch 'main':
    bpo-45716: Improve the error message when using True/False/None as keywords in a call (GH-29413)
    e2d6563

    @pablogsal
    Copy link
    Member

    New changeset 5618c81 by Pablo Galindo Salgado in branch '3.10':
    [3.10] bpo-45716: Improve the error message when using True/False/None as keywords in a call (GH-29413). (GH-29428)
    5618c81

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants