Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any object with more than two levels is truncated #1819

Open
MetRonnie opened this issue Jan 27, 2025 · 8 comments
Open

Any object with more than two levels is truncated #1819

MetRonnie opened this issue Jan 27, 2025 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@MetRonnie
Copy link

MetRonnie commented Jan 27, 2025

Type: Bug

Behaviour

Clicking "Copy value" in the variables context menu leads to the presented object being copied as-is, i.e. truncated.

I have tested the JS debugger and it does not exhibit the same behaviour.

Steps to reproduce:

  1. Right-click a variable and click "Copy value"
  2. Paste somewhere

For example, trying to copy this dictionary:

Image

leads to the clipboard containing this ellipsis

{'hold': {'result': [...]}}

instead of the actual dictionary.

Diagnostic data

launch.json configuration

    "launch": {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Python: localhost attach",
                "type": "debugpy",
                "request": "attach",
                "justMyCode": false,
                "connect": {
                    "host": "localhost",
                    "port": 6678
                },
                "pathMappings": [
                    {
                        "localRoot": "${workspaceFolder}",
                        "remoteRoot": "${workspaceFolder}"
                    }
                ],
            },
            {
                "name": "Python: Debug Tests",
                "type": "debugpy",
                "request": "launch",
                "program": "${file}",
                "purpose": ["debug-test"],
                "justMyCode": false
              }
        ],
        "compounds": []
    },

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

N/A

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

N/A

Extension version: 2024.14.0
VS Code version: Code 1.96.2 (fabdb6a30b49f79a7aba0f2ad9df9b399473380f, 2024-12-19T10:22:47.216Z)
OS version: Linux x64 5.14.0-503.21.1.el9_5.x86_64
Modes:

  • Python version (& distribution if applicable, e.g. Anaconda): 3.12.6
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda
System Info
Item Value
CPUs AMD EPYC 7763 64-Core Processor (4 x 0)
GPU Status 2d_canvas: unavailable_software
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: disabled_software
multiple_raster_threads: enabled_on
opengl: disabled_off
rasterization: disabled_software
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: disabled_software
video_encode: disabled_software
vulkan: disabled_off
webgl: unavailable_software
webgl2: unavailable_software
webgpu: disabled_off
webnn: unavailable_software
Load (avg) 2, 1, 2
Memory (System) 15.32GB (6.89GB free)
Process Argv
Screen Reader no
VM 0%
DESKTOP_SESSION gnome
XDG_CURRENT_DESKTOP GNOME
XDG_SESSION_DESKTOP undefined
XDG_SESSION_TYPE x11
@eleanorjboyd eleanorjboyd transferred this issue from microsoft/vscode-python-debugger Jan 28, 2025
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Jan 28, 2025
@rchiodo
Copy link
Contributor

rchiodo commented Jan 28, 2025

I believe this is by design. Copy in the debugger copies the __repr__ of the variable. It just evals the variable so it ends up with the same thing that the variable view shows.

@rchiodo rchiodo closed this as completed Jan 28, 2025
@rchiodo rchiodo added design Issue is how the product is designed and removed needs repro Issue has not been reproduced yet labels Jan 28, 2025
@rchiodo
Copy link
Contributor

rchiodo commented Jan 28, 2025

If you want more to be displayed, you have to change the __repr__ for the stuff in the dictionary.

Something like this:

class A():
    def __init__(self):
        self.a = 1
        self.b = 2
        self.c = 3

    def __repr__(self):
        return f"A(a={self.a}, b={self.b}, c={self.c})"

a = A()
dict = {"a": a, "b": list}
print(dict)

@rchiodo
Copy link
Contributor

rchiodo commented Jan 28, 2025

Can you share your code? It seems weird that you'd get '[...]' in the value for a variable unless it was really deep into iteration. At the first level I don't think it should show just ....

I'm thinking maybe the problem here isn't copying but rather the gathering of the value itself.

@rchiodo rchiodo reopened this Jan 28, 2025
@rchiodo rchiodo added needs repro Issue has not been reproduced yet and removed design Issue is how the product is designed labels Jan 28, 2025
@MetRonnie
Copy link
Author

The object in question is solely built-ins all the way down. The variable was created by using json.loads(). The full dictionary is like this:

{
    'hold': {
        'result': [{'success': True, 'id': 'a5bf34'}]
    }
}

I can reproduce this with a simple file run in the debugger:

Image

@rchiodo
Copy link
Contributor

rchiodo commented Jan 29, 2025

It comes down to this constant here:

If an object is more than two levels deep (the size of the tuple), it just truncates it. This seems unnecessary to me but changing it could affect the perf of a lot of stuff.

Maybe we'd need a setting to allow this to be controlled by the user.

@rchiodo rchiodo added enhancement New feature or request and removed needs repro Issue has not been reproduced yet labels Jan 29, 2025
@rchiodo rchiodo changed the title "Copy value" truncates the object Any object with more than two levels is truncated Jan 29, 2025
@MetRonnie
Copy link
Author

I have no objection to the representation in the debug panel being truncated, by the way. It's just that it's not useful that when you copy it, it doesn't copy the whole object

@rchiodo
Copy link
Contributor

rchiodo commented Jan 30, 2025

Changing the copy eval to use a different truncation might be possible. On the eval for the copy we get a 'clipboard' context.

That seems like it would be hard to know it's going to behave that way though. It would just be more information for some reason. And it might be slow too if we always had the clipboard eval expand everything.

I think I'd want a way for the user to specify how much data we expand.

@gramster
Copy link
Member

gramster commented Feb 7, 2025

Potentially a duplicate of issue(s): #1644

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants