我在 Windows 10 上全新安装了 Python 3.7-32。
我想尝试 Protocols python 方法,接下来我会做:
文件 test_protocols.py 只有一行:
from typing import Protocol
然后:
>python test_protocols.py
我有下一条错误消息需要解释:
Traceback (most recent call last):
File "test_protocols.py", line 1, in <module>
from typing import Protocol
ImportError: cannot import name 'Protocol' from 'typing' (C:\Programing\Python\Python37-32\lib\typing.py)
我做错了什么?
也许我读错了 PEP-0544,但从我的角度来看,我做的和记录的一样。
原文由 mad 发布,翻译遵循 CC BY-SA 4.0 许可协议
截至 2019 年 1 月 20 日, PEP 544 的状态为
Draft
。据我了解,它还没有在 CPython 中实现。UPD :它应该从 Python 3.8 开始工作,尝试更新。