This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nejucomo
Recipients
Date 2007-07-04.19:53:11
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
For a variable defined in a module scope, and stack frame object's locals and globals scope dictionaries each contain that variables name mapped to None.

This confuses python code which inspects the bindings, such as pdb.  Such code incorrectly reports the value as None.

It may be that the binding values are correct at the time of exception generation, but altered by the time the exception traceback is caught.  This problem may also be related to module imports.

Here's are two simple examples, the first does not trigger this problem, the second does.

Both use this module called "buggy.py":
# Begin buggy.py
whatKnightsSay = 'Ni!'
print 'We are the Knights who say: %r' % (whatKnightsSay,)
42 + whatKnightsSay
# End buggy.py

# Begin a non-failing example:
$ pdb buggy.py
> /home/n/sandbox/python-module-binding-bug-src/buggy.py(1)<module>()
-> whatKnightsSay = 'Ni!'
(Pdb) print whatKnightsSay
*** NameError: name 'whatKnightsSay' is not defined
(Pdb) next
> /home/n/sandbox/python-module-binding-bug-src/buggy.py(2)<module>()
-> print 'We are the Knights who say: %r' % (whatKnightsSay,)
(Pdb) print whatKnightsSay
Ni!
(Pdb) next
We are the Knights who say: 'Ni!'
> /home/n/sandbox/python-module-binding-bug-src/buggy.py(3)<module>()
-> 42 + whatKnightsSay
(Pdb) print whatKnightsSay
Ni!
(Pdb) next
TypeError: "unsupported operand type(s) for +: 'int' and 'str'"
> /home/n/sandbox/python-module-binding-bug-src/buggy.py(3)<module>()
-> 42 + whatKnightsSay
(Pdb) print whatKnightsSay
Ni!
(Pdb) next
--Return--
> /home/n/sandbox/python-module-binding-bug-src/buggy.py(3)<module>()->None
-> 42 + whatKnightsSay
(Pdb) print whatKnightsSay
Ni!
(Pdb) next
TypeError: "unsupported operand type(s) for +: 'int' and 'str'"
> <string>(1)<module>()->None
(Pdb) print whatKnightsSay
Ni!
# End succeeding example.


And here's a simple failing example, which relies on a second module:
# Begin triggerPdb.py
import pdb
pdb.set_trace()
import buggy
# End triggerPdb.py

Now pdb get's confused about the module level binding:
# Begin failure example:
$ python triggerPdb.py
> /home/n/sandbox/python-module-binding-bug-src/triggerPdb.py(3)<module>()
-> import buggy
(Pdb) next
We are the Knights who say: 'Ni!'
TypeError: "unsupported operand type(s) for +: 'int' and 'str'"
> /home/n/sandbox/python-module-binding-bug-src/triggerPdb.py(3)<module>()
-> import buggy
(Pdb) down
> /home/n/sandbox/python-module-binding-bug/buggy.py(3)<module>()
-> 42 + whatKnightsSay
(Pdb) list
  1     whatKnightsSay = 'Ni!'
  2     print 'We are the Knights who say: %r' % (whatKnightsSay,)
  3  -> 42 + whatKnightsSay
[EOF]
(Pdb) p whatKnightsSay
None
 
# End failing example.


I've included these two simple sources, as well as another that does traceback inspection in an except clause (which fails like the second example here).




History
Date User Action Args
2007-08-23 14:58:20adminlinkissue1748015 messages
2007-08-23 14:58:20admincreate