3

When i try to debug this sample script with ipdb:

n = 1
next = 1
print('end')

I can't execute line 3 because python variables obscure pdb commands:

$ ipdb test.py
> /tmp/test.py(1)<module>()
----> 1 n = 1
      2 next = 1
      3 print('end')

ipdb> next
> /tmp/test.py(2)<module>()
      1 n = 1
----> 2 next = 1
      3 print('end')

ipdb> next
> /tmp/test.py(3)<module>()
      1 n = 1
      2 next = 1
----> 3 print('end')

ipdb> next
1
ipdb> n
1
ipdb> !n
1
ipdb> !next
1

How can i proceed further with my code execution when both commands (n/next) aren't recognized anymore? (Let's assume s/step are also obscured by variables).

What i tried so far:

  • using ipdb3 instead of ipdb - the same problem (maybe because ipdb is link to ipdb3 in my case :))
  • using pdb - it works! n/next commands move to next line instead of displaying python variables. What's wrong with my ipdb?
  • !!n alleviates the problem - it runs ipdb version of next. If only I could alias n !!n and then repeatedly use Enter to execute it, the problem would be solved for me. But Enter just displays variable n instead of running alias n (which should resolve into !!n)

I'm using

  • Manjaro Linux 16.10
  • Python 3.5.2 :: Anaconda 4.2.0 (64-bit)
  • ipdb (0.10.1)
  • ipython (5.1.0)
  • ipython-genutils (0.1.0)
  • i don't have ~/.pdbrc file

EDIT

The issue was fixed by by: https://github.com/ipython/ipython/pull/10050

Kossak
  • 1,273
  • 1
  • 16
  • 31
  • Using `pdb3` your example works as expected. Repeated `next` steps through the program and restarts it while `!next` shows the value of the variable. Can't reproduce in cpython's pdb. – tdelaney Oct 24 '16 at 17:38
  • I installed `python3-ipdb` on my linux machine and it worked there also. `next` was always treated as a command and `!next` showed the value of the variable. – tdelaney Oct 24 '16 at 17:44
  • I added versions of my python/ipdb/ipython to my post. Maybe it makes difference. – Kossak Oct 24 '16 at 17:46
  • I am linux mint 17 x64 with python 3.4.3. – tdelaney Oct 24 '16 at 17:47
  • `ipdb` is the python 2 version... try `ipdb3`.... but it should still work the same way. – tdelaney Oct 24 '16 at 17:48
  • Snapshot of me nexting away: http://pastebin.com/FyakqK1A – tdelaney Oct 24 '16 at 17:54
  • ipdb3 doesn't work either, but it works with standard pdb! What's wrong with my ipdb? – Kossak Oct 24 '16 at 17:54
  • Good question! Maybe somebody more closely matching your version can check. Or if ipython has its own place for questions/bug reports, maybe there. – tdelaney Oct 24 '16 at 17:55
  • How about adding `ipython` tag? That may get the right viewership. – tdelaney Oct 24 '16 at 17:58
  • 1
    `!!n` should force it to run the command instead of showing the variable. I think `!n` forces it to treat it as a variable, and `n` guesses. – Thomas K Oct 25 '16 at 10:28
  • @ThomasK It works! Thank you. Add it as an answer. Another question: when i add `alias n !!n` i can't just press `n` `` `` etc. because `` just repeats normal `n` instead of my alias `!!n`. Do you know any solution to this? – Kossak Oct 25 '16 at 17:05
  • 1
    I have created a pull request to fix the empty line problem you face. https://github.com/ipython/ipython/pull/10035 – Ziya Tang Oct 25 '16 at 22:52

2 Answers2

2

Update in 12/14/2016:

Finally the iPython team decide to revoke this design.


The solution of your problem is use !! statement to force standard behavior.

> /home/v-zit/test.py(1)<module>()
----> 1 n = 1
      2 next = 11
      3 print('end')

ipdb> n
> /home/v-zit/test.py(2)<module>()
      1 n = 1
----> 2 next = 11
      3 print('end')

ipdb> n
1
ipdb> !!n
> /home/v-zit/test.py(3)<module>()
      1 n = 1
      2 next = 11
----> 3 print('end')

ipdb> next
11
ipdb> !!next
end
--Return--
None
> /home/v-zit/test.py(3)<module>()
      1 n = 1
      2 next = 11
----> 3 print('end')

ipdb>

Reference:

https://github.com/ipython/ipython/pull/9449

https://github.com/ipython/ipython/pull/10050

Ziya Tang
  • 91
  • 3
  • I don't think `del n` is a workaround - it destroys python variable that the program is using, so it will crash upon reading it. – Kossak Oct 24 '16 at 19:39
0

The solution is to use brackets (variable_name).

For example, if you have one vairable named q, you want to check it out, if you directly input q in the prompt, then the ipdb debugging process will break up.

>>> q

Instead, you should input (q) to ckeck this vairable:

>>> (q)
KingLiu
  • 59
  • 4