Skip to content

Improve SyntaxError with future names suggestion #154337

Description

@sobolevn

Feature or enhancement

Currently regular imports with typos suggest close alternatives, which is helpful:

>>> from os import pth
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    from os import pth
ImportError: cannot import name 'pth' from 'os' (/Users/sobolev/Desktop/cpython/Lib/os.py). Did you mean: 'path'?

But, the same is not true for SyntaxError, when you make a typo in __future__ imports:

>>> from __future__ import barry_as_FLUF
  File "<python-input-0>", line 1
    from __future__ import barry_as_FLUF
                           ^^^^^^^^^^^^^
SyntaxError: future feature barry_as_FLUF is not defined

or

>>> from __future__ import anotations
  File "<python-input-2>", line 1
    from __future__ import anotations
                           ^^^^^^^^^^
SyntaxError: future feature anotations is not defined

I propose to do the same for names defined in __future__:

```python
>>> from __future__ import anotations
  File "<python-input-2>", line 1
    from __future__ import anotations
                           ^^^^^^^^^^
SyntaxError: future feature 'anotations' is not defined. Did you mean: 'annotations'?

I am working on a PR for this.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions