gh-74614: bdb and pdb: Add watchpoint function by mlouielu · Pull Request #1756 · python/cpython (original) (raw)

The test.test_pdb.test_rwatch_command doctest fails:

Failed example:
    with PdbTestInput(['next',
                       'rwatch foo',
                       'continue',
                       'continue',
                       'continue',
                       'continue',
                       'continue',
                       'continue',
                       'continue',
                       'continue']):
        test_function()
Expected:
    > <doctest test.test_pdb.test_rwatch_command[0]>(3)test_function()
    -> foo = 10
    (Pdb) next
    > <doctest test.test_pdb.test_rwatch_command[0]>(4)test_function()
    -> type(foo)
    (Pdb) rwatch foo
    (Pdb) continue
    <BLANKLINE>
    read watchpoint 10:foo
[...]
Got:
    > <doctest test.test_pdb.test_rwatch_command[0]>(3)test_function()
    -> foo = 10
    (Pdb) next
    > <doctest test.test_pdb.test_rwatch_command[0]>(4)test_function()
    -> type(foo)
    (Pdb) rwatch foo
    (Pdb) continue
    <BLANKLINE>
    read watchpoint 4:foo
[...]

read watchpoint 4:foo comes from the freshly added functions:

self._do_watch(arg, 'read watchpoint')
def _do_watch(self, arg, type):
if not arg:
# Print out all breakpoint
self.do_break(None)
return None
try:
eval(arg, self.curframe.f_locals)
except NameError:
self.error('No symbol "%s" in current context' % arg)
return None
self.set_watch(arg, self.curframe, type)
def set_watch(self, var_name, var_frame, bptype):
try:
var_value = copy.copy(eval(var_name, var_frame.f_locals))
except NameError:
return 'Variable %s does not exist' % var_name
list = self.breaks.setdefault(bptype, [])
if var_name not in list:
list.append(var_name)
Breakpoint(None, None, var_name=var_name, var_value=var_value,
var_frame=var_frame, bptype=bptype)
return None

I cannot recognize what the problem is though.