Skip to content

Commit d9fcbbd

Browse files
CopilotArzelaAscoIi
andcommitted
Address code review feedback: improve error handling and documentation
Co-authored-by: ArzelaAscoIi <37148029+ArzelaAscoIi@users.noreply.github.com>
1 parent e047501 commit d9fcbbd

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

deepset_cloud_sdk/_s3/upload.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
# and try_acquire accepts a blocking parameter
3232
try:
3333
_LIMITER_SUPPORTS_BLOCKING = "blocking" in inspect.signature(Limiter.try_acquire).parameters
34-
except (AttributeError, ValueError):
34+
except (AttributeError, TypeError):
3535
# 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
3638
_LIMITER_SUPPORTS_BLOCKING = False
3739

3840

@@ -137,19 +139,23 @@ async def __aexit__(
137139
except AttributeError:
138140
pass
139141

140-
def _rate_limit_acquire(self, name: str = "") -> None:
142+
def _rate_limit_acquire(self) -> None:
141143
"""
142144
Acquire a rate limit token.
143145
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.
146148
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).
148152
"""
149153
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)
151156
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("")
153159

154160
async def _upload_file_with_retries(
155161
self,

0 commit comments

Comments
 (0)