python - 用于 python 类型提示检查的控制台工具

标签 python type-hinting

我有一个带有类型提示的项目 (Python 3.5.2)。我想运行静态检查器来验证类型提示中指定的约束是否得到遵守。有哪些工具可用于此?我一直无法在 corresponding PEP 中找到引用资料

最佳答案

Mypy可能是你要找的。它是一个基于控制台的工具,可以使用 PEP 484 类型注释对 Python 代码进行类型检查。 PEP 484 中未提及它的原因是因为没有内在原因表明 mypy 是唯一可能的类型检查器——例如,Pycharm 也基于 PEP 484 注释实现了类似的东西。

Mypy 仍处于积极的开发/测试模式下,因此您可能会偶尔遇到错误,但它相对稳定。

关于python - 用于 python 类型提示检查的控制台工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38747565/

相关文章:

python - 无法覆盖 __call__ 的实现

python - 在Windows cmd中以颜色显示用户输入的文本

python - x长度为2个字符的排列

python - pylint 为可调用的对象属性给出不可调用的错误

python - PEP 484 : exclusive type for type hint

python - 在numpy中将2D数组广播到4D数组

php - 多个不相关接口(interface)的类型提示

python - 是否可以通过 doctest 测试使用 get_type_hints 的函数?

python - Into 和 From 接口(interface) : struggling with typing. 类型的协方差

python - Scikit-学习 TransformerMixin : 'numpy.ndarray' object has no attribute 'fit'