mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	 422c4fc855
			
		
	
	
		422c4fc855
		
			
		
	
	
	
	
		
			
			In order to patch flask.g e.g. as in #84982, that proxies getattr must not be invoked. For that, mock must not try to read from the original object. In some cases that is unavoidable, e.g. when doing autospec. However, patch("flask.g", new_callable=MagicMock) should be entirely safe.
		
			
				
	
	
		
			27 lines
		
	
	
	
		
			466 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			27 lines
		
	
	
	
		
			466 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| target = {'foo': 'FOO'}
 | |
| 
 | |
| 
 | |
| def is_instance(obj, klass):
 | |
|     """Version of is_instance that doesn't access __class__"""
 | |
|     return issubclass(type(obj), klass)
 | |
| 
 | |
| 
 | |
| class SomeClass(object):
 | |
|     class_attribute = None
 | |
| 
 | |
|     def wibble(self): pass
 | |
| 
 | |
| 
 | |
| class X(object):
 | |
|     pass
 | |
| 
 | |
| # A standin for weurkzeug.local.LocalProxy - issue 119600
 | |
| def _inaccessible(*args, **kwargs):
 | |
|     raise AttributeError
 | |
| 
 | |
| 
 | |
| class OpaqueProxy:
 | |
|     __getattribute__ = _inaccessible
 | |
| 
 | |
| 
 | |
| g = OpaqueProxy()
 |