Revealed type is "builtins.list[builtins.object*]"
➌
top_test.py:43: error:
Value of type variable "LT" of "top" cannot be "object"
➍
Found 1 error in 1 file (checked 1 source file)
➊
reveal_type(series)
显示
test_top_tuples
中的
series
是
Iterator[tuple[int, str]]
类型,即我显式声明的类型。
➋
reveal_type(result)
确认
top
调用返回的类型正是我想要的:根据为
series
声明的类
型,
result
的类型是
list[tuple[int, str]]
。
➌
reveal_type(series)
显示
test_top_objects_error
中的
series
是
list[object*]
类型。
Mypy
在推
导的类型后面加了一个
*
。在这个测试中,我没有为
series
注解类型,因此
是推导出来的。
➍
我是有意测试类型错误,
Mypy
也确实发现了错误:可迭代对象
series
中元素的类型不
能是
object
(必须是
SupportsLessThan
类型)。
截至
Mypy 0.910
(
2021
年
7
月),
reveal_type
的输出有时不显示我声明的
类型,而是显示相容的类型。鉴于此,我没有使用 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.