Commit c11b6860 authored by Moul's avatar Moul Committed by Vincent Texier

[fix] Fix money helper mypy alert by typing Condition properties

Use isinstance(obj, type) with mypy for if condition to be handled (type() == is deprecated in python)
parent e3d3a990
Pipeline #6218 failed with stages
from typing import Optional, TypeVar, Type, Any
from typing import Optional, TypeVar, Type, Any, Union
from pypeg2 import re, attr, Keyword, Enum, contiguous, maybe_some, whitespace, K
......@@ -321,9 +321,9 @@ class Condition:
:param value: Content of the condition as string
"""
self.value = value
self.left = ""
self.right = ""
self.op = ""
self.left = "" # type: Union[str, Condition]
self.right = "" # type: Union[str, Condition]
self.op = "" # type: Union[str, Condition]
def __eq__(self, other: Any) -> bool:
"""
......
from typing import Union, Type, Any
from duniterpy.grammars.output import SIG, CSV, CLTV, XHX, ConditionType
from typing import Union, Any
from duniterpy.grammars.output import SIG, CSV, CLTV, XHX, Condition
def output_available(
condition: Type[ConditionType], comparison: Any, value: Union[str, int]
condition: Condition, comparison: Any, value: Union[str, int]
) -> bool:
"""
Check if output source is available
......@@ -14,13 +14,13 @@ def output_available(
operator.gt(a, b) is equivalent to a > b
operator.ge(a, b) is equivalent to a >= b
"""
if type(condition.left) == SIG:
if isinstance(condition.left, SIG):
return comparison(condition.left.pubkey, value)
if type(condition.left) == CSV:
if isinstance(condition.left, CSV):
return comparison(int(condition.left.time), value)
if type(condition.left) == CLTV:
if isinstance(condition.left, CLTV):
return comparison(int(condition.left.timestamp), value)
if type(condition.left) == XHX:
if isinstance(condition.left, XHX):
return comparison(condition.left.sha_hash, value)
else:
return False
return False
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment