Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r90613:69629e27d040
Date: 2017-03-09 18:18 +0100
http://bitbucket.org/pypy/pypy/changeset/69629e27d040/

Log:    issue #2491: cpyext types are allowed to have non-strings as
        '__qualname__'. Used for meta-types maybe? Untested

diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -494,10 +494,10 @@
             minsize = rffi.sizeof(PyObject.TO)
         new_layout = (pto.c_tp_basicsize > minsize or pto.c_tp_itemsize > 0)
 
+        self.flag_cpytype = True
         W_TypeObject.__init__(self, space, name,
             bases_w or [space.w_object], dict_w, force_new_layout=new_layout,
             is_heaptype=flag_heaptype)
-        self.flag_cpytype = True
         # if a sequence or a mapping, then set the flag to force it
         if pto.c_tp_as_sequence and pto.c_tp_as_sequence.c_sq_item:
             self.flag_map_or_seq = 'S'
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
@@ -168,6 +168,9 @@
     # used to cache the type's __new__ function
     w_new_function = None
 
+    # set to True by cpyext _before_ it even calls __init__() below
+    flag_cpytype = False
+
     @dont_look_inside
     def __init__(self, space, name, bases_w, dict_w,
                  overridetypedef=None, force_new_layout=False,
@@ -183,7 +186,6 @@
         self.w_doc = space.w_None
         self.weak_subclasses = []
         self.flag_heaptype = is_heaptype
-        self.flag_cpytype = False
         self.flag_abstract = False
         self.flag_sequence_bug_compat = False
         self.flag_map_or_seq = '?'   # '?' means "don't know, check otherwise"
@@ -194,18 +196,16 @@
         else:
             layout = setup_user_defined_type(self, force_new_layout)
         self.layout = layout
+        self.qualname = self.getname(space)
         if self.flag_heaptype:
             w_qualname = self.dict_w.pop('__qualname__', None)
             if w_qualname is not None:
-                if not space.isinstance_w(w_qualname, space.w_unicode):
+                if space.isinstance_w(w_qualname, space.w_unicode):
+                    self.qualname = space.unicode_w(w_qualname)
+                elif not self.flag_cpytype:
                     raise oefmt(space.w_TypeError,
                                 "type __qualname__ must be a str, not %T",
                                 w_qualname)
-                self.qualname = space.unicode_w(w_qualname)
-            else:
-                self.qualname = self.getname(space)
-        else:
-            self.qualname = self.getname(space)
 
         if not is_mro_purely_of_types(self.mro_w):
             pass
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to