Issue while printing args in pdb

Hi,

I am seeing an issue in pdb while printing from args when multiple args are passed to a function.

lets say we pass three arguments then args[0] should display the first one, in pdb it displays entire tuple instead of first argument.

consider the following sample program,

def my_function(*args):
    breakpoint()
    first_arg = args[0] if args else None  # Safe access to the first argument
    print("First argument:", first_arg)

my_function(10, 20, 30)  # Output: First argument: 10
my_function()  # Output: First argument: None

it’s output,

$ python3 test_arg.py
> /home/python/test_arg.py(3)my_function()
-> first_arg = args[0] if args else None  # Safe access to the first argument
(Pdb) n
> /home/python/test_arg.py(4)my_function()
-> print("First argument:", first_arg)
(Pdb) first_arg
10
(Pdb) args[1]
args = (10, 20, 30)
(Pdb) c
First argument: 10
> /home/python/test_arg.py(3)my_function()
-> first_arg = args[0] if args else None  # Safe access to the first argument
(Pdb) c
First argument: None

this seems to happen for linux and windows as well. shouldn’t args[0] even in pdb print 10?

if this is a legitimate issue please let me know where I can raise it.

regards,

In pdb args is a command that shows the arguments to the current function. Use p to print things:

(Pdb) args[1]
args = (10, 20, 30)
(Pdb) p args[1]
20
1 Like

Thank you, Oscar. if we give args I can understand about pdb having defined command, even args[1] is giving the same result means, I feel it to be a bit off.

1 Like

This is fixed in 3.13. You’ll have expected result for args[0] in 3.13.

oh nice, Thank you @gaogaotiantian.