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.

classification
Title: Bug in --listfuncs option of trace.py
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder: The trace module lacks unit tests
View: 9315
Assigned To: belopolsky Nosy List: belopolsky, eli.bendersky, terry.reedy
Priority: normal Keywords: patch

Created on 2010-07-17 08:38 by eli.bendersky, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue9282.1.patch eli.bendersky, 2010-07-17 12:18
Messages (7)
msg110543 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2010-07-17 08:38
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.
msg110549 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2010-07-17 12:18
The fix is simple one-liner, so here's a patch.
msg110611 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-07-17 22:44
Looking at the 2.x code, that is the obvious fix. I think this ready to commit.
msg110713 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-07-19 04:03
Trace.py does not appear to have a test module to add a test case to.
test_trace.py currently tests the line trace facility turned on with sys.settrace. I will inquire on pydev about this. "Does trace ..."
msg110933 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2010-07-20 17:46
I've opened issue 9315 to address the lack of unit tests for trace.py

I think that this should be committed regardless, since it fixes a serious bug in the module. Adding unit tests can take time, and is less critical.
msg110957 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-07-20 19:38
This is clearly an artifact of porting to 3.x.  In 2.x the code was


            calls = self.calledfuncs.keys()
            calls.sort()
            for filename, modulename, funcname in calls:

which was translated to

           for filename, modulename, funcname in sorted(calls.keys()):

missing the calls assignment.  I am going to commit this patch.
msg110967 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-07-20 20:32
Committed with a minor change to meet 80-character line limit.

See r82997 (r82999 for 3.1).
History
Date User Action Args
2022-04-11 14:57:03adminsetgithub: 53528
2010-07-20 20:32:59belopolskysetstatus: open -> closed
resolution: accepted -> fixed
messages: + msg110967

stage: commit review -> resolved
2010-07-20 19:38:04belopolskysetnosy: + belopolsky
messages: + msg110957

assignee: belopolsky
superseder: The trace module lacks unit tests
resolution: accepted
2010-07-20 17:46:53eli.benderskysetmessages: + msg110933
2010-07-19 04:03:45terry.reedysetmessages: + msg110713
2010-07-17 22:44:45terry.reedysetstage: commit review
messages: + msg110611
versions: - Python 3.3
2010-07-17 12:18:03eli.benderskysetfiles: + issue9282.1.patch
keywords: + patch
messages: + msg110549
2010-07-17 08:38:39eli.benderskycreate