You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Interactive Window and/or Cell Scripts (.py files with #%% markers)
What happened?
Unsure if this formally is a bug, but it is definitely bugging me.
The problem that I experience is that mouse hover (and the Variable Viewer) calls the str function on member variables of the class, which in turn call expensive getters. I hope the code below more clearly demonstrates the issue.
When the first cell has been exectuted, the hover shows the text "return value of expensive getter function".
I think these settings.json entries might prevent the issue, but they do not:
"debug.inlineValues": "off",
"jupyter.showVariableViewWhenDebugging": false,
Can you let me know if this is a bug, or my misunderstanding?
This settings.json entry does work for the code below, but is not really feasible, because we have a lot of generated classes, so the class names may vary:
Perhaps a second issue: I would expect hover and Variable View to call __repr__ rather than __str__ .
# %%classGetterIssue:
"""Class that has an expensive getter property."""def__init__(self):
passdef__str__(self):
return"getter_property: "+self.getter_propertydef__repr__(self):
return"getter_property: <getter_property(self)>"@propertydefgetter_property(self):
"""Calling this getter on hover or Variable View is problematic."""return"return value of expensive getter function"# The problem occurs when the cursor hovers over the text 'my_issue' below:my_issue=GetterIssue()
# %%print(str(my_issue)) # This is the function I would like to keeprepr(my_issue) # Hacked to not use the getter, probably not generally acceptable
VS Code Version
1.67.2
Jupyter Extension Version
v2022.4.1021342353
Jupyter logs
No response
Coding Language and Runtime Version
No response
Language Extension Version (if applicable)
v2022.6.3
Anaconda Version (if applicable)
No response
Running Jupyter locally or remotely?
Local
The text was updated successfully, but these errors were encountered:
@pvanschendel Looping back to check if I'm understanding the issue correctly here. Currently with hover (and variable view) you'd see something like this:
From my knowledge of python this is expect, for example when just debugging a .py file (not using Jupyter / interactive window) we see similar:
I would think the issue here is that str or repr should not be calling an expensive getter. Am I maybe not getting part of this scenario that you are asking about?
Also, I believe that debugging would expect to show str over repr as that's the expected "reading friendly" representation of the object.
Thanks for taking the trouble to check this. It is already good to know that this is expected behavior, so we have to live with it.
What was unexepcted for me is that these calls are (sometimes, when no cached value is available ?) also mode when only editing the code, so not debugging or otherwise running it, so I have to be really careful where to put my cursor,
I guess my mistake is that, if I implement a special function like str, I should be prepared that any editor or other tool may be calling this, not just user code.
Applies To
What happened?
Unsure if this formally is a bug, but it is definitely bugging me.
The problem that I experience is that mouse hover (and the Variable Viewer) calls the str function on member variables of the class, which in turn call expensive getters. I hope the code below more clearly demonstrates the issue.
When the first cell has been exectuted, the hover shows the text "return value of expensive getter function".
I think these settings.json entries might prevent the issue, but they do not:
Can you let me know if this is a bug, or my misunderstanding?
This settings.json entry does work for the code below, but is not really feasible, because we have a lot of generated classes, so the class names may vary:
Perhaps a second issue: I would expect hover and Variable View to call
__repr__
rather than__str__
.VS Code Version
1.67.2
Jupyter Extension Version
v2022.4.1021342353
Jupyter logs
No response
Coding Language and Runtime Version
No response
Language Extension Version (if applicable)
v2022.6.3
Anaconda Version (if applicable)
No response
Running Jupyter locally or remotely?
Local
The text was updated successfully, but these errors were encountered: