赋值中的类型不兼容(表达式的类型为“List[<nothing>]”,变量的类型为(…)

2024-04-29 19:36:39 发布

您现在位置:Python中文网/ 问答频道 /正文

考虑以下独立示例:

from typing import List, Union

T_BENCODED_LIST = Union[List[bytes], List[List[bytes]]]
ret: T_BENCODED_LIST = []

当我用mypy测试它时,我得到以下错误:

example.py:4: error: Incompatible types in assignment (expression has type "List[<nothing>]", variable has type "Union[List[bytes], List[List[bytes]]]")

这里的问题是什么?如何正确地注释这个示例?你知道吗


Tags: fromimport示例typingbytesexampletype错误