How to test that pylance includes expected suggestions with python #4996
-
Hi, I'm working on a python library that's mostly intended for use within jupyter notebooks. I would like to test that certain parts of our API include expected autocompletion suggestions (since it's an important part of the user's experience). Could you please guide me on how this could be achieved? For context, I've had some issues with dynamically generated attributes not autocompleting as I intended. For example, if I wrap an object with @Property, then I can no longer see it's dynamically generated attributes. If I access the actual object, then it works fine. Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
For Pyright and Pylance we statically analyze the library to determine what methods a class might contain. This means the methods have to statically exist in the python source and generally can't be added at runtime. There are some exceptions to that (overloads of getattr for example can specify dynamic attributes that might be added, but that's still putting the same information into the source). I assume you're trying it out and you're not getting the results you hoped? What does the source python look like? |
Beta Was this translation helpful? Give feedback.
Some of the dynamic attributes may be working in a jupyter notebook because in a notebook there's actually an additional completion provider, the jupyter kernel itself. The Jupyter extension provides completions in this manner by asking the kernel for them. These are then combined with the static completions provided by Pylance.
But anything you dynamically add through
setattr
can only be found this way = actually running the code and querying the kernel.