我想获取对象属性的类型提示。我只能获得该类的提示,而不能获得该类的实例。
我尝试foo_instance.__class__
从这里使用,但只显示类变量。
那么在示例中如何获得 的类型提示bar
?
class foo:
var: int = 42
def __init__(self):
self.bar: int = 2
print(get_type_hints(foo)) # returns {'var': <class 'int'>}
Run Code Online (Sandbox Code Playgroud)