[pypy-svn] r20823 - in pypy/dist/pypy: annotation objspace/flow tool

mwh at codespeak.net mwh at codespeak.net
Wed Dec 7 11:12:16 CET 2005


Author: mwh
Date: Wed Dec  7 11:12:14 2005
New Revision: 20823

Modified:
   pypy/dist/pypy/annotation/description.py
   pypy/dist/pypy/objspace/flow/model.py
   pypy/dist/pypy/tool/sourcetools.py
Log:
supply a default alt_name for specialized functions if none is supplied
in the spirit of what happened before the somepbc-refactoring branch
landed, so you get names like wrap__str in the resulting graph.


Modified: pypy/dist/pypy/annotation/description.py
==============================================================================
--- pypy/dist/pypy/annotation/description.py	(original)
+++ pypy/dist/pypy/annotation/description.py	Wed Dec  7 11:12:14 2005
@@ -168,6 +168,21 @@
         try:
             return self._cache[key]
         except KeyError:
+            def nameof(thing):
+                if isinstance(thing, str):
+                    return thing
+                elif hasattr(thing, '__name__'): # mostly types and functions
+                    return thing.__name__
+                elif hasattr(thing, 'name'): # mostly ClassDescs
+                    return thing.name
+                elif isinstance(thing, tuple):
+                    return '_'.join(map(nameof, thing))
+                else:
+                    return str(thing)[:30]
+                
+            if key is not None and alt_name is None:
+                postfix = nameof(key)
+                alt_name = "%s__%s"%(self.name, postfix)
             graph = self.buildgraph(alt_name, builder)
             self._cache[key] = graph
             return graph

Modified: pypy/dist/pypy/objspace/flow/model.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/model.py	(original)
+++ pypy/dist/pypy/objspace/flow/model.py	Wed Dec  7 11:12:14 2005
@@ -68,7 +68,7 @@
 
     def __repr__(self):
         if hasattr(self, 'func'):
-            fnrepr = nice_repr_for_func(self.func)
+            fnrepr = nice_repr_for_func(self.func, self.name)
         else:
             fnrepr = self.name
         return '<FunctionGraph of %s at 0x%x>' % (fnrepr, uid(self))

Modified: pypy/dist/pypy/tool/sourcetools.py
==============================================================================
--- pypy/dist/pypy/tool/sourcetools.py	(original)
+++ pypy/dist/pypy/tool/sourcetools.py	Wed Dec  7 11:12:14 2005
@@ -249,11 +249,12 @@
     func = getattr(func, 'func_code', func)
     return (func.co_flags & CO_VARKEYWORDS) != 0
 
-def nice_repr_for_func(fn):
+def nice_repr_for_func(fn, name=None):
     mod = getattr(fn, '__module__', None)
     if mod is None:
         mod = '?'
-    name = getattr(fn, '__name__', None)
+    if name is None:
+        name = getattr(fn, '__name__', None)
     if name is not None:
         firstlineno = fn.func_code.co_firstlineno
     else:



More information about the Pypy-commit mailing list