Author: Dario Bertini <[email protected]>
Branch:
Changeset: r45161:7b1d0c454f8a
Date: 2011-06-28 16:35 +0200
http://bitbucket.org/pypy/pypy/changeset/7b1d0c454f8a/
Log: (berdario, antocuni) Changed the Wrapper/Adapter to make it more
sane
diff --git a/lib-python/modified-2.7/copy.py b/lib-python/modified-2.7/copy.py
--- a/lib-python/modified-2.7/copy.py
+++ b/lib-python/modified-2.7/copy.py
@@ -53,23 +53,12 @@
from copy_reg import dispatch_table
from __pypy__ import identity_dict
-class _MemoWrapper(object):
+class _MemoAdapter(object):
"""Wrapper around dictionaries, to make them behave like identity_dict
-(or directly return an identity_dict istance)
used to avoid breaking code that may rely on supplying a dictionary to
deepcopy"""
- def __new__(cls, inner_dict):
- if isinstance(inner_dict, (_MemoWrapper, identity_dict)):
- return inner_dict
- elif inner_dict is None:
- return identity_dict()
- else:
- return super(_MemoWrapper, cls).__new__(cls)
-
+
def __init__(self, inner_dict):
- if isinstance(inner_dict, (_MemoWrapper, identity_dict)):
- return
- else:
- self.inner_dict = inner_dict
+ self.inner_dict = inner_dict
def __getitem__(self, key):
return self.inner_dict[id(key)]
@@ -79,7 +68,15 @@
def get(self, key, *args, **kwargs):
return self.inner_dict.get(id(key), *args, **kwargs)
-
+
+def _get_memo(memo_dict):
+ if isinstance(memo_dict, (_MemoAdapter, identity_dict)):
+ return memo_dict
+ elif memo_dict is None:
+ return identity_dict()
+ else:
+ return _MemoAdapter(memo_dict)
+
class Error(Exception):
pass
@@ -177,7 +174,7 @@
See the module's __doc__ string for more info.
"""
- memo = _MemoWrapper(memo)
+ memo = _get_memo(memo)
y = memo.get(x, _nil)
if y is not _nil:
@@ -334,7 +331,7 @@
return x
assert isinstance(info, tuple)
- memo = _MemoWrapper(memo)
+ memo = _get_memo(memo)
n = len(info)
assert n in (2, 3, 4, 5)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit