[Python-Dev] Bug? Can't rebind local variables after calling pdb.set_trace()

Guido van Rossum guido at python.org
Tue Apr 12 20:10:02 CEST 2011


On Tue, Apr 12, 2011 at 11:01 AM, Djoume Salvetti <dsalvetti at trapeze.com> wrote:
> On Tue, Apr 12, 2011 at 1:22 PM, Guido van Rossum <guido at python.org> wrote:
>>
>> Looking at the pastebin you are using !lv = 2. Why the !? Without it,
>> it works fine:
>>
>
>
> I just wanted to make sure I was executing a python statement and not a pdb
> alias.
> I re-tested without the exclamation mark and still have the same issue:
>  -> import pdb; pdb.set_trace()
> (Pdb) list
>   1     gv = 1
>   2
>   3     def f():
>   4         lv = 1
>   5  ->     import pdb; pdb.set_trace()
>   6
>   7     if __name__ == '__main__':
>   8         f()
> [EOF]
> (Pdb) lv
> 1
> (Pdb) lv = 2
> (Pdb) lv
> 1
> (Pdb)

Interesting. You'll find that if you let the function continue, lv is
actually set to 2. Why pdb prints 1 I don't know. It might be
interesting to find out why that is, although since it's fixed in
Python 2.7 and Python 3, perhaps observing the changes in pdb.py (or
other related code) between Python 2.6 and 2.7 might be the quickest
way to find out.

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list