Skip to content

Insert import with alias creates invalid import #2495

Description

@spaceship-zebra

Describe the Bug

Pyrefly shows import suggestions also based on alias imports in other files. When using such an import it creates a from foo import NameAlias statement instead of from foo import Name as NameAlias. Here is a minimal example to reproduce it:

# model.py
class MyModel: pass
# alias_user.py
from pyrefly_repro.model import MyModel as MyModelAlias
# normal_user.py
x: MyM # and continue typing
Image

Pressing enter results in an invalid import:

# normal_user.py
from pyrefly_repro.model import MyModelAlias # Could not import `MyModelAlias` from `pyrefly_repro.model`
x: MyModelAlias

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

VS Code with Pyrefly v0.53.0

Metadata

Metadata

Labels

language-serverIssues specific to our IDE integration rather than type checking

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions