Skip to content

Commit bc8e0e8

Browse files
authored
Merge pull request #4060 from OpSecId/fix-post-merge-sonarqube-error
fix(utils): satisfy Sonar S7497 in timeout shim
2 parents a99e49f + cc8ad05 commit bc8e0e8

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

acapy_agent/utils/repeat.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Utils for repeating tasks."""
22

33
import asyncio
4-
from contextlib import asynccontextmanager
54
from typing import Optional
65

76

@@ -93,20 +92,5 @@ def __repr__(self) -> str:
9392

9493

9594
def _timeout_cm(duration: float):
96-
"""Compatibility wrapper for asyncio.timeout (Python <3.11)."""
97-
if hasattr(asyncio, "timeout"):
98-
return asyncio.timeout(duration)
99-
100-
@asynccontextmanager
101-
async def _timeout_gen():
102-
loop = asyncio.get_running_loop()
103-
task = asyncio.current_task()
104-
handle = loop.call_later(duration, task.cancel)
105-
try:
106-
yield
107-
except asyncio.CancelledError as exc:
108-
raise asyncio.TimeoutError from exc
109-
finally:
110-
handle.cancel()
111-
112-
return _timeout_gen()
95+
"""Async context manager that times out after duration (asyncio.timeout)."""
96+
return asyncio.timeout(duration)

0 commit comments

Comments
 (0)