[pypy-commit] pypy py3.3: Set __qualname__ of builtin methods

amauryfa noreply at buildbot.pypy.org
Thu Jan 8 22:21:26 CET 2015


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3.3
Changeset: r75259:826457bf5cda
Date: 2015-01-08 18:42 +0100
http://bitbucket.org/pypy/pypy/changeset/826457bf5cda/

Log:	Set __qualname__ of builtin methods

diff --git a/lib-python/3/test/test_funcattrs.py b/lib-python/3/test/test_funcattrs.py
--- a/lib-python/3/test/test_funcattrs.py
+++ b/lib-python/3/test/test_funcattrs.py
@@ -121,7 +121,8 @@
         self.b.__qualname__ = 'd'
         self.assertEqual(self.b.__qualname__, 'd')
         # __qualname__ must be a string
-        self.cannot_set_attr(self.b, '__qualname__', 7, TypeError)
+        self.cannot_set_attr(self.b, '__qualname__', 7,
+                             (TypeError, AttributeError))
 
     def test___code__(self):
         num_one, num_two = 7, 8
diff --git a/pypy/objspace/std/test/test_typeobject.py b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -395,6 +395,9 @@
         class D(B, C):    # assert does not raise TypeError
             pass
 
+    def test_method_qualname(self):
+        assert dict.copy.__qualname__ == 'dict.copy'
+
     def test_builtin_add(self):
         x = 5
         assert x.__add__(6) == 11
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
@@ -1,7 +1,8 @@
 from pypy.interpreter import gateway
 from pypy.interpreter.baseobjspace import W_Root, SpaceCache
 from pypy.interpreter.error import oefmt, OperationError
-from pypy.interpreter.function import Function, StaticMethod
+from pypy.interpreter.function import (
+    Function, StaticMethod, FunctionWithFixedCode)
 from pypy.interpreter.typedef import weakref_descr, GetSetProperty,\
      descr_get_dict, dict_descr, Member, TypeDef
 from pypy.interpreter.astcompiler.misc import mangle
@@ -1263,8 +1264,17 @@
             overridetypedef = typedef
         w_type = W_TypeObject(space, typedef.name, bases_w, dict_w,
                               overridetypedef=overridetypedef)
+
         if typedef is not overridetypedef:
             w_type.w_doc = space.wrap(typedef.doc)
+        else:
+            # Set the __qualname__ of member functions
+            for name in rawdict:
+                w_obj = dict_w[name]
+                if isinstance(w_obj, FunctionWithFixedCode):
+                    qualname = w_type.getqualname(space) + '.' + name
+                    w_obj.fset_func_qualname(space, space.wrap(qualname))
+                
         if hasattr(typedef, 'flag_sequence_bug_compat'):
             w_type.flag_sequence_bug_compat = typedef.flag_sequence_bug_compat
         w_type.lazyloaders = lazyloaders


More information about the pypy-commit mailing list