Created
December 3, 2012 17:13
-
-
Save vortec/4196432 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pdb import set_trace | |
def wrap1(name): | |
print('wrap 1: {}'.format(str(locals()))) | |
def inner(): ## no reference to name in inner function | |
set_trace() | |
inner() | |
def wrap2(name): | |
print('wrap 2: {}'.format(str(locals()))) | |
def inner(): ## reference to name before set_trace() | |
name | |
set_trace() | |
inner() | |
def wrap3(name): | |
print('wrap 3: {}'.format(str(locals()))) | |
def inner(): ## reference to name after set_trace(), same as wrap2() | |
set_trace() | |
name | |
inner() | |
wrap1('this is broken') | |
wrap2('this works') | |
wrap3('this works too') | |
""" OUTPUT: | |
fk-mbp:workspace fabian$ python pdb_bug.py | |
wrap 1: {'name': 'this is broken'} | |
--Return-- | |
> /Users/fabian/workspace/pdb_bug.py(7)inner()->None | |
-> set_trace() | |
(Pdb) name | |
*** NameError: name 'name' is not defined | |
(Pdb) c | |
wrap 2: {'name': 'this works'} | |
--Return-- | |
> /Users/fabian/workspace/pdb_bug.py(14)inner()->None | |
-> set_trace() | |
(Pdb) name | |
'this works' | |
(Pdb) c | |
wrap 3: {'name': 'this works too'} | |
> /Users/fabian/workspace/pdb_bug.py(21)inner() | |
-> name | |
(Pdb) name | |
'this works too' | |
(Pdb) c | |
fk-mbp:workspace fabian$ | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment