[pypy-svn] pypy default: For test_cprofile: get the exact same repr as CPython, which is a
arigo
commits-noreply at bitbucket.org
Sat Feb 12 21:05:20 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r41857:905a25d69a1e
Date: 2011-02-12 21:03 +0100
http://bitbucket.org/pypy/pypy/changeset/905a25d69a1e/
Log: For test_cprofile: get the exact same repr as CPython, which is a
bit more precise. Unfortunately it requires a bit of hacking for
built-in methods.
diff --git a/pypy/module/_lsprof/interp_lsprof.py b/pypy/module/_lsprof/interp_lsprof.py
--- a/pypy/module/_lsprof/interp_lsprof.py
+++ b/pypy/module/_lsprof/interp_lsprof.py
@@ -163,11 +163,19 @@
def create_spec(space, w_arg):
if isinstance(w_arg, Method):
w_function = w_arg.w_function
- class_name = w_arg.w_class.getname(space, '?')
if isinstance(w_function, Function):
name = w_function.name
else:
name = '?'
+ # try to get the real class that defines the method,
+ # which is a superclass of the class of the instance
+ from pypy.objspace.std.typeobject import W_TypeObject # xxx
+ w_type = w_arg.w_class
+ class_name = w_type.getname(space) # if the rest doesn't work
+ if isinstance(w_type, W_TypeObject) and name != '?':
+ w_realclass, _ = space.lookup_in_type_where(w_type, name)
+ if isinstance(w_realclass, W_TypeObject):
+ class_name = w_realclass.get_module_type_name()
return "{method '%s' of '%s' objects}" % (name, class_name)
elif isinstance(w_arg, Function):
if w_arg.w_module is None:
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -408,6 +408,18 @@
return w_self.dict_w['__module__']
return space.wrap('__builtin__')
+ def get_module_type_name(w_self):
+ space = w_self.space
+ w_mod = w_self.get_module()
+ if not space.is_true(space.isinstance(w_mod, space.w_str)):
+ mod = '__builtin__'
+ else:
+ mod = space.str_w(w_mod)
+ if mod !='__builtin__':
+ return '%s.%s' % (mod, w_self.name)
+ else:
+ return w_self.name
+
def add_subclass(w_self, w_subclass):
space = w_self.space
if not space.config.translation.rweakref:
diff --git a/pypy/module/_lsprof/test/test_cprofile.py b/pypy/module/_lsprof/test/test_cprofile.py
--- a/pypy/module/_lsprof/test/test_cprofile.py
+++ b/pypy/module/_lsprof/test/test_cprofile.py
@@ -177,7 +177,7 @@
8 0.312 0.039 0.400 0.050 profilee.py:88(helper2)
8 0.064 0.008 0.080 0.010 profilee.py:98(subhelper)
4 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
- 1 0.000 0.000 0.000 0.000 {.*disable.*}
+ 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
12 0.000 0.000 0.012 0.001 {hasattr}
8 0.000 0.000 0.000 0.000 {range}
4 0.000 0.000 0.000 0.000 {sys.exc_info}
More information about the Pypy-commit
mailing list