我有以下内容:
在 myfile.py 中:
from file1 import REQ
@has_request_variable
def fun(request, REQ(validator=check_int))
/* body */
在文件 1.py
class REQ(object):
def __init__(self, validator=None):
self.validator = validator
def has_request_variables(view_func):
/* body */
# Below I am calling the validator function to check
error = param.validator(var_name, val)
现在我想使用 mypy 注释有趣的函数,我已经按照以下方式完成了它并且它工作但它并不理想,因为在乐趣中我知道消息是 int 类型所以我们应该用类似 int 的东西来注释参数...如何使用 mypy 实现它。
from file1 import REQ
@has_request_variable
def fun(request, message=REQ(validator=check_int))
# type(Any, REQ) -> Any
msg = message # type: int
/* body */