[pypy-svn] r17165 - in pypy/dist/pypy: objspace/flow translator

arigo at codespeak.net arigo at codespeak.net
Fri Sep 2 14:42:53 CEST 2005


Author: arigo
Date: Fri Sep  2 14:42:52 2005
New Revision: 17165

Modified:
   pypy/dist/pypy/objspace/flow/model.py
   pypy/dist/pypy/translator/translator.py
Log:
When making the flow graph of a function, grab its source code lazily.
(Workaround for possibly buggy inspect.getsource())


Modified: pypy/dist/pypy/objspace/flow/model.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/model.py	(original)
+++ pypy/dist/pypy/objspace/flow/model.py	Fri Sep  2 14:42:52 2005
@@ -30,6 +30,16 @@
 
 __metaclass__ = type
 
+class roproperty(object):
+    def __init__(self, getter):
+        self.getter = getter
+    def __get__(self, obj, cls=None):
+        if obj is None:
+            return self
+        else:
+            return self.getter(obj)
+
+
 class FunctionGraph(object):
     
     def __init__(self, name, startblock, return_var=None):
@@ -52,6 +62,11 @@
     def getreturnvar(self):
         return self.returnblock.inputargs[0]
 
+    def getsource(self):
+        from pypy.tool.sourcetools import getsource
+        return getsource(self.func)
+    source = roproperty(getsource)
+
 ##    def hasonlyexceptionreturns(self):
 ##        try:
 ##            return self._onlyex

Modified: pypy/dist/pypy/translator/translator.py
==============================================================================
--- pypy/dist/pypy/translator/translator.py	(original)
+++ pypy/dist/pypy/translator/translator.py	Fri Sep  2 14:42:52 2005
@@ -74,11 +74,6 @@
             self.flowgraphs[func] = graph
             self.functions.append(func)
             graph.func = func
-            try:
-                import inspect
-                graph.source = inspect.getsource(func)
-            except:
-                pass  # e.g. when func is defined interactively
         if called_by:
             self.callgraph[called_by, func, call_tag] = called_by, func
         return graph



More information about the Pypy-commit mailing list