Skip to content

Commit a85e43a

Browse files
fix: resolve all 67 ruff lint errors
Fix import sorting, unused imports, line length violations, nested if/with statements, missing raise-from chains, and try/except/pass patterns across source and test files.
1 parent 09c17a4 commit a85e43a

28 files changed

Lines changed: 202 additions & 95 deletions

s3proxy/app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from prometheus_client import CONTENT_TYPE_LATEST, generate_latest
1717
from structlog.stdlib import BoundLogger
1818

19-
from . import metrics # Ensure Prometheus collectors are registered at import time
2019
from .config import Settings
2120
from .errors import S3Error, get_s3_error_code
2221
from .handlers import S3ProxyHandler

s3proxy/client/verifier.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ def _parse_v4_credential(
6464
return creds, date_stamp, region, service, None
6565

6666
def _compute_v4_signature(
67-
self, canonical_request: str, amz_date: str, date_stamp: str, region: str, service: str, secret_key: str
67+
self,
68+
canonical_request: str,
69+
amz_date: str,
70+
date_stamp: str,
71+
region: str,
72+
service: str,
73+
secret_key: str,
6874
) -> str:
6975
"""Compute V4 signature for a canonical request."""
7076
string_to_sign = self._build_string_to_sign(

s3proxy/concurrency.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import asyncio
6+
import contextlib
67
import ctypes
78
import gc
89
import os
@@ -111,10 +112,8 @@ async def release(self, bytes_reserved: int) -> None:
111112
gc.collect(2)
112113

113114
if _malloc_release:
114-
try:
115+
with contextlib.suppress(OSError):
115116
_malloc_release()
116-
except OSError:
117-
pass
118117

119118
# Yield to allow OS memory reclaim
120119
await asyncio.sleep(0)

s3proxy/handlers/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ def _parse_range(self, header: str, size: int) -> tuple[int, int]:
108108
else:
109109
parts = spec.split("-")
110110
start, end = int(parts[0]), min(int(parts[1]), size - 1)
111-
except (ValueError, IndexError):
112-
raise S3Error.invalid_range("Invalid range header format")
111+
except (ValueError, IndexError) as err:
112+
raise S3Error.invalid_range("Invalid range header format") from err
113113
if start > end or start >= size:
114114
raise S3Error.invalid_range("Range not satisfiable")
115115
return start, end
@@ -122,8 +122,8 @@ def _parse_copy_source_range(
122122
range_str = range_header.replace("bytes=", "")
123123
try:
124124
start, end = map(int, range_str.split("-"))
125-
except (ValueError, TypeError):
126-
raise S3Error.invalid_range("Invalid copy source range format")
125+
except (ValueError, TypeError) as err:
126+
raise S3Error.invalid_range("Invalid copy source range format") from err
127127
if start > end or start >= total_size:
128128
raise S3Error.invalid_range("Range not satisfiable")
129129
return start, min(end, total_size - 1)

s3proxy/handlers/multipart/lifecycle.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ async def handle_complete_multipart_upload(
185185
)
186186

187187
location = f"{self.settings.s3_endpoint}/{bucket}/{key}"
188-
etag = hashlib.md5(str(state.total_plaintext_size).encode(), usedforsecurity=False).hexdigest()
188+
etag = hashlib.md5(
189+
str(state.total_plaintext_size).encode(), usedforsecurity=False
190+
).hexdigest()
189191

190192
return Response(
191193
content=xml_responses.complete_multipart(location, bucket, key, etag),

s3proxy/request_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
from structlog.stdlib import BoundLogger
1414

1515
from . import concurrency, crypto
16+
from .errors import S3Error, raise_for_client_error, raise_for_exception
17+
from .handlers import S3ProxyHandler
1618
from .metrics import (
1719
REQUEST_COUNT,
1820
REQUEST_DURATION,
1921
REQUESTS_IN_FLIGHT,
2022
get_operation_name,
2123
)
22-
from .errors import S3Error, raise_for_client_error, raise_for_exception
23-
from .handlers import S3ProxyHandler
2424
from .routing import RequestDispatcher
2525
from .s3client import ParsedRequest, SigV4Verifier
2626

s3proxy/state/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
# Recovery
3737
from .recovery import reconstruct_upload_state_from_s3
3838

39-
# Serialization utilities
40-
from .serialization import json_dumps, json_loads
41-
4239
# Redis client
4340
from .redis import (
4441
close_redis,
@@ -47,6 +44,9 @@
4744
init_redis,
4845
is_using_redis,
4946
)
47+
48+
# Serialization utilities
49+
from .serialization import json_dumps, json_loads
5050
from .storage import MemoryStateStore, RedisStateStore, StateStore
5151

5252
__all__ = [

s3proxy/state/storage.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ async def get_and_delete(self, key: str, _retries: int = 0) -> bytes | None:
141141

142142
except redis.WatchError:
143143
if _retries >= MAX_WATCH_RETRIES:
144-
logger.error("REDIS_WATCH_RETRIES_EXHAUSTED", key=key, operation="get_and_delete")
144+
logger.error(
145+
"REDIS_WATCH_RETRIES_EXHAUSTED",
146+
key=key,
147+
operation="get_and_delete",
148+
)
145149
raise
146150
logger.debug("REDIS_WATCH_RETRY", key=key, attempt=_retries + 1)
147151
return await self.get_and_delete(key, _retries=_retries + 1)

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
os.environ.setdefault("S3PROXY_ENCRYPT_KEY", "test-encryption-key-for-pytest")
1515
os.environ.setdefault("S3PROXY_HOST", "http://localhost:9000")
1616

17-
from s3proxy.state import redis as state_redis
1817
from s3proxy.config import Settings
19-
from s3proxy.state import MultipartStateManager
2018
from s3proxy.s3client import S3Client, S3Credentials
19+
from s3proxy.state import MultipartStateManager
20+
from s3proxy.state import redis as state_redis
2121

2222
# ============================================================================
2323
# Redis Fixtures

tests/ha/test_ha_redis_e2e.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import httpx
2222
import pytest
2323

24-
from s3proxy.config import Settings
25-
2624

2725
def is_docker_available():
2826
"""Check if Docker is available and running."""

0 commit comments

Comments
 (0)