summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/backoff/python314-compat.patch
blob: 2393be2868fd5f478788118c930caa8dd0c64156 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
diff --git a/tests/test_backoff_async.py b/tests/test_backoff_async.py
index 226ef08..9298b5f 100644
--- a/tests/test_backoff_async.py
+++ b/tests/test_backoff_async.py
@@ -692,7 +692,7 @@ def test_on_predicate_on_regular_function_without_event_loop(monkeypatch):
     monkeypatch.setattr('time.sleep', lambda x: None)
 
     # Set default event loop to None.
-    loop = asyncio.get_event_loop()
+    loop = asyncio.new_event_loop()
     asyncio.set_event_loop(None)
 
     try:
@@ -716,7 +716,7 @@ def test_on_exception_on_regular_function_without_event_loop(monkeypatch):
     monkeypatch.setattr('time.sleep', lambda x: None)
 
     # Set default event loop to None.
-    loop = asyncio.get_event_loop()
+    loop = asyncio.new_event_loop()
     asyncio.set_event_loop(None)
 
     try:

From 401709d040df302cdf3cd4a7e0d7703c90ff2d9e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Edgar=20Ram=C3=ADrez-Mondrag=C3=B3n?= <edgarrm358@gmail.com>
Date: Thu, 17 Oct 2024 16:28:46 -0600
Subject: [PATCH] Use `inspect.iscoroutinefunction` instead of
 `asyncio.iscoroutinefunction`

---
 backoff/_async.py     | 13 +++++++------
 backoff/_decorator.py |  6 +++---
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/backoff/_async.py b/backoff/_async.py
index 82fd477..c24587c 100644
--- a/backoff/_async.py
+++ b/backoff/_async.py
@@ -1,5 +1,6 @@
 # coding:utf-8
 import datetime
+import inspect
 import functools
 import asyncio
 from datetime import timedelta
@@ -8,7 +9,7 @@
 
 
 def _ensure_coroutine(coro_or_func):
-    if asyncio.iscoroutinefunction(coro_or_func):
+    if inspect.iscoroutinefunction(coro_or_func):
         return coro_or_func
     else:
         @functools.wraps(coro_or_func)
@@ -47,10 +48,10 @@ def retry_predicate(target, wait_gen, predicate,
     on_giveup = _ensure_coroutines(on_giveup)
 
     # Easy to implement, please report if you need this.
-    assert not asyncio.iscoroutinefunction(max_tries)
-    assert not asyncio.iscoroutinefunction(jitter)
+    assert not inspect.iscoroutinefunction(max_tries)
+    assert not inspect.iscoroutinefunction(jitter)
 
-    assert asyncio.iscoroutinefunction(target)
+    assert inspect.iscoroutinefunction(target)
 
     @functools.wraps(target)
     async def retry(*args, **kwargs):
@@ -124,8 +125,8 @@ def retry_exception(target, wait_gen, exception,
     giveup = _ensure_coroutine(giveup)
 
     # Easy to implement, please report if you need this.
-    assert not asyncio.iscoroutinefunction(max_tries)
-    assert not asyncio.iscoroutinefunction(jitter)
+    assert not inspect.iscoroutinefunction(max_tries)
+    assert not inspect.iscoroutinefunction(jitter)
 
     @functools.wraps(target)
     async def retry(*args, **kwargs):
diff --git a/backoff/_decorator.py b/backoff/_decorator.py
index 77ed8c2..ca5d0ff 100644
--- a/backoff/_decorator.py
+++ b/backoff/_decorator.py
@@ -1,5 +1,5 @@
 # coding:utf-8
-import asyncio
+import inspect
 import logging
 import operator
 from typing import Any, Callable, Iterable, Optional, Type, Union
@@ -98,7 +98,7 @@ def decorate(target):
             log_level=giveup_log_level
         )
 
-        if asyncio.iscoroutinefunction(target):
+        if inspect.iscoroutinefunction(target):
             retry = _async.retry_predicate
         else:
             retry = _sync.retry_predicate
@@ -198,7 +198,7 @@ def decorate(target):
             log_level=giveup_log_level,
         )
 
-        if asyncio.iscoroutinefunction(target):
+        if inspect.iscoroutinefunction(target):
             retry = _async.retry_exception
         else:
             retry = _sync.retry_exception