diff options
| author | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-09-13 16:45:02 (GMT) | 
|---|---|---|
| committer | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-09-13 16:45:02 (GMT) | 
| commit | 9d17da33e2dcc51c73fdebe737eb1b9317ee69cd (patch) | |
| tree | 4437e3ee2328f9cb83391f81338261c19e2c1e7e /Lib/trace.py | |
| parent | c0c0b146718f3098397c287d2e03028f486606ee (diff) | |
| download | cpython-9d17da33e2dcc51c73fdebe737eb1b9317ee69cd.zip cpython-9d17da33e2dcc51c73fdebe737eb1b9317ee69cd.tar.gz cpython-9d17da33e2dcc51c73fdebe737eb1b9317ee69cd.tar.bz2  | |
Issue #9315: Fix for the trace module to record correct class name
when tracing methods.  Unit tests. Patch by Eli Bendersky.
Diffstat (limited to 'Lib/trace.py')
| -rw-r--r-- | Lib/trace.py | 12 | 
1 files changed, 4 insertions, 8 deletions
diff --git a/Lib/trace.py b/Lib/trace.py index 43a5d33..7ec0cf6 100644 --- a/Lib/trace.py +++ b/Lib/trace.py @@ -56,7 +56,7 @@ import threading  import time  import token  import tokenize -import types +import inspect  import gc  try: @@ -398,7 +398,7 @@ def find_lines(code, strs):      # and check the constants for references to other code objects      for c in code.co_consts: -        if isinstance(c, types.CodeType): +        if inspect.iscode(c):              # find another code object, so recurse into it              linenos.update(find_lines(c, strs))      return linenos @@ -545,7 +545,7 @@ class Trace:              ## use of gc.get_referrers() was suggested by Michael Hudson              # all functions which refer to this code object              funcs = [f for f in gc.get_referrers(code) -                         if hasattr(f, "func_doc")] +                         if inspect.isfunction(f)]              # require len(func) == 1 to avoid ambiguity caused by calls to              # new.function(): "In the face of ambiguity, refuse the              # temptation to guess." @@ -557,17 +557,13 @@ class Trace:                                     if hasattr(c, "__bases__")]                      if len(classes) == 1:                          # ditto for new.classobj() -                        clsname = str(classes[0]) +                        clsname = classes[0].__name__                          # cache the result - assumption is that new.* is                          # not called later to disturb this relationship                          # _caller_cache could be flushed if functions in                          # the new module get called.                          self._caller_cache[code] = clsname          if clsname is not None: -            # final hack - module name shows up in str(cls), but we've already -            # computed module name, so remove it -            clsname = clsname.split(".")[1:] -            clsname = ".".join(clsname)              funcname = "%s.%s" % (clsname, funcname)          return filename, modulename, funcname  | 
