[pypy-commit] pypy mappingproxy: Allow attribute deletion on C-defined types
rlamy
pypy.commits at gmail.com
Fri Aug 5 11:47:53 EDT 2016
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: mappingproxy
Changeset: r86034:016781b80468
Date: 2016-08-05 16:47 +0100
http://bitbucket.org/pypy/pypy/changeset/016781b80468/
Log: Allow attribute deletion on C-defined types
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
@@ -294,6 +294,15 @@
assert type(obj)._some_attribute == 1
del d["_some_attribute"]
+ class A(object):
+ pass
+ obj = A()
+ d = module.get_type_dict(obj)
+ assert type(d) is dict
+ d["_some_attribute"] = 1
+ assert type(obj)._some_attribute == 1
+ del d["_some_attribute"]
+
d = module.get_type_dict(1)
assert type(d) is dict
try:
@@ -371,6 +380,21 @@
api.Py_DecRef(ref)
+ def test_type_dict(self, space, api):
+ w_class = space.appexec([], """():
+ class A(object):
+ pass
+ return A
+ """)
+ ref = make_ref(space, w_class)
+
+ py_type = rffi.cast(PyTypeObjectPtr, ref)
+ w_dict = from_ref(space, py_type.c_tp_dict)
+ w_name = space.newunicode(u'a')
+ space.setitem(w_dict, w_name, space.wrap(1))
+ assert space.int_w(space.getattr(w_class, w_name)) == 1
+ space.delitem(w_dict, w_name)
+
def test_multiple_inheritance(self, space, api):
w_class = space.appexec([], """():
class A(object):
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
@@ -344,7 +344,7 @@
def deldictvalue(self, space, key):
if self.lazyloaders:
self._cleanup_() # force un-lazification
- if not self.is_heaptype():
+ if not (self.is_heaptype() or self.is_cpytype()):
raise oefmt(space.w_TypeError,
"can't delete attributes on type object '%N'", self)
try:
More information about the pypy-commit
mailing list