Skip to content

Commit 41da016

Browse files
allen0099claude
andcommitted
fix: resolve pre-existing lint/format violations blocking new CI gate
The new lint workflow (introduced in the previous commit) caught findings that predate it and were never enforced by CI: - memcached.py passed a positional bool to pymemcache's delete() - switched to the noreply= keyword it already supports. - cache.py's internal invariant assert and session/manager.py's necessarily-long get_session() (security/renewal branches) are legitimate; ignored per-file in pyproject.toml, matching the existing convention there. - cache.py/routes.py/session/manager.py/state/manager.py had drifted from `ruff format` output; reformatted mechanically. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 1a0797f commit 41da016

6 files changed

Lines changed: 21 additions & 9 deletions

File tree

‎fastapi_cachex/backends/memcached.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ async def clear_path(self, path: str, include_params: bool = False) -> int:
177177
# Try to delete the prefixed key (exact match only)
178178
prefixed_key = self._make_key(path)
179179
try:
180-
result = await asyncio.to_thread(self.client.delete, prefixed_key, False)
180+
result = await asyncio.to_thread(
181+
self.client.delete, prefixed_key, noreply=False
182+
)
181183
except Exception: # noqa: BLE001
182184
return 0
183185
else:

‎fastapi_cachex/cache.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,7 @@ async def wrapper(*args: Any, **kwargs: Any) -> Response:
320320
# StreamingResponse/FileResponse — cannot compute ETag; serve as-is
321321
current_response.headers["Cache-Control"] = cache_control
322322
return current_response
323-
current_etag = (
324-
f'W/"{hashlib.md5(current_body).hexdigest()}"' # noqa: S324
325-
)
323+
current_etag = f'W/"{hashlib.md5(current_body).hexdigest()}"' # noqa: S324
326324

327325
if client_etag == current_etag:
328326
# For no-cache, compare fresh data with client's ETag
@@ -381,7 +379,9 @@ async def wrapper(*args: Any, **kwargs: Any) -> Response:
381379

382380
# Update cache if needed
383381
if not cached_data or cached_data.fingerprint != current_etag:
384-
assert current_body is not None # guaranteed by early-return guards above
382+
assert (
383+
current_body is not None
384+
) # guaranteed by early-return guards above
385385
# Store in cache if data changed
386386
await cache_backend.set(
387387
cache_key,

‎fastapi_cachex/routes.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ async def _get_cached_hits_handler(backend: BaseCacheBackend) -> CacheHitsRespon
129129
if method: # Valid cache key
130130
# Check if cache entry is expired
131131
is_expired = expiry is not None and expiry <= now
132-
ttl_remaining = max(0.0, round(expiry - now, 2)) if expiry is not None else None
132+
ttl_remaining = (
133+
max(0.0, round(expiry - now, 2)) if expiry is not None else None
134+
)
133135

134136
cached_hits.append(
135137
CacheHitRecord(
@@ -188,7 +190,9 @@ async def _get_cached_records_handler(
188190
content = entry.content
189191
content_size = len(content) if isinstance(content, (bytes, str)) else 0
190192

191-
ttl_remaining = max(0.0, round(expiry - now, 2)) if expiry is not None else None
193+
ttl_remaining = (
194+
max(0.0, round(expiry - now, 2)) if expiry is not None else None
195+
)
192196

193197
content_preview = (
194198
content[:100].decode("utf-8", errors="ignore")

‎fastapi_cachex/session/manager.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,9 @@ async def _save_session(self, session: Session) -> None:
449449
ttl = max(ttl, 1) # Ensure at least 1 second
450450

451451
fingerprint = self.security.hash_data(value.decode("utf-8"))
452-
await self.backend.set(key, CacheEntry(fingerprint=fingerprint, content=value), ttl=ttl)
452+
await self.backend.set(
453+
key, CacheEntry(fingerprint=fingerprint, content=value), ttl=ttl
454+
)
453455
logger.debug("Session saved; id=%s ttl=%s", session.session_id, ttl)
454456

455457
async def _load_session(self, session_id: str) -> Session | None:

‎fastapi_cachex/state/manager.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ async def create_state(
125125
fingerprint = hashlib.sha256(json_content.encode()).hexdigest()
126126

127127
cache_key = f"{self.key_prefix}{state}"
128-
entry = CacheEntry(fingerprint=fingerprint, content=json_content.encode("utf-8"))
128+
entry = CacheEntry(
129+
fingerprint=fingerprint, content=json_content.encode("utf-8")
130+
)
129131
await self.backend.set(cache_key, entry, ttl=effective_ttl)
130132

131133
logger.debug("OAuth state created; state=%s ttl=%s", state, effective_ttl)

‎pyproject.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,12 @@ keep-runtime-typing = true
111111
]
112112
"fastapi_cachex/cache.py" = [
113113
"PLR0913", "PLR0915", "PLR0911", "PLR0912", # Many arguments/statements/returns/branches needed for flexible caching logic
114+
"S101", # Internal invariant guard, not a validation shortcut
114115
]
115116
"fastapi_cachex/backends/memcached.py" = ["PLC0415"] # Optional dependency
116117
"fastapi_cachex/backends/redis.py" = ["PLR0913", "PLC0415"] # Optional dependency, Redis config
117118
"fastapi_cachex/proxy.py" = ["PLW0603"] # Global backend management by design
119+
"fastapi_cachex/session/manager.py" = ["PLR0915"] # Session/security validation branches needed
118120

119121
[tool.ruff.format]
120122
docstring-code-format = true

0 commit comments

Comments
 (0)