@@ -361,6 +361,69 @@ def test_rich_inspect_at_breakpoint(kernel_with_debug):
361361 assert reply ["body" ]["data" ] == {"text/plain" : locals_ [0 ]["value" ]}
362362
363363
364+ def test_rich_inspect_at_breakpoint_non_literal_repr (kernel_with_debug ):
365+ # The rich representation comes back from debugpy as a string. A value in
366+ # it whose repr is an expression must be read as data, not evaluated.
367+ code = """class Expr:
368+ def __repr__(self):
369+ return "len('abc')"
370+
371+ class Rich:
372+ def _repr_mimebundle_(self, include=None, exclude=None):
373+ return {"text/plain": Expr()}
374+
375+ def f(a):
376+ b = a
377+ return b
378+
379+ f(Rich())"""
380+
381+ r = wait_for_debug_request (kernel_with_debug , "dumpCell" , {"code" : code })
382+ if debugpy :
383+ source = r ["body" ]["sourcePath" ]
384+ else :
385+ assert r == {}
386+ source = "some path"
387+
388+ wait_for_debug_request (
389+ kernel_with_debug ,
390+ "setBreakpoints" ,
391+ {
392+ "breakpoints" : [{"line" : 10 }],
393+ "source" : {"path" : source },
394+ "sourceModified" : False ,
395+ },
396+ )
397+
398+ wait_for_debug_request (kernel_with_debug , "debugInfo" )
399+
400+ wait_for_debug_request (kernel_with_debug , "configurationDone" )
401+
402+ kernel_with_debug .execute (code )
403+
404+ if not debugpy :
405+ # Cannot stop on breakpoint if debugpy not installed
406+ return
407+
408+ # Wait for stop on breakpoint
409+ msg : dict = {"msg_type" : "" , "content" : {}}
410+ while msg .get ("msg_type" ) != "debug_event" or msg ["content" ].get ("event" ) != "stopped" :
411+ msg = kernel_with_debug .get_iopub_msg (timeout = TIMEOUT )
412+
413+ stacks = wait_for_debug_request (kernel_with_debug , "stackTrace" , {"threadId" : 1 })["body" ][
414+ "stackFrames"
415+ ]
416+
417+ reply = wait_for_debug_request (
418+ kernel_with_debug ,
419+ "richInspectVariables" ,
420+ {"variableName" : "a" , "frameId" : stacks [0 ]["id" ]},
421+ )
422+
423+ assert reply ["success" ]
424+ assert reply ["body" ] == {"data" : {}, "metadata" : {}}
425+
426+
364427def test_convert_to_long_pathname ():
365428 if sys .platform == "win32" :
366429 from ipykernel .compiler import _convert_to_long_pathname
0 commit comments