对 Python 的 annotations 一直耿耿于怀,有些时候指定类型还是很便利的。
PEP 484 -- Type Hints 中有一段:
This PEP aims to provide a standard syntax for type annotations, opening up
Python code to easier static analysis and refactoring, potential runtime type
checking, and (perhaps, in some contexts) code generation utilizing type
information.
其中提到了 potential runtime type checking, 问题就在这,如何才能实现运行时检查类型。
(碎碎念:说来也怪,高中那年看到 python 不需要指定类型,一度震惊无比,
这么写了几年 python 后,觉得有的地方还是指定类型更合适)