-
Notifications
You must be signed in to change notification settings - Fork 768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intellisense suggests imported names which should be considered an implementation detail #1875
Comments
The Intellisense mechanism in pylance does enforce this convention for "py.typed" libraries and for type stubs. In these cases, it does not offer these imported symbols as completion suggestions unless they are included in While PEP 8 does suggest that imported names should be considered an implementation detail, we've found that most libraries (especially those that are not "py.typed") do not follow this convention. If we were to enforce this convention more generally, I can assure you that we'd receive a deluge of bug reports from unhappy pylance users! |
Ok, thanks for the link, I was not aware of "py.typed". I've added it to my package but it doesn't seem to help, I assume that's because it only works inter-package, my use case is two modules in the same package. Given that most libraries don't follow that convention, would it be fine to just make imported names a lower priority in the list of suggestions? |
Yes, "py.typed" applies only to packages installed within your Python environment. We will discuss your suggestion, but my educated guess is that most pylance users will not want us to deprioritize these symbols in the suggestion list. We might be able to validate (or refute) that hypothesis through an experiment using telemetry-based feedback. It's unfortunate that Python doesn't have an |
Regardless of the prioritization, I think it would make sense to also consider user-code with |
@erictraut It would be nice if there were an option where users could either:
This is because your reasoning here is still true even of library authors who include
This is probably because PEP 561 (which defines Also, PEP8 isn't really clear that imported names in
|
We do enforce this for type stubs and |
@judej @erictraut coming back to this, I'm finding my team is doing things like this
Is that the Pylance recommended workaround? Is it really a problem to put the imported names at the bottom of the intellisense list? Even if it's just for |
I'm new to python, and it would be very useful to be able to filter out these implementation details from Intellisense autocomplete, even if it's a setting I have to opt into. Such as it is I'm resorting to what seems like a step backwards in code quality. I would like to know what is preferred, because I tend to make a lot of modules with just a few or even just one method being intentionally exported, and I just dislike all of the clutter that comes with seeing everything that has been declared in the auto completion list. |
PEP-8 mentions
When I have
and I create
I don't actually mind that
c
is shown, because I expect that some code doesn't consider imports an implementation detail, e.g.__init__.py
, but I think it would be more useful if all the imported names were at the bottom of the list.Perhaps the order could be something like this:
__all__
Even better would be if the names intellisense thinks might be private are greyed slightly (It could be a good way to solve microsoft/python-language-server#619)
Pylance version:
Pylance language server 2021.9.3 (pyright d2771b18)
OS version: WIndows 10
Python version: 3.8.10
The text was updated successfully, but these errors were encountered: