[New-bugs-announce] [issue9282] Bug in --listfuncs option of trace.py

Eli Bendersky report at bugs.python.org
Sat Jul 17 10:38:40 CEST 2010


New submission from Eli Bendersky <eliben at gmail.com>:

Running:

py3d -m trace -C . --listfuncs trace_target.py

Where py3d points to a freshly compiled Python 3 trunk interpreter, results in an error: 

functions called:
Traceback (most recent call last):
  File "/home/eliben/python_src/eliben-py3k/Lib/runpy.py", line 160, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/home/eliben/python_src/eliben-py3k/Lib/runpy.py", line 73, in _run_code
    exec(code, run_globals)
  File "/home/eliben/python_src/eliben-py3k/Lib/trace.py", line 816, in <module>
    main()
  File "/home/eliben/python_src/eliben-py3k/Lib/trace.py", line 813, in main
    results.write_results(missing, summary=summary, coverdir=coverdir)
  File "/home/eliben/python_src/eliben-py3k/Lib/trace.py", line 260, in write_results
    for filename, modulename, funcname in sorted(calls.keys()):
NameError: global name 'calls' is not defined


--------------

With Python 2.x it runs fine. The cause is probably a bug introduced during the porting to Python 3. The relevant piece of code in the write_results() method in trace.py is:

        if self.calledfuncs:
            print()
            print("functions called:")
            for filename, modulename, funcname in sorted(calls.keys()):
                print(("filename: %s, modulename: %s, funcname: %s"
                       % (filename, modulename, funcname)))

The 'calls' variable in the loop isn't defined anywhere. Previously (in 2.6) this same chunk of code looked like this:

        if self.calledfuncs:
            print
            print "functions called:"
            calls = self.calledfuncs.keys()
            calls.sort()
            for filename, modulename, funcname in calls:
                print ("filename: %s, modulename: %s, funcname: %s"
                       % (filename, modulename, funcname))

Which aliases 'calls' to 'self.calledfuncs.keys()'

------

Once this is confirmed as a bug, I will be happy to submit a patch that solves the problem.

----------
components: Library (Lib)
messages: 110543
nosy: eli.bendersky, tjreedy
priority: normal
severity: normal
status: open
title: Bug in --listfuncs option of trace.py
type: behavior
versions: Python 3.1, Python 3.2, Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9282>
_______________________________________


More information about the New-bugs-announce mailing list