Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdb fails when setting a breakpoint to function names with return-type annotations #125884

Open
baco opened this issue Oct 23, 2024 · 0 comments
Open
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@baco
Copy link

baco commented Oct 23, 2024

Bug report

Bug description:

When having return-type annotations on a function:

def foo() -> int:
    return 0

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 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:

(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

Linked PRs

@baco baco added the type-bug An unexpected behavior, bug, or error label Oct 23, 2024
@baco 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
@gaogaotiantian gaogaotiantian self-assigned this Oct 23, 2024
@picnixz picnixz added the stdlib Python modules in the Lib dir label Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants