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

Assigning to Ellipsis should be the same as assigning to __debug__ #88439

Closed
aroberge mannequin opened this issue May 31, 2021 · 9 comments
Closed

Assigning to Ellipsis should be the same as assigning to __debug__ #88439

aroberge mannequin opened this issue May 31, 2021 · 9 comments
Labels
3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@aroberge
Copy link
Mannequin

aroberge mannequin commented May 31, 2021

BPO 44273
Nosy @aroberge, @serhiy-storchaka, @pablogsal
PRs
  • bpo-44273: Improve syntax error message for assigning to "..." #26477
  • [3.10] bpo-44273: Improve syntax error message for assigning to "..." (GH-26477) #26478
  • 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-06-01.11:14:23.699>
    created_at = <Date 2021-05-31.15:04:05.962>
    labels = ['interpreter-core', '3.10']
    title = 'Assigning to Ellipsis should be the same as assigning to __debug__'
    updated_at = <Date 2021-06-03.21:22:37.615>
    user = 'https://github.com/aroberge'

    bugs.python.org fields:

    activity = <Date 2021-06-03.21:22:37.615>
    actor = 'pablogsal'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-06-01.11:14:23.699>
    closer = 'pablogsal'
    components = ['Interpreter Core']
    creation = <Date 2021-05-31.15:04:05.962>
    creator = 'aroberge'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44273
    keywords = ['patch']
    message_count = 9.0
    messages = ['394808', '394824', '394825', '394826', '394827', '394829', '394831', '394853', '395049']
    nosy_count = 3.0
    nosy_names = ['aroberge', 'serhiy.storchaka', 'pablogsal']
    pr_nums = ['26477', '26478']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue44273'
    versions = ['Python 3.10']

    @aroberge
    Copy link
    Mannequin Author

    aroberge mannequin commented May 31, 2021

    Consider the following in Python 3.10

    >>> ... = 1
      File "<stdin>", line 1
        ... = 1
        ^^^
    SyntaxError: cannot assign to Ellipsis here. Maybe you meant '==' instead of '='?
    >>> __debug__ = 1
      File "<stdin>", line 1
    SyntaxError: cannot assign to __debug__

    In prior Python versions, assignments to Ellisis written as ... were treated the same as assignment to __debug__. I believe that the old message was a better choice.

    The error message about assigning to Ellipsis (...) is made even more confusing since Ellipsis (the name) can be assigned to a different value.

    >>> ... == Ellipsis
    True
    >>> Ellipsis = 1
    >>> ... == Ellipsis
    False
    >>> ...
    Ellipsis

    @aroberge aroberge mannequin added 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) labels May 31, 2021
    @pablogsal
    Copy link
    Member

    Hummmm, I sort of agree, but I need to weigh how complex is going to be to special-case. I really don't want to start adding many different paths for the different built-ins in different situations.

    @pablogsal
    Copy link
    Member

    Also, another problem is that "cannot assign to __debug__" is actually a compiler error, while "cannot assign to Ellipsis here. Maybe you meant '==' instead of '='?" is a parser error. This is because "__debug__" is tokenized as NAME while '...' is tokenized as ELLIPSIS (it's own token).

    @pablogsal
    Copy link
    Member

    What we can do is to replace:

    SyntaxError: cannot assign to Ellipsis here. Maybe you meant '==' instead of '='?

    for

    SyntaxError: cannot assign to '...' here. Maybe you meant '==' instead of '='?

    @aroberge
    Copy link
    Mannequin Author

    aroberge mannequin commented May 31, 2021

    I think that the suggestion to explicitly refer to '...' instead of the
    name Ellipsis would be preferable.

    Aside: I had not realized that this was done at a different stage for
    __debug__ and Ellipsis ("Ignorance is bliss"...) and do realize that this
    is a rare corner case that a beginner would almost never encountered.
    (I'm just trying my best to prevent any kind of confusion in my own
    program, and probably overestimate the potential for confusion here for
    cPython users).

    @pablogsal
    Copy link
    Member

    I suggest to just close it or otherwise changing the message to include "..." instead of "Ellipsis". Anything else is actually much more complex than it seems, unfortunately

    @aroberge
    Copy link
    Mannequin Author

    aroberge mannequin commented May 31, 2021

    Up to your best judgment Pablo - and thanks for your ongoing work on improving error messages.

    @pablogsal
    Copy link
    Member

    New changeset 39dd141 by Serhiy Storchaka in branch 'main':
    bpo-44273: Improve syntax error message for assigning to "..." (GH-26477)
    39dd141

    @pablogsal
    Copy link
    Member

    New changeset 3283bf4 by Pablo Galindo in branch '3.10':
    [3.10] bpo-44273: Improve syntax error message for assigning to "..." (GH-26477) (GH-26478)
    3283bf4

    @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.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant