在带有mypy
的项目上使用
typeguard时,我遇到了错误:
src/pythontemplate/adder.py:6: error: Untyped decorator makes function "add_two" untyped [misc]
在以下示例代码中:
"""Example python file with a function."""
from typeguard import typechecked
@typechecked
def add_two(*, x: int) -> int:
"""Adds a value to an incoming number."""
return x + 2
看完this答案后,似乎可以通过为
@typechecked
函数/装饰器手动添加类型来解决此错误消息。
@typeguard
装饰器的类型。python
文件中,因此在每个文件中添加该装饰器的类型,或者甚至导入到具有该类型的单独文件,将是相当多的重复代码和/或样板代码.如何确保
@typeguard
装饰器被键入?