mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	Robustify getfile() against classes that lie about their __module__s
(such as the exceptions in _weakref and _locale!)
This commit is contained in:
		
							parent
							
								
									da79389f10
								
							
						
					
					
						commit
						c99e0f1862
					
				
					 1 changed files with 1 additions and 1 deletions
				
			
		| 
						 | 
					@ -173,7 +173,7 @@ def getfile(object):
 | 
				
			||||||
            return object.__file__
 | 
					            return object.__file__
 | 
				
			||||||
        raise TypeError, 'arg is a built-in module'
 | 
					        raise TypeError, 'arg is a built-in module'
 | 
				
			||||||
    if isclass(object):
 | 
					    if isclass(object):
 | 
				
			||||||
        object = sys.modules[object.__module__]
 | 
					        object = sys.modules.get(object.__module__)
 | 
				
			||||||
        if hasattr(object, '__file__'):
 | 
					        if hasattr(object, '__file__'):
 | 
				
			||||||
            return object.__file__
 | 
					            return object.__file__
 | 
				
			||||||
        raise TypeError, 'arg is a built-in class'
 | 
					        raise TypeError, 'arg is a built-in class'
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue