facebook / facebook/pyrefly

Imports with syntax `from .submodule import name` in `__init__.py` modules bind the submodule

Open
#1,008 1 comment 0 reactions 0 assignees View on GitHub
typechecking
Dominant language
Rust
Stars
7k
Forks
516
PR merge metrics
No merged PRs in 30d

Description

### Describe the Bug

In an example like
```
from .foo import bar
print(foo)
```
the name `foo` is defined - we should be binding the name and including it in the exports.

Note that in principle, this could also shadow other names, e.g. in this example:
```
from .baz import bar
from .bar import foo
```
the `from .bar import foo` binds the name `bar`, which overwrites the original binding

Came up in discussion of #932, but I realized that it is really a separate problem whose root cause is gaps in the logic of `definitions.rs` and `bindings.rs`. It is also probably lower priority, since except in the shadowing case (which is artificial in that that pattern isn't very likely in real codebases) we already handle downstream reads reasonably well.

### Sandbox Link

_No response_

### (Only applicable for extension issues) IDE Information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.