Support "go to def" in notebooks when statically-unknown type is known by Jupyter kernel #6192
Replies: 7 comments
-
It's not a general problem with properties, as go to def on import datetime
d = datetime.date(1, 1, 1)
d.year Here's a simplified repro: import shap
explainer = shap.Explainer(1)
shap_values = explainer()
reveal_type(shap_values) # Type of "shap_values" is "Unknown"
shap_values.data We are having trouble inferring the return type of I'm not sure what the specific issue is. If I start commenting out chunks of Here's a simplified example of a function that returns a def func():
out = []
out.append(1)
return out
result = func()
reveal_type(result) # Type of "result" is "list[Unknown]" I'd suggest filing an issue on Btw, @ibobak the images in your bugs are great and very helpful for understanding the scenario. Thanks for that! But providing code as text (also) would make it much easier for us to repro it. |
Beta Was this translation helpful? Give feedback.
-
Oh, also, you should be able to improve your own experience by adding this annotation on |
Beta Was this translation helpful? Give feedback.
-
Erik, thank you very much for your answer. It is a commercial project, and I got this just in the middle of my work. I know submitting code would be easier for you, but to do this, I would have to reproduce this in a separate notebook, etc. (to avoid inclusion of the commercial code). I just did not have time at that moment, sorry for that. As to what I understood from your answer: pylance is analyzing the code statically, and this is the biggest issue. No library maintainers (shap and others) will do any code changes just to fulfill the requirements of good static code: those libraries are what they are. Python is a dynamic programming language, work of a data scientist is a dynamic work: we are working in REPL mode, running cell by cell. Therefore, functionality of code navigation, finding types, etc. should be seriously redesigned. And the main feature of this redesign should be finding out what is the type of variable live (at run-time of the notebook). |
Beta Was this translation helpful? Give feedback.
-
To summarize, this refactoring should be made as to the "pylance in jupyter notebooks":
|
Beta Was this translation helpful? Give feedback.
-
@rebornix, what do you think about this? Does the Jupyter extension already have type info for all variables in a cell after it is executed (ex. for the Jupyter variables pane)? Could you provide us with the full dotted name of a particular variable's type so we could implement go to def in this scenario? Or maybe there's a better approach? |
Beta Was this translation helpful? Give feedback.
-
@debonte we have api in both VS Code and Jupyter to fetch variables, and for the top levels, we have both the type and also value/summary. So technically you can use that one. I'm not sure if Pylance should use VS Code api or Jupyter, or it should be Jupyter contributing this info to Pylance. |
Beta Was this translation helpful? Give feedback.
-
Moving this issue to discussions as an enhancement request for comments and upvotes. |
Beta Was this translation helpful? Give feedback.
-
Type: Bug
Behaviour
when I am trying to navigate (Ctrl+B in my case, this is "Go to definition") on a property, it tells me "no definition found for [name_of_property]".
Steps to reproduce:
Diagnostic data
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)Extension version: 2024.8.0
VS Code version: Code 1.90.0 (89de5a8d4d6205e5b11647eb6a74844ca23d2573, 2024-06-04T19:43:07.605Z)
OS version: Linux x64 6.4.6-060406-generic
Modes:
python.languageServer
setting: PylanceUser Settings
Installed Extensions
System Info
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
A/B Experiments
Beta Was this translation helpful? Give feedback.
All reactions