[pypy-commit] pypy mappingproxy: Move cpyext implementation of mappingproxy to objspace
rlamy
pypy.commits at gmail.com
Wed Aug 3 00:29:23 EDT 2016
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: mappingproxy
Changeset: r85999:fd9153375a2a
Date: 2016-08-03 05:17 +0100
http://bitbucket.org/pypy/pypy/changeset/fd9153375a2a/
Log: Move cpyext implementation of mappingproxy to objspace
diff --git a/pypy/module/cpyext/dictproxyobject.py b/pypy/module/cpyext/dictproxyobject.py
--- a/pypy/module/cpyext/dictproxyobject.py
+++ b/pypy/module/cpyext/dictproxyobject.py
@@ -1,67 +1,7 @@
-# Read-only proxy for mappings. PyPy does not have a separate type for
-# type.__dict__, so PyDictProxy_New has to use a custom read-only mapping.
-
-from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.gateway import unwrap_spec, WrappedDefault
-from pypy.interpreter.typedef import TypeDef, interp2app
+from pypy.objspace.std.dictproxyobject import W_DictProxyObject
from pypy.module.cpyext.api import cpython_api, build_type_checkers
from pypy.module.cpyext.pyobject import PyObject
-class W_DictProxyObject(W_Root):
- "Read-only proxy for mappings."
-
- def __init__(self, w_mapping):
- self.w_mapping = w_mapping
-
- def descr_len(self, space):
- return space.len(self.w_mapping)
-
- def descr_getitem(self, space, w_key):
- return space.getitem(self.w_mapping, w_key)
-
- def descr_contains(self, space, w_key):
- return space.contains(self.w_mapping, w_key)
-
- def descr_iter(self, space):
- return space.iter(self.w_mapping)
-
- def descr_str(self, space):
- return space.str(self.w_mapping)
-
- def descr_repr(self, space):
- return space.repr(self.w_mapping)
-
- @unwrap_spec(w_default=WrappedDefault(None))
- def get_w(self, space, w_key, w_default):
- return space.call_method(self.w_mapping, "get", w_key, w_default)
-
- def keys_w(self, space):
- return space.call_method(self.w_mapping, "keys")
-
- def values_w(self, space):
- return space.call_method(self.w_mapping, "values")
-
- def items_w(self, space):
- return space.call_method(self.w_mapping, "items")
-
- def copy_w(self, space):
- return space.call_method(self.w_mapping, "copy")
-
-W_DictProxyObject.typedef = TypeDef(
- 'mappingproxy',
- __len__=interp2app(W_DictProxyObject.descr_len),
- __getitem__=interp2app(W_DictProxyObject.descr_getitem),
- __contains__=interp2app(W_DictProxyObject.descr_contains),
- __iter__=interp2app(W_DictProxyObject.descr_iter),
- __str__=interp2app(W_DictProxyObject.descr_str),
- __repr__=interp2app(W_DictProxyObject.descr_repr),
- get=interp2app(W_DictProxyObject.get_w),
- keys=interp2app(W_DictProxyObject.keys_w),
- values=interp2app(W_DictProxyObject.values_w),
- items=interp2app(W_DictProxyObject.items_w),
- copy=interp2app(W_DictProxyObject.copy_w)
-)
-
PyDictProxy_Check, PyDictProxy_CheckExact = build_type_checkers(
"DictProxy", W_DictProxyObject)
diff --git a/pypy/module/cpyext/dictproxyobject.py b/pypy/objspace/std/dictproxyobject.py
copy from pypy/module/cpyext/dictproxyobject.py
copy to pypy/objspace/std/dictproxyobject.py
--- a/pypy/module/cpyext/dictproxyobject.py
+++ b/pypy/objspace/std/dictproxyobject.py
@@ -4,8 +4,6 @@
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.gateway import unwrap_spec, WrappedDefault
from pypy.interpreter.typedef import TypeDef, interp2app
-from pypy.module.cpyext.api import cpython_api, build_type_checkers
-from pypy.module.cpyext.pyobject import PyObject
class W_DictProxyObject(W_Root):
"Read-only proxy for mappings."
@@ -61,10 +59,3 @@
items=interp2app(W_DictProxyObject.items_w),
copy=interp2app(W_DictProxyObject.copy_w)
)
-
-PyDictProxy_Check, PyDictProxy_CheckExact = build_type_checkers(
- "DictProxy", W_DictProxyObject)
-
- at cpython_api([PyObject], PyObject)
-def PyDictProxy_New(space, w_dict):
- return space.wrap(W_DictProxyObject(w_dict))
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
@@ -486,11 +486,13 @@
def getdict(self, space): # returning a dict-proxy!
from pypy.objspace.std.classdict import ClassDictStrategy
from pypy.objspace.std.dictmultiobject import W_DictObject
+ from pypy.objspace.std.dictproxyobject import W_DictProxyObject
if self.lazyloaders:
self._cleanup_() # force un-lazification
strategy = space.fromcache(ClassDictStrategy)
storage = strategy.erase(self)
- return W_DictObject(space, strategy, storage)
+ w_dict = W_DictObject(space, strategy, storage)
+ return W_DictProxyObject(w_dict)
def is_heaptype(self):
return self.flag_heaptype
More information about the pypy-commit
mailing list