我想在检查相同类的类方法中进行静态类型提示。
示例:
class Human:
def __init__(self, name, gender):
self.name = name
self.gender = gender
def is_same_gender(self, other_person: Human):
return self.gender == other_person.gender
但是,我总是遇到not defined
错误
Traceback (most recent call last):
File ".../scratch.py", line 9, in <module>
class Human:
File ".../scratch.py", line 14, in Human
def is_same_gender(self, other_person: Human):
NameError: name 'Human' is not defined
在Python中这种类型提示是否可能?我正在Windows 10中使用Anaconda 3.6.5。