From f3e38e871dc59d268d345ecac68517ddf56cebd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Furkan=20=C4=B0=C5=9Fleyen?= <54645034+OmerFI@users.noreply.github.com> Date: Wed, 6 Sep 2023 01:45:39 +0300 Subject: [PATCH] Fix mypy errors (partly) --- src/pyprobs/probability.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/pyprobs/probability.py b/src/pyprobs/probability.py index ba4a615..9748202 100644 --- a/src/pyprobs/probability.py +++ b/src/pyprobs/probability.py @@ -50,7 +50,7 @@ class Probability(object): def __init__(self) -> None: self._mutable = True - self._constant = "unset" + self._constant: Union[int, float, str] = "unset" self._args = False self.history = {} @@ -100,7 +100,7 @@ def _int_probability(arg: int) -> bool: @classmethod def _float_probability(cls, arg: float) -> bool: if arg % 1 == 0: - if cls._int_probability(arg): + if cls._int_probability(int(arg)): return True return False elif arg > 1 or arg < 0: @@ -117,7 +117,9 @@ def _float_probability(cls, arg: float) -> bool: @classmethod def _str_probability(cls, arg: str) -> bool: if "%" in arg and "/" in arg: - return NotImplemented # can change later + raise exceptions.ProbabilityTypeError( + "Given str value must contain '%' or '/'." + ) if "%" in arg: arg = ( @@ -127,13 +129,16 @@ def _str_probability(cls, arg: str) -> bool: ) return cls._float_probability(int(arg.strip()) / 100) elif "/" in arg: - arg = arg.split("/") - first_part = int(arg[0]) - second_part = int(arg[1]) + splitted_arg = arg.split("/") + first_part = int(splitted_arg[0]) + second_part = int(splitted_arg[1]) value = _randint(1, second_part) if first_part >= value: return True return False + raise exceptions.ProbabilityTypeError( + "Given str value must contain '%' or '/'." + ) @staticmethod def _adjust_str(arg: str) -> str: @@ -147,6 +152,7 @@ def _adjust_str(arg: str) -> str: for idx, t in enumerate(arg_as_list): arg_as_list[idx] = t.strip() return "%".join(arg_as_list) + return arg @classmethod def prob(cls, *args, num: int = 1) -> Union[bool, Iterable[bool]]: