mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	[3.13] gh-123046: Fix regexp to catch cases where the module name is omitted from the weakref repr (GH-123047) (#123058)
gh-123046: Fix regexp to catch cases where the module name is omitted from the weakref repr (GH-123047)
(cherry picked from commit 786cac0c64)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: sobolevn <mail@sobolevn.me>
			
			
This commit is contained in:
		
							parent
							
								
									5ac14eeea6
								
							
						
					
					
						commit
						a604b2440f
					
				
					 1 changed files with 19 additions and 12 deletions
				
			
		|  | @ -123,10 +123,12 @@ def test_basic_ref(self): | ||||||
|     def test_ref_repr(self): |     def test_ref_repr(self): | ||||||
|         obj = C() |         obj = C() | ||||||
|         ref = weakref.ref(obj) |         ref = weakref.ref(obj) | ||||||
|         self.assertRegex(repr(ref), |         regex = ( | ||||||
|                          rf"<weakref at 0x[0-9a-fA-F]+; " |             rf"<weakref at 0x[0-9a-fA-F]+; " | ||||||
|                          rf"to '{C.__module__}.{C.__qualname__}' " |             rf"to '{'' if __name__ == '__main__' else C.__module__ + '.'}{C.__qualname__}' " | ||||||
|                          rf"at 0x[0-9a-fA-F]+>") |             rf"at 0x[0-9a-fA-F]+>" | ||||||
|  |         ) | ||||||
|  |         self.assertRegex(repr(ref), regex) | ||||||
| 
 | 
 | ||||||
|         obj = None |         obj = None | ||||||
|         gc_collect() |         gc_collect() | ||||||
|  | @ -141,10 +143,13 @@ def __name__(self): | ||||||
| 
 | 
 | ||||||
|         obj2 = WithName() |         obj2 = WithName() | ||||||
|         ref2 = weakref.ref(obj2) |         ref2 = weakref.ref(obj2) | ||||||
|         self.assertRegex(repr(ref2), |         regex = ( | ||||||
|                          rf"<weakref at 0x[0-9a-fA-F]+; " |             rf"<weakref at 0x[0-9a-fA-F]+; " | ||||||
|                          rf"to '{WithName.__module__}.{WithName.__qualname__}' " |             rf"to '{'' if __name__ == '__main__' else WithName.__module__ + '.'}" | ||||||
|                          rf"at 0x[0-9a-fA-F]+ \(custom_name\)>") |             rf"{WithName.__qualname__}' " | ||||||
|  |             rf"at 0x[0-9a-fA-F]+ +\(custom_name\)>" | ||||||
|  |         ) | ||||||
|  |         self.assertRegex(repr(ref2), regex) | ||||||
| 
 | 
 | ||||||
|     def test_repr_failure_gh99184(self): |     def test_repr_failure_gh99184(self): | ||||||
|         class MyConfig(dict): |         class MyConfig(dict): | ||||||
|  | @ -229,10 +234,12 @@ def check(proxy): | ||||||
|     def test_proxy_repr(self): |     def test_proxy_repr(self): | ||||||
|         obj = C() |         obj = C() | ||||||
|         ref = weakref.proxy(obj, self.callback) |         ref = weakref.proxy(obj, self.callback) | ||||||
|         self.assertRegex(repr(ref), |         regex = ( | ||||||
|                          rf"<weakproxy at 0x[0-9a-fA-F]+; " |             rf"<weakproxy at 0x[0-9a-fA-F]+; " | ||||||
|                          rf"to '{C.__module__}.{C.__qualname__}' " |             rf"to '{'' if __name__ == '__main__' else C.__module__ + '.'}{C.__qualname__}' " | ||||||
|                          rf"at 0x[0-9a-fA-F]+>") |             rf"at 0x[0-9a-fA-F]+>" | ||||||
|  |         ) | ||||||
|  |         self.assertRegex(repr(ref), regex) | ||||||
| 
 | 
 | ||||||
|         obj = None |         obj = None | ||||||
|         gc_collect() |         gc_collect() | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Miss Islington (bot)
						Miss Islington (bot)