Is it possible to hide certain objects from displaying as autocompletion suggestions, preferably only when accessed from another file? #3797
Unanswered
ItsCubeTime
asked this question in
Q&A
Replies: 1 comment
-
Related: #1875 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Say I have a module
foo
where its__init__.py
contains the following code:When writing in this file, I want to get code suggestions for the math module, but when later on importing this module in a separate file
main.py
of which may look like:I probably dont want to see anything of the
math
module when typingfoo.
. How would one solve this?One option would be to change the contents of
foo
to something like:or
or create a separate file
foo.py
inside thefoo
folder that contains all the declarations & logic and simply import things as I like intofoo/__init__.py
(which is probably the most popular solution).All of which methods would work just fine for organizational purposes even though the first 2 candidates really only obscures the objects without really preventing them from showing at all.
But say if I then have a 3rd file
bar.py
with some additional code:and I want to migrate that into the
foo
module it wont just be as simple as copy-pasting it over from one file to another. All out of a sudden I will have to modify this code to adhere to the candidating practices described above - which will be additional manual work.So to recap: I dont want intellisense autocompletion to pickup on certain unwanted objects (though, its fine if say
foo.math
still runs despite that it may be a little strange), preferably only when accessed through an external file (so that I can still see the contents of math when writing inside of the init file offoo
in my example). Do you guys know of any techniques that I could use to allow myself to use external libraries and/or declare functions directly inside of module__init__.py
files whilst being able to in some way hide them from intellisense autocompletion when the file is accessed by another file without just renaming them or putting these "util" functions in a separate unexposed file?Ive already discovered that intellisense typically wont pick up on imports done via importlib - which could act as a partial solution, but then I still wont see any autocompletion when working within the module, which is undesired.
Is there perhaps some global variables declared by cpython or pylance that I can make use of to make certain objects not declare in certain autocompletion scenarios? like the following psuedo code:
Thanks for reading 💝
Beta Was this translation helpful? Give feedback.
All reactions