Skip to content

Commit

Permalink
tools: minor improvements of type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Exirel committed Oct 18, 2024
1 parent 9dcca35 commit 5cf930d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions sopel/tools/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __call__(
ast_expression = ast.parse(expression_str, mode='eval')
return self._eval_node(ast_expression.body, time.time() + timeout)

def _eval_node(self, node: ast.AST, timeout: float) -> int | float:
def _eval_node(self, node: ast.AST, timeout: float) -> float:
"""Recursively evaluate the given :class:`ast.Node <ast.AST>`.
:param node: the AST node to evaluate
Expand Down Expand Up @@ -120,7 +120,7 @@ def _eval_node(self, node: ast.AST, timeout: float) -> int | float:
)


def guarded_mul(left: int | float, right: int | float) -> int | float:
def guarded_mul(left: float, right: float) -> float:
"""Multiply two values, guarding against overly large inputs.
:param left: the left operand
Expand Down Expand Up @@ -209,7 +209,7 @@ def pow_complexity(num: int, exp: int) -> float:
return exp ** 1.590 * num.bit_length() ** 1.73 / 36864057619.3


def guarded_pow(num: int | float, exp: int | float) -> int | float:
def guarded_pow(num: float, exp: float) -> float:
"""Raise a number to a power, guarding against overly large inputs.
:param num: base
Expand Down Expand Up @@ -263,7 +263,7 @@ def __call__(
self,
expression_str: str,
timeout: float = 5.0,
) -> int | float:
) -> float:
result = ExpressionEvaluator.__call__(self, expression_str, timeout)

# This wrapper is here so additional sanity checks could be done
Expand Down
2 changes: 1 addition & 1 deletion sopel/tools/memories.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def __getitem__(self, key: str | None) -> Any:
def __contains__(self, key: Any) -> Any:
return super().__contains__(self._make_key(key))

def __setitem__(self, key: str | None, value: Any) -> Any:
def __setitem__(self, key: str | None, value: Any) -> None:
super().__setitem__(self._make_key(key), value)

def setdefault(self, key: str, default: Any = None) -> Any:
Expand Down

0 comments on commit 5cf930d

Please sign in to comment.