在Python3.6中,该语言引入了新的Variable Annotations.
但是,当一种类型不存在时,可能会发生两种不同的情况:
>>> def test():
... a: something = 0
...
>>> test()
>>>
>>> a: something = 0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'something' is not defined
为什么不存在的类型处理行为不同?这难道不会导致人们忽略函数中未定义的类型吗?
Notes
在Python3.6 RC1和RC2上都try 过——行为相同.
PyCharm在函数内部和外部都突出显示something
为"未解析引用".