Skip to content

Improve error message locations for future statements with unknown future features #126139

Closed
@brianschubert

Description

@brianschubert

Feature or enhancement

Proposal:

Currently, attempting to use a future statement with an unknown future feature produces a syntax error with the error location set to the start of the line:

$ python3 example.py
  File "../example.py", line 1
    from __future__ import does_not_exist
    ^
SyntaxError: future feature does_not_exist is not defined

This has some unfortunate UX in the new 3.13 REPL, where it results in only the f character at the start of the line being highlighted:

image

The UX is also suboptimal for future statements with multiple future features, since the error location doesn't show which feature is causing the error:

$ python3 example.py
  File "../example.py", line 1
    from __future__ import division, with_statement, pirnt_function
    ^
SyntaxError: future feature pirnt_function is not defined

It would be nice if the error location instead highlighted the specific future feature that isn't defined. Something like:

$ python3 example.py
  File "../example.py", line 1
    from __future__ import division, with_statement, pirnt_function
                                                     ^^^^^^^^^^^^^^
SyntaxError: future feature pirnt_function is not defined

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions