question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

View value in Data Viewer exception when viewing class variables

See original GitHub issue

Environment data

  • VS Code version: 1.52.1
  • Extension version (available under the Extensions sidebar): ms-python.python 2021.1.502429796
  • OS and version: Ubuntu 20.10
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.6
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): N/A
  • Relevant/affected Python packages and their versions:
    • jupyter-lab 2.2.5
  • Relevant/affected Python-related VS Code extensions and their versions:
    • ms-toolsai.jupyter v2020.12.414227025
  • Value of the python.languageServer setting: Pylance

Expected behaviour

When creating a class it should be possible to view the instance variables in the the Data Viewer.

Actual behaviour

Instance variables cannot be viewed in the data viewer and errors are raised. In the case in the mp4 below:

Error: Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'a' is not defined

In a bigger class I get some different error, just cannot reproduce it in a short example:

Error: Traceback (most recent call last):
  File "/home/user1/.vscode/extensions/ms-python.python-2021.1.502429796/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_vars.py", line 416, in evaluate_expression
    compiled = compile(_expression_to_evaluate(expression), '<string>', 'eval')
  File "<string>", line 1
    _VSCODE_DataFrameImport._VSCODE_getDataFrameInfo([0:969] )
                                                       ^
SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user1/.vscode/extensions/ms-python.python-2021.1.502429796/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py", line 969, in internal_evaluate_expression_json
    pydevd_vars.evaluate_expression(py_db, frame, expression, is_exec=True)
  File "/home/user1/.vscode/extensions/ms-python.python-2021.1.502429796/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_vars.py", line 368, in new_func
    return _run_with_unblock_threads(original_func, py_db, curr_thread, frame, expression, is_exec)
  File "/home/user1/.vscode/extensions/ms-python.python-2021.1.502429796/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_vars.py", line 336, in _run_with_unblock_threads
    return _run_with_interrupt_thread(original_func, py_db, curr_thread, frame, expression, is_exec)
  File "/home/user1/.vscode/extensions/ms-python.python-2021.1.502429796/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_vars.py", line 307, in _run_with_interrupt_thread
    return original_func(py_db, frame, expression, is_exec)
  File "/home/user1/.vscode/extensions/ms-python.python-2021.1.502429796/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_vars.py", line 418, in evaluate_expression
    Exec(_expression_to_evaluate(expression), updated_globals, frame.f_locals)
  File "/home/user1/.vscode/extensions/ms-python.python-2021.1.502429796/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<string>", line 1
    _VSCODE_DataFrameImport._VSCODE_getDataFrameInfo([0:969] )
                                                       ^
SyntaxError: invalid syntax

Steps to reproduce:

https://user-images.githubusercontent.com/20948931/106627331-9d049d80-6570-11eb-9f29-c87e93f73d36.mp4

As you can see, in the second part of the video after adding variable a when I try to open the tc.a class instance the a variable is shown.

To me it looks like the wrong variable name is handed over to the Data Viewer.

Sample Code:

import numpy as np

class Bugrep:
    def __init__(self, i: int) -> None:
        self.a = np.random.rand(i,i)
        self.b = 3
        self.c = [3, 5, 6, 7, 8]


tc = Bugrep(3)

a1 = np.random.rand(10, 10)
a = np.random.rand(3,3)

print(tc.a)

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

Error 2021-02-02 17:04:57: Failed to create File hash for interpreter python [Error: ENOENT: no such file or directory, lstat 'python'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'lstat',
  path: 'python'
}
Error 2021-02-02 17:04:57: Failed to create File hash for interpreter python [Error: ENOENT: no such file or directory, lstat 'python'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'lstat',
  path: 'python'
}
Error 2021-02-02 17:04:58: Failed to create File hash for interpreter python [Error: ENOENT: no such file or directory, lstat 'python'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'lstat',
  path: 'python'
}
> python ~/.vscode/extensions/ms-python.python-2021.1.502429796/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
q-wertzcommented, Mar 2, 2021

Sorry restarted the IDE and now it works 🎉

1reaction
rchiodocommented, Feb 9, 2021

Validated. tc.a is viewable now in the data viewer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

7 Ways to Look at the Values of Variables While Debugging in ...
Hover over a variable to see its value. The most commonly used way to look at variables is the DataTip. When stopped in...
Read more >
Error with show variable in data viewer for jupyter notebook
However, every time I am trying to view the values in Data Viewer, VS Code is throwing error below. It says that the...
Read more >
JetBrains Rider - Inspect variable values and objects
To find a specific value in a complex object that is currently in scope, focus the variables view in the Debug window and...
Read more >
Debugging the Eclipse IDE for Java Developers
Variables /Expression view – Shows the declared variables and their values. Press Ctrl+Shift+d or Ctrl+Shift+i on a selected variable or expression to show...
Read more >
How to Make the Most of Your Python Debugger in VSCode
Watch variables, use conditional breakpoints, call stack, exception breakpoint, etc— when working on larger projects. Quick pulse check — Still using print() ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found