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.
Of these goals, static analysis is the most important. This includes
support for off-line type checkers such as mypy, as well as providing
a standard notation that can be used by IDEs for code completion and
refactoring.
Non-goals
While the proposed typing module will contain some building
blocks for runtime type checking in particular the get_type_hints()
function third party packages would have to be developed to
implement specific runtime type checking functionality, for example
using decorators or metaclasses. Using type hints for performance
optimizations is left as an exercise for the reader.
答案很简单,那就是没有简单的方法。^{cd1>}模块按设计,不会为运行时检查提供太多帮助。PEP 484说
相关问题 更多 >
编程相关推荐