在 Python 3.6 中,语言中引入了新的变量注释。
但是,当类型不存在时,可能会发生两种不同的情况:
>>> 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
为什么不存在的类型处理行为不同?它不会导致人们忽略函数中未定义的类型吗?
笔记
尝试使用 Python 3.6 RC1 和 RC2 - 相同的行为。
PyCharmsomething
在函数内部和外部都突出显示为“未解析的引用”。