pylance-release
pylance-release copied to clipboard
Narrow completion suggestions to __all__ value
Is your feature request related to a problem? Please describe.
Some modules import a lot of symbols into their namespace. Auto-completion on such modules lists own symbols as well as all imported ones, which can be inconvenient.
Let's say I have a module a.py
containing following
from typing import List
__all__ = ["foo"]
def foo() -> List[str]:
return ["a"]
Currently autocomplete on a.
gives me a.List
and a.foo
as possible options.
Describe the solution you'd like
When triggering auto complete on such module I would like to see only names listed in __all__
in suggestions + common module attributes such as __file__
, __doc__
Additional context
For modules that don't specify __all__
all names should be listed as before.
I don't think this matches the expectations of most users. The __all__
symbol is not meant to be a comprehensive list of exported symbols. Rather, it's a list of symbols that are included in a wildcard import.
Since this isn't a core type checking issue, I'm going to transfer it to the pylance-release project and let the pylance team decide how to proceed.
@m-novikov, is the module part of a "py.typed" library? If so, then we could limit suggestions only to those symbols that are considered part of the public interface for the library. For modules that are not part of a "py.typed" library (or type stubs), we don't have a good way of knowing which symbols are meant to be public and which are not. Python doesn't have any keywords like public
and private
, so we generally need to assume that the module author meant for all symbols to be public. See this documentation for more details.
It's not a part of py.typed
. Maybe it makes sense to rank "private" symbols lower in suggestions?
Are there any updates on this?
+1 for first showing all attributes defined in __all__
, if present, and then show all other "more private like" functions/attributes. I understand it is not what __all__
means, but it kind of does mean this.
Moving this issue to discussion as an enhancement request for comments and upvotes.