mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
This commit is contained in:
		
							parent
							
								
									52035a04ab
								
							
						
					
					
						commit
						775fd66d7b
					
				
					 4 changed files with 116 additions and 1 deletions
				
			
		|  | @ -85,6 +85,17 @@ def copy(self): | |||
|                 new[key] = o | ||||
|         return new | ||||
| 
 | ||||
|     __copy__ = copy | ||||
| 
 | ||||
|     def __deepcopy__(self, memo): | ||||
|         from copy import deepcopy | ||||
|         new = self.__class__() | ||||
|         for key, wr in self.data.items(): | ||||
|             o = wr() | ||||
|             if o is not None: | ||||
|                 new[deepcopy(key, memo)] = o | ||||
|         return new | ||||
| 
 | ||||
|     def get(self, key, default=None): | ||||
|         try: | ||||
|             wr = self.data[key] | ||||
|  | @ -256,6 +267,17 @@ def copy(self): | |||
|                 new[o] = value | ||||
|         return new | ||||
| 
 | ||||
|     __copy__ = copy | ||||
| 
 | ||||
|     def __deepcopy__(self, memo): | ||||
|         from copy import deepcopy | ||||
|         new = self.__class__() | ||||
|         for key, value in self.data.items(): | ||||
|             o = key() | ||||
|             if o is not None: | ||||
|                 new[o] = deepcopy(value, memo) | ||||
|         return new | ||||
| 
 | ||||
|     def get(self, key, default=None): | ||||
|         return self.data.get(ref(key),default) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Antoine Pitrou
						Antoine Pitrou