Skip to content

Commit de80832

Browse files
committed
Addressing comments from chopan50, block 16
1 parent e1db9ea commit de80832

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

manim/utils/simple_functions.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111

1212

1313
from functools import lru_cache
14-
from typing import Callable, overload
14+
from typing import Any, Callable, Protocol, TypeVar
1515

1616
import numpy as np
1717
from scipy import special
1818

1919

2020
def binary_search(
21-
function: Callable[[int | float], int | float],
22-
target: int | float,
23-
lower_bound: int | float,
24-
upper_bound: int | float,
25-
tolerance: int | float = 1e-4,
26-
) -> int | float | None:
21+
function: Callable[[float], float],
22+
target: float,
23+
lower_bound: float,
24+
upper_bound: float,
25+
tolerance: float = 1e-4,
26+
) -> float | None:
2727
"""Searches for a value in a range by repeatedly dividing the range in half.
2828
2929
To be more precise, performs numerical binary search to determine the
@@ -92,15 +92,16 @@ def choose(n: int, k: int) -> int:
9292
return value
9393

9494

95-
@overload
96-
def clip(a: float, min_a: float, max_a: float) -> float: ...
95+
class Comparable(Protocol):
96+
def __lt__(self, other: Any) -> bool: ...
9797

98+
def __gt__(self, other: Any) -> bool: ...
9899

99-
@overload
100-
def clip(a: str, min_a: str, max_a: str) -> str: ...
101100

101+
ComparableT = TypeVar("ComparableT", bound=Comparable) # noqa: Y001
102102

103-
def clip(a, min_a, max_a): # type: ignore[no-untyped-def]
103+
104+
def clip(a: ComparableT, min_a: ComparableT, max_a: ComparableT) -> ComparableT:
104105
"""Clips ``a`` to the interval [``min_a``, ``max_a``].
105106
106107
Accepts any comparable objects (i.e. those that support <, >).

0 commit comments

Comments
 (0)