Skip to content

Commit 4bb3a27

Browse files
committed
paillat comment
1 parent 8311d59 commit 4bb3a27

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

discord/ext/tasks/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,22 @@ def __init__(
139139
raise TypeError(
140140
f"Expected coroutine function, not {type(self.coro).__name__!r}."
141141
)
142-
if not isinstance(overlap, (bool, int)):
143-
raise TypeError("overlap must be a bool or a positive integer.")
144-
145142
if isinstance(overlap, bool):
146-
if overlap is True:
143+
if overlap:
147144
self._run_with_semaphore = self._run_direct
148-
else:
145+
elif isinstance(overlap, int):
149146
if overlap <= 1:
150147
raise ValueError("overlap as an integer must be greater than 1.")
151148
self._semaphore = asyncio.Semaphore(overlap)
152-
self._run_with_semaphore = self._make_semaphore_runner()
149+
self._run_with_semaphore = self._semaphore_runner_factory()
150+
else:
151+
raise TypeError("overlap must be a bool or a positive integer.")
153152

154153
async def _run_direct(self, *args: Any, **kwargs: Any) -> None:
155154
"""Run the coroutine directly."""
156155
await self.coro(*args, **kwargs)
157156

158-
def _make_semaphore_runner(self) -> Callable[..., Awaitable[None]]:
157+
def _semaphore_runner_factory(self) -> Callable[..., Awaitable[None]]:
159158
"""Return a function that runs the coroutine with a semaphore."""
160159

161160
async def runner(*args: Any, **kwargs: Any) -> None:

0 commit comments

Comments
 (0)