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.

Class variable display when debugging doesn't consistently use __repr__()

See original GitHub issue

Issue Type: Bug

Set a breakpoint on the last line of the following code and run the debugger:

class XYZ(object):
    def __iter__(self):
        for x in range(17):
            yield x
    def __repr__(self):
        return "test"

XYZ_instance = XYZ()
_breakHere = True

If the __iter__ method above returns an error or too many values (16 works, 17 doesn’t), the debugger shows XYZ_instance: <XYZ> instead of XYZ_instance: test.

Extension version: 2018.4.0 VS Code version: Code 1.23.0 (7c7da59c2333a1306c41e6e7b68d7f0caa7b3d45, 2018-05-03T16:44:55.614Z) OS version: Windows_NT x64 10.0.16299

System Info
Item Value
CPUs Intel® Core™ i7-4700HQ CPU @ 2.40GHz (8 x 2394)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: disabled_software
video_decode: enabled
video_encode: enabled
vpx_decode: unavailable_software
webgl: enabled
webgl2: enabled
Memory (System) 15.91GB (8.81GB free)
Process Argv C:\Program Files\Microsoft VS Code\Code.exe C:\Users\jjw\Desktop\testbug.py
Screen Reader no
VM 50%

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jjwhitneycommented, May 31, 2018

Thanks so much for pointing to that project. I didn’t know where to find the code that caused the behavior and now I can see clearly what’s happening. By an amazing coincidence, my bug was fixed (accidentally it seems, by someone fixing another unrelated bug) a few hours ago: https://github.com/Microsoft/ptvsd/commit/0866c0c830367a31dc967bf14295ac566d5b4f68

I’ve fixed the problem locally by replacing the SafeRepr class in pythonFiles/PythonTools/visualstudio_py_util.py with the updated class from the ptvsd project.

For those wanting more information, the debugger is basically “guessing” whether or not __repr__ output is reasonably small. The fix that was made above assumes that most objects won’t have a problem with this and instead only refuses to call __repr__ if it happens to be one of the few built-in types that are known to have __repr__ outputs that scale with the number of their elements.

0reactions
brettcannoncommented, May 28, 2018

@jjwhitney why 16 is a question to ask over on https://github.com/microsoft/ptvsd where the debugger is maintained (and actually your other question as well since the debugger sends us the object representation).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Class variable display when debugging doesn't ...
Issue Type: Bug Set a breakpoint on the last line of the following code and run the debugger: class XYZ(object): def __iter__(self): for...
Read more >
What is the difference between __str__ and __repr__?
The difference with repr(object) is that str(object) does not always attempt to return a string that is acceptable to eval() ; its goal...
Read more >
Python __str__() and __repr__() functions
This method is called when repr() function is invoked on the object. If possible, the string returned should be a valid Python expression...
Read more >
Debugging with gdb - Examining Data
Open-source document that explains how to use GDB to debug programs. ... If a display expression refers to local variables, then it does...
Read more >
Debugging configurations for Python apps in Visual Studio Code
For general debugging features such as inspecting variables, setting breakpoints, and other activities that aren't language-dependent, review VS Code debugging.
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