user3064538
user3064538

Reputation:

How do I start pdb and step into a function from the REPL?

I want to know how Python executes inspect.signature, so I want to step into this function call inspect.signature(bytes.__getitem__). One way to do that is to write a file with these contents

import inspect

breakpoint()
inspect.signature(bytes.__getitem__)

and then run it and use the s pdb command to step into the function call.

My question is, can I do this from the REPL?

Upvotes: 2

Views: 728

Answers (1)

user3064538
user3064538

Reputation:

You can do it by importing pdb and then calling your function using either pdb.runcall:

>>> from inspect import signature
>>> import pdb
>>> pdb.runcall(signature, bytes.__getitem__)
> /usr/lib/python3.9/inspect.py(3118)signature()
-> return Signature.from_callable(obj, follow_wrapped=follow_wrapped)
(Pdb) 

or pdb.run:

>>> pdb.run("signature(bytes.__getitem__)")
> <string>(1)<module>()->None
(Pdb) s
--Call--
> /usr/lib/python3.9/inspect.py(3116)signature()
-> def signature(obj, *, follow_wrapped=True):
(Pdb) 

Upvotes: 4

Related Questions