Author: Armin Rigo <[email protected]>
Branch:
Changeset: r84347:415b6c689836
Date: 2016-05-10 11:19 +0200
http://bitbucket.org/pypy/pypy/changeset/415b6c689836/
Log: Metaclass support: revert a change done in e6d78e83ee3c that would
not set is_cpytype() on cpyext subtypes of type. Unsure why it was
needed at that point in time, but it doesn't appear to be now, and
it gets massively in the way, because it confuses
pypy.tool.ann_override.
diff --git a/pypy/module/cpyext/test/test_typeobject.py
b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -1,3 +1,4 @@
+from pypy.interpreter import gateway
from rpython.rtyper.lltypesystem import rffi
from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
from pypy.module.cpyext.test.test_api import BaseApiTest
@@ -391,6 +392,14 @@
api.Py_DecRef(ref)
class AppTestSlots(AppTestCpythonExtensionBase):
+ def setup_class(cls):
+ AppTestCpythonExtensionBase.setup_class.im_func(cls)
+ def _check_type_object(w_X):
+ assert w_X.is_cpytype()
+ assert not w_X.is_heaptype()
+ cls.w__check_type_object = cls.space.wrap(
+ gateway.interp2app(_check_type_object))
+
def test_some_slots(self):
module = self.import_extension('foo', [
("test_type", "METH_O",
@@ -1050,3 +1059,29 @@
x = module.new_obj()
assert x() == 42
assert x(4, bar=5) == 42
+
+ def test_custom_metaclass(self):
+ module = self.import_extension('foo', [
+ ("getMetaClass", "METH_NOARGS",
+ '''
+ PyObject *obj;
+ FooType_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ FooType_Type.tp_base = &PyType_Type;
+ if (PyType_Ready(&FooType_Type) < 0) return NULL;
+ Py_INCREF(&FooType_Type);
+ return (PyObject *)&FooType_Type;
+ '''
+ )],
+ '''
+ static PyTypeObject FooType_Type = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "foo.Type",
+ };
+ ''')
+ FooType = module.getMetaClass()
+ if not self.runappdirect:
+ self._check_type_object(FooType)
+ class X(object):
+ __metaclass__ = FooType
+ print repr(X)
+ X()
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
@@ -405,8 +405,7 @@
W_TypeObject.__init__(self, space, name,
bases_w or [space.w_object], dict_w, force_new_layout=new_layout)
- if not space.is_true(space.issubtype(self, space.w_type)):
- self.flag_cpytype = True
+ self.flag_cpytype = True
self.flag_heaptype = False
# 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:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit