Skip to content

Commit

Permalink
Fix mypy errors (partly)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerFI committed Sep 5, 2023
1 parent 6250494 commit f3e38e8
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/pyprobs/probability.py
Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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:
Expand All @@ -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 = (
Expand All @@ -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:
Expand All @@ -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]]:
Expand Down

0 comments on commit f3e38e8

Please sign in to comment.