Skip to content

Commit 70e2cef

Browse files
committed
Fix mypy error: Incompatible types in assignment
``` discord/backoff.py:73: error: Incompatible types in assignment (expression has type "function", variable has type "Callable[..., float]") ``` - Refer to <python/mypy#10740 (comment)>
1 parent e980fdd commit 70e2cef

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎discord/backoff.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ def __init__(self, base: int = 1, *, integral: bool = False):
7070
rand = random.Random()
7171
rand.seed()
7272

73-
self._randfunc: Callable[..., Union[int, float]] = rand.randrange if integral else rand.uniform # type: ignore
73+
# Note: This redundant type check is needed to avoid mypy bug (mypy#10740).
74+
# Refer to <https://github.com/python/mypy/issues/10740#issuecomment-878622464>
75+
T2 = Callable[..., Union[int, float]]
76+
f1: T2 = rand.randrange
77+
f2: T2 = rand.uniform
78+
self._randfunc: T2 = f1 if integral else f2
7479

7580
@overload
7681
def delay(self: ExponentialBackoff[Literal[False]]) -> float:

0 commit comments

Comments
 (0)