如何解决当比较多个类型的并集时,确保mypy可以得到比较值总是相同类型的提示
我得到了mypy引发的以下回溯:
dust/core/validator/_validators.py:504: error: Unsupported operand types for < ("str" and "ValidateProperty")
dust/core/validator/_validators.py:504: error: Unsupported operand types for < ("float" and "ValidateProperty")
dust/core/validator/_validators.py:504: error: Unsupported operand types for < ("float" and "str")
dust/core/validator/_validators.py:504: error: Unsupported operand types for < ("str" and "float")
用于类似下面的代码。
class Value(ValidateProperty):
def __init__(min_value: VALUE_RANGE=None,max_value: VALUE_RANGE=None):
if min_value is not None and max_value is not None:
if max_value < min_value:
raise ValueError(f"max_value can not be less than min_value")
VALUE_RANGE
在哪里
VALUE_RANGE = typing.Union[FLOAT,STRING,None]
这样:
FLOAT = typing.Union[float,"ValidateProperty",None]
STRING = typing.Union[str,None]
和ValidateProperty
是具有__get__
和__set__
方法的ABC类。
如何确保mypy获得的共同值始终是相同类型的?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。