1. Pypy
  2. Untitled project
  3. pypy

Commits

Dario Bertini  committed 7b1d0c4

(berdario, antocuni)
Changed the Wrapper/Adapter to make it more sane

  • Participants
  • Parent commits d9ea05b
  • Branches default

Comments (0)

Files changed (1)

File lib-python/modified-2.7/copy.py

View file
  • Ignore whitespace
 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)]
         
     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
     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:
         return x
     assert isinstance(info, tuple)
     
-    memo = _MemoWrapper(memo)
+    memo = _get_memo(memo)
     
     n = len(info)
     assert n in (2, 3, 4, 5)