pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Don't suggest imports from private modules

Open mezuzza opened this issue 1 year ago • 3 comments

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 avatar Aug 19 '24 04:08 mezuzza

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.

mezuzza avatar Aug 19 '24 04:08 mezuzza

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.

KacieKK avatar Aug 19 '24 21:08 KacieKK

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

heejaechang avatar Aug 27 '24 17:08 heejaechang

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.

mezuzza avatar Sep 04 '24 18:09 mezuzza