Author: Armin Rigo <[email protected]>
Branch: issue2464
Changeset: r89554:2d4f56fdba06
Date: 2017-01-14 09:38 +0100
http://bitbucket.org/pypy/pypy/changeset/2d4f56fdba06/
Log: Found a generic way to solve the __objclass__ problem
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -276,12 +276,15 @@
self.use_closure = use_closure
def copy_for_type(self, w_objclass):
- new = instantiate(GetSetProperty)
- new._init(self.fget, self.fset, self.fdel, self.doc, self.reqcls,
- None, self.use_closure)
- new.name = self.name
- new.w_objclass = w_objclass
- return new
+ if self.objclass_getter is None:
+ new = instantiate(GetSetProperty)
+ new._init(self.fget, self.fset, self.fdel, self.doc, self.reqcls,
+ None, self.use_closure)
+ new.name = self.name
+ new.w_objclass = w_objclass
+ return new
+ else:
+ return self
@unwrap_spec(w_cls = WrappedDefault(None))
def descr_property_get(self, space, w_obj, w_cls=None):
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
@@ -1329,3 +1329,6 @@
pass
assert X.__dict__['__dict__'].__objclass__ is X
assert X.__dict__['__weakref__'].__objclass__ is X
+ assert object.__dict__['__class__'].__objclass__ is object
+ assert int.__dict__['imag'].__objclass__ is int
+ assert file.closed.__objclass__ is file
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
@@ -1312,10 +1312,13 @@
def build(self, typedef):
"NOT_RPYTHON: initialization-time only."
from pypy.objspace.std.objectobject import W_ObjectObject
+ from pypy.interpreter.typedef import GetSetProperty
+ from rpython.rlib.objectmodel import instantiate
space = self.space
rawdict = typedef.rawdict
lazyloaders = {}
+ w_type = instantiate(W_TypeObject)
# compute the bases
if typedef is W_ObjectObject.typedef:
@@ -1327,13 +1330,16 @@
# wrap everything
dict_w = {}
for descrname, descrvalue in rawdict.items():
+ # special case for GetSetProperties' __objclass__:
+ if isinstance(descrvalue, GetSetProperty):
+ descrvalue = descrvalue.copy_for_type(w_type)
dict_w[descrname] = space.wrap(descrvalue)
if typedef.applevel_subclasses_base is not None:
overridetypedef = typedef.applevel_subclasses_base.typedef
else:
overridetypedef = typedef
- w_type = W_TypeObject(space, typedef.name, bases_w, dict_w,
+ w_type.__init__(space, typedef.name, bases_w, dict_w,
overridetypedef=overridetypedef,
is_heaptype=overridetypedef.heaptype)
if typedef is not overridetypedef:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit