You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When having return-type annotations on a function:
deffoo() ->int:
return0
and trying to establish a breakpoint on the name of the function:
(Pdb) break foo
PDB raises the following exception (snipped):
Traceback (most recent call last):
File "/usr/lib/python3.13/pdb.py", line 1137, in do_break
lineno = int(arg)
ValueError: invalid literal for int() with base 10: 'foo'
During handling of the above exception, another exception occurred:
...
SyntaxError: 'return' outside function
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /usr/lib/python3.13/dis.py(76)_try_compile()
-> return compile(source, name, 'exec')
This also happens with temporary breakpoinstbreak. This was tested using Python versions from Debian official repositories. The failure appears in 3.13.0 and was not present in 3.12.6.
Analyzing with @asottile they point out that the following lines: Lib/pdb.py:121, Lib/pdb.py:141 may be causing this behavior. They also provided further probing of the issue:
(Pdb) p compile(funcdef, filename, 'exec').co_consts
('return', <code object main at 0x102b73020, file "/private/tmp/y/t3.py", line 1>, None)
(Pdb) p funcdef
'def main() -> int:\n pass\n'
I think it's expecting to find the code object there.
it's due to the disassembly
(Pdb) dis.dis(compile('def f() -> int: pass', filename, 'exec'))
0 RESUME 0
1 LOAD_CONST 0 ('return')
LOAD_NAME 0 (int)
BUILD_TUPLE 2
LOAD_CONST 1 (<code object f at 0x102b73020, file "/private/tmp/y/t3.py", line 1>)
MAKE_FUNCTION
SET_FUNCTION_ATTRIBUTE 4 (annotations)
STORE_NAME 1 (f)
RETURN_CONST 2 (None)
Disassembly of <code object f at 0x102b73020, file "/private/tmp/y/t3.py", line 1>:
1 RESUME 0
RETURN_CONST 0 (None)
baco
changed the title
pdb fails when setting a breakpoint to function names with type annotations
pdb fails when setting a breakpoint to function names with return-type annotations
Oct 23, 2024
Bug report
Bug description:
When having return-type annotations on a function:
and trying to establish a breakpoint on the name of the function:
PDB raises the following exception (snipped):
This also happens with temporary breakpoins
tbreak
. This was tested using Python versions from Debian official repositories. The failure appears in 3.13.0 and was not present in 3.12.6.Analyzing with @asottile they point out that the following lines: Lib/pdb.py:121, Lib/pdb.py:141 may be causing this behavior. They also provided further probing of the issue:
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: