![](/img/trans.png)
[英]How can you test that a python typing Protocol is a subclass of another Protocol?
[英]can not import Protocol from typing
我在 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,但从我的角度来看,我做的和记录的一样。
截至 2019 年 1 月 20 日, PEP 544的状态为Draft
。 据我了解,它还没有在 CPython 中实现。
UPD :它应该从 Python 3.8 开始工作,请尝试更新。
如果它在输入中不存在,请执行
pip install typing_extensions
from typing_extensions import Protocol
根据操作系统和 Python 版本协议类可能在打字模块或打字扩展中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.