facebook / facebook/pyrefly

Prefer package imports to module imports in auto import

Open
#1,534 3 comments 1 reaction 1 assignee Claimed by @maggiemoss View on GitHub
help wanted language-server
Dominant language
Rust
Stars
7k
Forks
519
PR merge metrics
No merged PRs in 30d

Description

### Describe the Bug

I have a monorepo managed by Pants and am using Pyrefly as my LSP. Let's say I have a layout like this:

```
.
└── root/
├── mod_a/
│ ├── __init__.py
│ └── utils.py
└── mod_b/
├── __init__.py
└── uses_utils.py
```

and `__init__.py` in `mod_a` has an `__all__` that exports all the functions in `utils.py`. Let's say that `utils.py` contains the definition of `some_func`. If I'm editing `uses_utils.py` and I type `some_func` Pyrefly correctly notices I don't have it imported and offers to add the `import` for me. But, if I accept that suggestion it adds `from mod_a.utils import some_func` instead of `from mod_a import some_func`. I think the latter should be the default but either way it'd be nice to at least have it be an option.

### 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.