mirror of
				https://github.com/python/cpython.git
				synced 2025-10-28 12:15:13 +00:00 
			
		
		
		
	 74613a46fc
			
		
	
	
		74613a46fc
		
			
		
	
	
	
	
		
			
			Add inspect.get_annotations, which safely computes the annotations defined on an object. It works around the quirks of accessing the annotations from various types of objects, and makes very few assumptions about the object passed in. inspect.get_annotations can also correctly un-stringize stringized annotations. inspect.signature, inspect.from_callable, and inspect.from_function now call inspect.get_annotations to retrieve annotations. This means inspect.signature and inspect.from_callable can now un-stringize stringized annotations, too.
		
			
				
	
	
		
			28 lines
		
	
	
	
		
			509 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
	
		
			509 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| a:int=3
 | |
| b:str="foo"
 | |
| 
 | |
| class MyClass:
 | |
|     a:int=4
 | |
|     b:str="bar"
 | |
|     def __init__(self, a, b):
 | |
|         self.a = a
 | |
|         self.b = b
 | |
|     def __eq__(self, other):
 | |
|         return isinstance(other, MyClass) and self.a == other.a and self.b == other.b
 | |
| 
 | |
| def function(a:int, b:str) -> MyClass:
 | |
|     return MyClass(a, b)
 | |
| 
 | |
| 
 | |
| def function2(a:int, b:"str", c:MyClass) -> MyClass:
 | |
|     pass
 | |
| 
 | |
| 
 | |
| def function3(a:"int", b:"str", c:"MyClass"):
 | |
|     pass
 | |
| 
 | |
| 
 | |
| class UnannotatedClass:
 | |
|     pass
 | |
| 
 | |
| def unannotated_function(a, b, c): pass
 |