Skip to content

Commit 97b3681

Browse files
Micro optimization: move Python version check from function exection time to import time (#236)
* Micro-optimization: move Python version check from function exection time to import time * Micro-optimization: move Python version check from function exection time to import time * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 655b5d0 commit 97b3681

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

async_timeout/__init__.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,27 @@ def _on_timeout(self, task: "asyncio.Task[None]") -> None:
214214
self._state = _State.TIMEOUT
215215

216216

217-
def _current_task(loop: asyncio.AbstractEventLoop) -> "Optional[asyncio.Task[Any]]":
218-
if sys.version_info >= (3, 7):
217+
if sys.version_info >= (3, 7):
218+
219+
def _current_task(loop: asyncio.AbstractEventLoop) -> "Optional[asyncio.Task[Any]]":
219220
return asyncio.current_task(loop=loop)
220-
else:
221+
222+
223+
else:
224+
225+
def _current_task(loop: asyncio.AbstractEventLoop) -> "Optional[asyncio.Task[Any]]":
221226
return asyncio.Task.current_task(loop=loop)
222227

223228

224-
def _get_running_loop() -> asyncio.AbstractEventLoop:
225-
if sys.version_info >= (3, 7):
229+
if sys.version_info >= (3, 7):
230+
231+
def _get_running_loop() -> asyncio.AbstractEventLoop:
226232
return asyncio.get_running_loop()
227-
else:
233+
234+
235+
else:
236+
237+
def _get_running_loop() -> asyncio.AbstractEventLoop:
228238
loop = asyncio.get_event_loop()
229239
if not loop.is_running():
230240
raise RuntimeError("no running event loop")

0 commit comments

Comments
 (0)