microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.71k stars 765 forks source link

Don't suggest imports from private modules #6275

Closed mezuzza closed 1 month ago

mezuzza commented 2 months ago

Let's say we have the following directory contents:

foo/
  __init__.py
  _bar.py

The contents look like so:

# __init__.py
from ._bar import baz

__all__ = ["baz"]

If I try to import auto-import baz, pyright seems to use from foo._bar import baz and I have to manually change the import. Could we prevent pyright and pylance from suggesting imports from private modules?

For context, I'm using coc-pyright with vim8, so it's totally possible I'm missing something, but I've looked for a while and can't find a good solution to this.

Also, I originally created this question on https://github.com/microsoft/pyright/discussions/8612#discussion-6996652.

mezuzza commented 2 months ago

There are a number of other improvements around the auto-import feature, but I suspect that it would be best to split them into multiple requests so that each can be handled more granularly? Please let me know if you'd prefer if I listed a few more in this thread as well.

KacieKK commented 2 months ago

Hey @mezuzza, thank you for reporting. I am trying to reproduce it in vscode, could you add more details in your example? Like where to trigger the auto import? For more suggestions, feel free to create more issues if they're unrelated to the current one.

heejaechang commented 2 months ago

it is by design for now. but we are planning to support it with full mode - https://github.com/microsoft/pylance-release/issues/5434

mezuzza commented 1 month ago

Thanks folks. Sorry about the delay in responding here; I've been a bit swamped and lost track of this. Thanks for the clarity around the full mode. I'll track that ticket and follow up if full mode doesn't quite solve the problem.