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

Improve error messages for assignment #79350

Closed
serhiy-storchaka opened this issue Nov 5, 2018 · 3 comments
Closed

Improve error messages for assignment #79350

serhiy-storchaka opened this issue Nov 5, 2018 · 3 comments
Labels
3.8 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

BPO 35169
Nosy @brettcannon, @benjaminp, @serhiy-storchaka, @1st1
PRs
  • bpo-35169: Improve error messages for forbidden assignments. #10342
  • 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 2018-11-20.18:07:05.604>
    created_at = <Date 2018-11-05.19:17:32.269>
    labels = ['interpreter-core', 'type-feature', '3.8']
    title = 'Improve error messages for assignment'
    updated_at = <Date 2018-11-20.18:07:05.603>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2018-11-20.18:07:05.603>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-11-20.18:07:05.604>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2018-11-05.19:17:32.269>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35169
    keywords = ['patch']
    message_count = 3.0
    messages = ['329313', '330056', '330138']
    nosy_count = 4.0
    nosy_names = ['brett.cannon', 'benjamin.peterson', 'serhiy.storchaka', 'yselivanov']
    pr_nums = ['10342']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue35169'
    versions = ['Python 3.8']

    @serhiy-storchaka
    Copy link
    Member Author

    This is a follow up of bpo-34641.

    >>> f(lambda x: x = 1)
      File "<stdin>", line 1
    SyntaxError: lambda cannot contain assignment
    >>> f(x.y = 1)
      File "<stdin>", line 1
    SyntaxError: keyword can't be an expression

    The error message "keyword can't be an expression" still looks confusing to me. This is because the term "keyword" is ambiguous. Usually it means reserved identifier like "if" or "def". Some keywords, like "None" and "True" can be expressions. Perhaps "keyword name can't be an expression" would be better.

    But I think that in these cases it is most likely that "=" was used instead of "==". And it would be better to generalize the error message for lambdas and point on a possible typo.

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

    The proposed PR changes this error message. It makes also an error message for forbidden assignment more concrete: "cannot assign to __debug__" instead of "assignment to keyword" (the latter is actually incorrect, because __debug__ is not true keyword in tokenizer). This restores Python 2 error messages. Improved also other error messages for forbidden assigning: dict and set displays, f-string expressions are not literals.

    @serhiy-storchaka serhiy-storchaka added 3.8 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Nov 5, 2018
    @serhiy-storchaka
    Copy link
    Member Author

    Benjamin, could you please take a look at this?

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 97f1efb by Serhiy Storchaka in branch 'master':
    bpo-35169: Improve error messages for forbidden assignments. (GH-10342)
    97f1efb

    @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
    3.8 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant