[英]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.