ipykernel icon indicating copy to clipboard operation
ipykernel copied to clipboard

Variable explorer displays functions with a leading underscore

Open jaipreet-s opened this issue 3 years ago • 4 comments

The inspectVariables request and the variable explorer panel in the debugger seems to display functions with a leading underscore.

Here's a simple repro

def _abc():
    return "Hello"

def abc():
    return "Hello"

In the above code snippet, _abc will appear in the "Variables" panel whereas abc will not, as demonstrated below

SCR-20230105-nlp

jaipreet-s avatar Jan 06 '23 01:01 jaipreet-s

Looking through the ipykernel code, my hunch is that this is actually an issue with pydevd

jasongrout avatar Jan 06 '23 20:01 jasongrout

Indeed, it does seem to be an issue with pydevd. If I add self.log.error(variables) just after https://github.com/ipython/ipykernel/blob/817258df78ee9d718081574e627edda2622c6af9/ipykernel/debugger.py#L610, I get the following when I evaluate the above example:

[IPKernelApp] ERROR | [{'name': 'special variables', 'value': '', 'type': '', 'evaluateName': 'special variables', 'variablesReference': 4703587392}, {'name': 'function variables', 'value': '', 'type': '', 'evaluateName': 'function variables', 'variablesReference': 4703586624}, {'name': 'In', 'value': '['', 'def abc():\n retu...rn "Hello"']', 'type': 'list', 'evaluateName': 'In', 'variablesReference': 4427080000}, {'name': 'Out', 'value': '{}', 'type': 'dict', 'evaluateName': 'Out', 'variablesReference': 4701765760}, {'name': 'debugpy', 'value': "<module 'debugpy' from '/private/var/folders/l0/km7g2yss183d7nrskwl4xgbc0000gn/T/tmpenv.UAXzGv3X/env/lib/python3.11/site-packages/debugpy/init.py'>", 'type': 'module', 'evaluateName': 'debugpy', 'variablesReference': 4423596880}, {'name': 'exit', 'value': '<IPython.core.autocall.ZMQExitAutocall object at 0x1183f52d0>', 'type': 'ZMQExitAutocall', 'evaluateName': 'exit', 'variablesReference': 4701770448}, {'name': 'quit', 'value': '<IPython.core.autocall.ZMQExitAutocall object at 0x1183f52d0>', 'type': 'ZMQExitAutocall', 'evaluateName': 'quit', 'variablesReference': 4701770448}, {'name': '', 'value': "''", 'type': 'str', 'evaluateName': '_', 'variablesReference': 0, 'presentationHint': {'attributes': ['rawString']}}, {'name': '_abc', 'value': '<function _abc at 0x118594a40>', 'type': 'function', 'evaluateName': '_abc', 'variablesReference': 4703472192}, {'name': '_dh', 'value': "[PosixPath('/private/...UAXzGv3X')]", 'type': 'list', 'evaluateName': '_dh', 'variablesReference': 4701770112}, {'name': '_i', 'value': "''", 'type': 'str', 'evaluateName': '_i', 'variablesReference': 0, 'presentationHint': {'attributes': ['rawString']}}, {'name': '_i1', 'value': ''def _abc():\n return "Hello"\n\ndef abc():\n return "Hello"'', 'type': 'str', 'evaluateName': '_i1', 'variablesReference': 0, 'presentationHint': {'attributes': ['rawString']}}, {'name': '_ih', 'value': '['', 'def _abc():\n retu...rn "Hello"']', 'type': 'list', 'evaluateName': '_ih', 'variablesReference': 4427080000}, {'name': '_ii', 'value': "''", 'type': 'str', 'evaluateName': '_ii', 'variablesReference': 0, 'presentationHint': {'attributes': ['rawString']}}, {'name': '_iii', 'value': "''", 'type': 'str', 'evaluateName': '_iii', 'variablesReference': 0, 'presentationHint': {'attributes': ['rawString']}}, {'name': '_oh', 'value': '{}', 'type': 'dict', 'evaluateName': '_oh', 'variablesReference': 4701765760}]

Note in particular it gives back {'name': '_abc', 'value': '<function _abc at 0x118594a40>', 'type': 'function', 'evaluateName': '_abc', 'variablesReference': 4703472192}, but not a corresponding variable for abc

jasongrout avatar Jan 06 '23 20:01 jasongrout

I made an issue over in pydevd with reproduction instructions: https://github.com/fabioz/PyDev.Debugger/issues/246

jasongrout avatar Jan 06 '23 20:01 jasongrout