Skip to content

Misleading syntax error for import-as statement followed by erroneous statement on same line #138944

Closed

Description

@brianschubert

Bug report

Bug description:

Currently we have:

>>> import typing as t; None = 1
  File "<python-input-0>", line 1
    import typing as t; None = 1
                     ^
SyntaxError: cannot use name as import target

which doesn't make sense. Prior to #123629, it was:

>>> import typing as t; None = 1
  File "<python-input-0>", line 1
    import typing as t; None = 1
                        ^^^^
SyntaxError: cannot assign to None

We should restore the old message for this case.

I have a patch ready.

CPython versions tested on:

CPython main branch, 3.14

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    3.14bugs and security fixes
    3.15bugs and security fixes
    on Sep 15, 2025
  2. brianschubert commented on Sep 15, 2025

    @brianschubert
    ContributorAuthor
  3. added a commit that references this issue on Oct 21, 2025
  4. added a commit that references this issue on Oct 26, 2025
  5. added a commit that references this issue on Oct 27, 2025
  6. added a commit that references this issue on Oct 31, 2025
  7. added a commit that references this issue on Dec 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.14bugs and security fixes3.15bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-parsertype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions