File tree Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -139,23 +139,22 @@ def __init__(
139
139
raise TypeError (
140
140
f"Expected coroutine function, not { type (self .coro ).__name__ !r} ."
141
141
)
142
- if not isinstance (overlap , (bool , int )):
143
- raise TypeError ("overlap must be a bool or a positive integer." )
144
-
145
142
if isinstance (overlap , bool ):
146
- if overlap is True :
143
+ if overlap :
147
144
self ._run_with_semaphore = self ._run_direct
148
- else :
145
+ elif isinstance ( overlap , int ) :
149
146
if overlap <= 1 :
150
147
raise ValueError ("overlap as an integer must be greater than 1." )
151
148
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." )
153
152
154
153
async def _run_direct (self , * args : Any , ** kwargs : Any ) -> None :
155
154
"""Run the coroutine directly."""
156
155
await self .coro (* args , ** kwargs )
157
156
158
- def _make_semaphore_runner (self ) -> Callable [..., Awaitable [None ]]:
157
+ def _semaphore_runner_factory (self ) -> Callable [..., Awaitable [None ]]:
159
158
"""Return a function that runs the coroutine with a semaphore."""
160
159
161
160
async def runner (* args : Any , ** kwargs : Any ) -> None :
You can’t perform that action at this time.
0 commit comments