Skip to Content
流畅的Python(第2版)
book

流畅的Python(第2版)

by Luciano Ramalho
April 2023
Intermediate to advanced
769 pages
25h 16m
Chinese
Posts & Telecom Press
Content preview from 流畅的Python(第2版)
222
8
top_test.py:41: note:
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.
Start your free trial

You might also like

Python高级编程(第2版)

Python高级编程(第2版)

Posts & Telecom Press, Michał Jaworski, Tarek Ziadé
Kafka权威指南(第2版)

Kafka权威指南(第2版)

Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty
Python贝叶斯分析(第2版)

Python贝叶斯分析(第2版)

Posts & Telecom Press, Osvaldo Martin

Publisher Resources

ISBN: 9787115612366