Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
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 fooPDB 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 functionUncaught exception. Entering post mortem debuggingRunning 'cont' or 'step' will restart the program> /usr/lib/python3.13/dis.py(76)_try_compile()-> return compile(source, name, 'exec')This also happens withtemporary 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)CPython versions tested on:
3.13
Operating systems tested on:
Linux