[pypy-commit] pypy refactor-wrapped-del: Improve error reporting.

arigo noreply at buildbot.pypy.org
Mon Jul 11 19:17:01 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: refactor-wrapped-del
Changeset: r45468:cdd54b72b4d4
Date: 2011-07-11 12:27 +0200
http://bitbucket.org/pypy/pypy/changeset/cdd54b72b4d4/

Log:	Improve error reporting.

diff --git a/pypy/rpython/rclass.py b/pypy/rpython/rclass.py
--- a/pypy/rpython/rclass.py
+++ b/pypy/rpython/rclass.py
@@ -388,20 +388,25 @@
         # XXX wrong complexity, but good enough because the set of
         # reachable graphs should be small
         callgraph = self.rtyper.annotator.translator.callgraph.values()
-        seen = set([graph])
+        seen = {graph: None}
         while True:
             oldlength = len(seen)
             for caller, callee in callgraph:
-                if caller in seen:
-                    seen.add(callee)
+                if caller in seen and callee not in seen:
+                    if (hasattr(callee, 'func') and
+                        getattr(callee.func, '_dont_reach_me_in_del_',False)):
+                        lst = [str(callee)]
+                        g = caller
+                        while g:
+                            lst.append(str(g))
+                            g = seen.get(g)
+                        lst.append('')
+                        raise TyperError("the RPython-level __del__() method "
+                                         "in %r calls:%s" % (
+                            graph, '\n\t'.join(lst[::-1])))
+                    seen[callee] = caller
             if len(seen) == oldlength:
                 break
-        for reachable_graph in seen:
-            if (hasattr(reachable_graph, 'func') and
-                getattr(reachable_graph.func, '_dont_reach_me_in_del_',False)):
-                raise TyperError("the RPython-level __del__() method in %r "
-                                 "ends up indirectly calling %r" % (
-                    graph, reachable_graph))
 
 # ____________________________________________________________
 
diff --git a/pypy/rpython/test/test_rclass.py b/pypy/rpython/test/test_rclass.py
--- a/pypy/rpython/test/test_rclass.py
+++ b/pypy/rpython/test/test_rclass.py
@@ -1038,7 +1038,8 @@
             a.bar()
         t = TranslationContext()
         t.buildannotator().build_types(f, [])
-        py.test.raises(TyperError, t.buildrtyper().specialize)
+        e = py.test.raises(TyperError, t.buildrtyper().specialize)
+        print e.value
 
     def test_instance_repr(self):
         from pypy.rlib.objectmodel import current_object_addr_as_int


More information about the pypy-commit mailing list