|
31 | 31 | # and try_acquire accepts a blocking parameter |
32 | 32 | try: |
33 | 33 | _LIMITER_SUPPORTS_BLOCKING = "blocking" in inspect.signature(Limiter.try_acquire).parameters |
34 | | -except (AttributeError, ValueError): |
| 34 | +except (AttributeError, TypeError): |
35 | 35 | # Fallback to False if we can't inspect the signature |
| 36 | + # AttributeError: if Limiter.try_acquire doesn't exist |
| 37 | + # TypeError: if Limiter.try_acquire is not callable |
36 | 38 | _LIMITER_SUPPORTS_BLOCKING = False |
37 | 39 |
|
38 | 40 |
|
@@ -137,19 +139,23 @@ async def __aexit__( |
137 | 139 | except AttributeError: |
138 | 140 | pass |
139 | 141 |
|
140 | | - def _rate_limit_acquire(self, name: str = "") -> None: |
| 142 | + def _rate_limit_acquire(self) -> None: |
141 | 143 | """ |
142 | 144 | Acquire a rate limit token. |
143 | 145 | |
144 | | - Uses blocking=False for pyrate-limiter 4.0.0+ to maintain non-blocking behavior, |
145 | | - or the default behavior for 3.x which was non-blocking with raise_when_fail=False. |
| 146 | + Uses blocking=False for pyrate-limiter 4.0.0+ to maintain non-blocking behavior |
| 147 | + consistent with the old raise_when_fail=False behavior in 3.x. |
146 | 148 | |
147 | | - :param name: The name of the item to acquire (default: "") |
| 149 | + In pyrate-limiter 3.x, using raise_when_fail=False made try_acquire non-blocking. |
| 150 | + In pyrate-limiter 4.0.0+, we need to explicitly pass blocking=False to get the same |
| 151 | + non-blocking behavior (returns immediately without waiting for rate limit). |
148 | 152 | """ |
149 | 153 | if _LIMITER_SUPPORTS_BLOCKING: |
150 | | - self.limiter.try_acquire(name, blocking=False) |
| 154 | + # pyrate-limiter 4.0.0+: use blocking=False for non-blocking behavior |
| 155 | + self.limiter.try_acquire("", blocking=False) |
151 | 156 | else: |
152 | | - self.limiter.try_acquire(name) |
| 157 | + # pyrate-limiter 3.x: non-blocking when initialized with raise_when_fail=False |
| 158 | + self.limiter.try_acquire("") |
153 | 159 |
|
154 | 160 | async def _upload_file_with_retries( |
155 | 161 | self, |
|
0 commit comments