mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	Issue #1515: Enable use of deepcopy() with instance methods. Patch by Robert Collins.
This commit is contained in:
		
							parent
							
								
									c63392c152
								
							
						
					
					
						commit
						d16f57bf4d
					
				
					 4 changed files with 19 additions and 0 deletions
				
			
		|  | @ -260,6 +260,10 @@ def _deepcopy_dict(x, memo): | ||||||
| if PyStringMap is not None: | if PyStringMap is not None: | ||||||
|     d[PyStringMap] = _deepcopy_dict |     d[PyStringMap] = _deepcopy_dict | ||||||
| 
 | 
 | ||||||
|  | def _deepcopy_method(x, memo): # Copy instance methods | ||||||
|  |     return type(x)(x.im_func, deepcopy(x.im_self, memo), x.im_class) | ||||||
|  | _deepcopy_dispatch[types.MethodType] = _deepcopy_method | ||||||
|  | 
 | ||||||
| def _keep_alive(x, memo): | def _keep_alive(x, memo): | ||||||
|     """Keeps a reference to the object x in the memo. |     """Keeps a reference to the object x in the memo. | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -672,6 +672,17 @@ def __init__(self, i): | ||||||
|         del d |         del d | ||||||
|         self.assertEqual(len(v), 1) |         self.assertEqual(len(v), 1) | ||||||
| 
 | 
 | ||||||
|  |     def test_deepcopy_bound_method(self): | ||||||
|  |         class Foo(object): | ||||||
|  |             def m(self): | ||||||
|  |                 pass | ||||||
|  |         f = Foo() | ||||||
|  |         f.b = f.m | ||||||
|  |         g = copy.deepcopy(f) | ||||||
|  |         self.assertEqual(g.m, g.b) | ||||||
|  |         self.assertTrue(g.b.im_self is g) | ||||||
|  |         g.b() | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| def global_foo(x, y): return x+y | def global_foo(x, y): return x+y | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -145,6 +145,7 @@ Josh Cogliati | ||||||
| Dave Cole | Dave Cole | ||||||
| Benjamin Collar | Benjamin Collar | ||||||
| Jeffery Collins | Jeffery Collins | ||||||
|  | Robert Collins | ||||||
| Paul Colomiets | Paul Colomiets | ||||||
| Matt Conway | Matt Conway | ||||||
| David M. Cooke | David M. Cooke | ||||||
|  |  | ||||||
|  | @ -483,6 +483,9 @@ Core and Builtins | ||||||
| Library | Library | ||||||
| ------- | ------- | ||||||
| 
 | 
 | ||||||
|  | - Issue #1515: Enable use of deepcopy() with instance methods.  Patch by | ||||||
|  |   Robert Collins. | ||||||
|  | 
 | ||||||
| - Issue #7403: logging: Fixed possible race condition in lock creation. | - Issue #7403: logging: Fixed possible race condition in lock creation. | ||||||
| 
 | 
 | ||||||
| - Issue #6845: Add restart support for binary upload in ftplib.  The | - Issue #6845: Add restart support for binary upload in ftplib.  The | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Antoine Pitrou
						Antoine Pitrou