Permalink
Browse files

Tweaks to callgraph.py so it can walk byterun.

Hooking up byterun to opy_main.py caused some errors.

(byterun will probably never be shipped, at least not in its current
form.  But it's still useful to see what code is used transitively.)
  • Loading branch information...
Andy Chu
Andy Chu committed Apr 9, 2018
1 parent 9a0d22b commit 8ee52710fa0d861ccdfabb68337713ae6cc43033
Showing with 14 additions and 4 deletions.
  1. +14 −4 opy/callgraph.py
View
@@ -141,15 +141,22 @@ def _Walk(obj, cls, ref, syms):
# log('OBJ %s %d', obj, id(obj))
# pass
if module_name is None:
# Oh is the namedtuple_ crap because of the Block class byterun/pyobj?
if module_name is None or module_name in (
'namedtuple_Arguments', 'namedtuple_ArgSpec',
'namedtuple_Block'):
syms.Add(obj, None, ref, None, None, None)
return # Can't walk anything
#log('OBJ %s %d', obj, id(obj))
module = sys.modules[obj.__module__]
#print(obj)
if hasattr(obj, '__code__'): # Builtins don't have bytecode.
co = getattr(obj, '__code__', None)
# For example, Builtins don't have bytecode.
if isinstance(co, types.CodeType):
co = obj.__code__
#log('CO %s', co)
#path = co.co_filename
mod_name = None
@@ -348,7 +355,10 @@ def Add(self, obj, cls, ref, mod_name, mod_path, line_num):
# NOTE: Python's classes don't have a __code__ object, which appears to
# be an irregularity. So we have to get location information from the
# METHODS.
assert not hasattr(obj, '__code__'), obj
# Exception: this type has a __code__ object that is not types.CodeType
if obj is not types.FunctionType:
assert not hasattr(obj, '__code__'), obj
#assert path is None
assert line_num is None

0 comments on commit 8ee5271

Please sign in to comment.