From 5cf930d5cb748a81de9bd951c86301f07516bced Mon Sep 17 00:00:00 2001 From: Florian Strzelecki Date: Fri, 18 Oct 2024 18:01:29 +0200 Subject: [PATCH] tools: minor improvements of type annotations --- sopel/tools/calculation.py | 8 ++++---- sopel/tools/memories.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sopel/tools/calculation.py b/sopel/tools/calculation.py index 96646048d..b32068705 100644 --- a/sopel/tools/calculation.py +++ b/sopel/tools/calculation.py @@ -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 `. :param node: the AST node to evaluate @@ -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 @@ -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 @@ -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 diff --git a/sopel/tools/memories.py b/sopel/tools/memories.py index 390df2455..c23f53e6a 100644 --- a/sopel/tools/memories.py +++ b/sopel/tools/memories.py @@ -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: