Skip to content

Commit e42f1b8

Browse files
committed
style: apply ruff lint and format to existing test/doc code
Address pre-existing ruff findings that were masked by the protoc build failure in the lint job. Manual fixes in 5 files: - tests/integration/test_assistants{,_async}.py: B904 add `from None` to AssertionError raises inside except blocks - tests/unit/test_http_error_parsing.py: RUF059 rename unused tuple unpack targets to `_code`/`_error_code`; SIM201 `not msg == ""` → `msg != ""` - tests/unit/preview/test_async_parity.py: F841 remove unused local - tests/unit/models/assistant/test_streaming_display.py: E402 hoist AsyncChatCompletionStream import to the top of the file Plus `ruff format` auto-applied to 28 files of pre-existing format drift. No behavioral changes.
1 parent 4574ce8 commit e42f1b8

32 files changed

Lines changed: 131 additions & 104 deletions

‎pinecone/_internal/indexes_helpers.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ def validate_create_inputs(
114114
raise ValidationError("spec dict must contain a 'serverless', 'pod', or 'byoc' key")
115115

116116
if dimension is not None and not isinstance(dimension, int):
117-
raise PineconeTypeError(
118-
f"dimension must be an integer, got {type(dimension).__name__!r}"
119-
)
117+
raise PineconeTypeError(f"dimension must be an integer, got {type(dimension).__name__!r}")
120118

121119
resolved_vt = resolve_enum_value(vector_type)
122120
if resolved_vt == "sparse" and dimension is not None:

‎tests/integration/test_admin.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ def test_admin_init_validation_whitespace_only_client_id(monkeypatch: pytest.Mon
9494

9595

9696
@pytest.mark.integration
97-
def test_admin_init_validation_whitespace_only_client_secret(monkeypatch: pytest.MonkeyPatch) -> None:
97+
def test_admin_init_validation_whitespace_only_client_secret(
98+
monkeypatch: pytest.MonkeyPatch,
99+
) -> None:
98100
"""Admin() raises PineconeValueError for a whitespace-only client_secret.
99101
100102
Env vars are cleared to prevent the fallback from masking the kwarg value.

‎tests/integration/test_assistants.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ def test_context_retrieval_validation_rest(client: Pinecone) -> None:
10921092
raise AssertionError(
10931093
"context() raised PineconeValueError when query='' and messages is non-empty — "
10941094
"empty string should be treated as not provided, leaving messages as the sole input"
1095-
)
1095+
) from None
10961096
except Exception:
10971097
# Any other exception (ApiError, NotFoundError, etc.) is acceptable here —
10981098
# the assistant does not exist and the API will reject the request.

‎tests/integration/test_assistants_async.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ async def test_context_retrieval_validation_async(async_client: AsyncPinecone) -
11601160
raise AssertionError(
11611161
"context() raised PineconeValueError when query='' and messages is non-empty — "
11621162
"empty string should be treated as not provided, leaving messages as the sole input"
1163-
)
1163+
) from None
11641164
except Exception:
11651165
# Any other exception (ApiError, NotFoundError, etc.) is acceptable here —
11661166
# the assistant does not exist and the API will reject the request.

‎tests/perf/test_grpc_throughput.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
QUERY_RESPONSE = {
1212
"matches": [
13-
{"id": f"v{i}", "score": 0.9 - i * 0.01, "values": [], "metadata": None}
14-
for i in range(100)
13+
{"id": f"v{i}", "score": 0.9 - i * 0.01, "values": [], "metadata": None} for i in range(100)
1514
],
1615
"namespace": "ns",
1716
"usage": {"read_units": 1},

‎tests/smoke/helpers.py‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ def wait_for_pod_warmup(
128128
last_exc = exc
129129
time.sleep(interval)
130130
raise TimeoutError(
131-
f"Pod index did not warm up within {timeout}s "
132-
f"(last fetch error: {last_exc!r})"
131+
f"Pod index did not warm up within {timeout}s (last fetch error: {last_exc!r})"
133132
)
134133

135134

@@ -157,11 +156,8 @@ def capture_deprecation_warning(expected_substring: str = "") -> Iterator[list[A
157156
relevant = [r for r in records if issubclass(r.category, DeprecationWarning)]
158157
if not relevant:
159158
raise AssertionError("Expected at least one DeprecationWarning, got none")
160-
if expected_substring and not any(
161-
expected_substring in str(r.message) for r in relevant
162-
):
159+
if expected_substring and not any(expected_substring in str(r.message) for r in relevant):
163160
messages = [str(r.message) for r in relevant]
164161
raise AssertionError(
165-
f"No captured DeprecationWarning contained {expected_substring!r}. "
166-
f"Got: {messages}"
162+
f"No captured DeprecationWarning contained {expected_substring!r}. Got: {messages}"
167163
)

‎tests/smoke/test_assistants_async.py‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ async def status_check() -> str:
8989
assert multimodal_file.status == "Available"
9090

9191
# ----- describe_file / list_files / list_files_page -----
92-
d_file = await pc.assistants.describe_file(
93-
assistant_name=name, file_id=text_file.id
94-
)
92+
d_file = await pc.assistants.describe_file(assistant_name=name, file_id=text_file.id)
9593
assert d_file.id == text_file.id
9694

9795
all_files = await pc.assistants.list_files(assistant_name=name).to_list()
@@ -161,9 +159,7 @@ async def status_check() -> str:
161159
assert via_call.name == name
162160

163161
# ----- delete_file -----
164-
await pc.assistants.delete_file(
165-
assistant_name=name, file_id=text_file.id
166-
)
162+
await pc.assistants.delete_file(assistant_name=name, file_id=text_file.id)
167163
finally:
168164
await async_cleanup_resource(
169165
lambda: pc.assistants.delete(name=name),

‎tests/smoke/test_assistants_sync.py‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ def test_assistants_smoke(client: Pinecone) -> None:
9393
assert multimodal_file.status == "Available"
9494

9595
# ----- describe_file / list_files / list_files_page -----
96-
d_file = client.assistants.describe_file(
97-
assistant_name=name, file_id=text_file.id
98-
)
96+
d_file = client.assistants.describe_file(assistant_name=name, file_id=text_file.id)
9997
assert d_file.id == text_file.id
10098

10199
all_files = client.assistants.list_files(assistant_name=name).to_list()
@@ -163,9 +161,7 @@ def test_assistants_smoke(client: Pinecone) -> None:
163161
assert via_call.name == name
164162

165163
# ----- delete_file (one of them) -----
166-
client.assistants.delete_file(
167-
assistant_name=name, file_id=text_file.id
168-
)
164+
client.assistants.delete_file(assistant_name=name, file_id=text_file.id)
169165
finally:
170166
# delete assistant first (tears down files server-side too)
171167
cleanup_resource(

‎tests/smoke/test_deprecated_shims_async.py‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ async def test_deprecated_shims_smoke_async(api_key: str) -> None:
7676
assert exists is True
7777

7878
with capture_deprecation_warning("configure_index"):
79-
await async_client.configure_index(
80-
serverless_name, tags={"env": "smoke-async"}
81-
)
79+
await async_client.configure_index(serverless_name, tags={"env": "smoke-async"})
8280

8381
# ----- IndexAsyncio() factory (constructor only) -----
8482
with capture_deprecation_warning("IndexAsyncio"):
@@ -109,9 +107,7 @@ async def test_deprecated_shims_smoke_async(api_key: str) -> None:
109107
jobs = await async_client.list_restore_jobs(limit=10)
110108
if jobs.data:
111109
with capture_deprecation_warning("describe_restore_job"):
112-
await async_client.describe_restore_job(
113-
job_id=jobs.data[0].restore_job_id
114-
)
110+
await async_client.describe_restore_job(job_id=jobs.data[0].restore_job_id)
115111
else:
116112
with capture_deprecation_warning("describe_restore_job"):
117113
with pytest.raises((NotFoundError, PineconeApiException)):

‎tests/smoke/test_pod_collections_async.py‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ async def _async_wait_for_collection_deletion(
4040
await asyncio.sleep(interval)
4141
print(f" WARNING: collection {name} still present after {timeout}s")
4242

43+
4344
POD_ENV = "us-east-1-aws"
4445
DIM = 8
4546
NAMESPACE = "smoke-pod-ns-async"
@@ -72,8 +73,7 @@ async def _async_wait_for_pod_warmup(
7273
last_exc = exc
7374
await asyncio.sleep(interval)
7475
raise TimeoutError(
75-
f"Pod index did not warm up within {timeout}s "
76-
f"(last fetch error: {last_exc!r})"
76+
f"Pod index did not warm up within {timeout}s (last fetch error: {last_exc!r})"
7777
)
7878

7979

@@ -97,13 +97,9 @@ async def test_pod_collections_smoke_async(api_key: str) -> None:
9797
idx1 = pc.index(name=pod1_name)
9898
try:
9999
await idx1.upsert(vectors=[_vec(0)], namespace=NAMESPACE)
100-
await _async_wait_for_pod_warmup(
101-
idx1, "p0", namespace=NAMESPACE, timeout=600
102-
)
100+
await _async_wait_for_pod_warmup(idx1, "p0", namespace=NAMESPACE, timeout=600)
103101

104-
await idx1.upsert(
105-
vectors=[_vec(i) for i in range(1, 6)], namespace=NAMESPACE
106-
)
102+
await idx1.upsert(vectors=[_vec(i) for i in range(1, 6)], namespace=NAMESPACE)
107103
await async_wait_for_vector_count(idx1, NAMESPACE, expected=6, timeout=120)
108104

109105
q = await idx1.query(
@@ -148,9 +144,7 @@ async def col_status() -> object:
148144

149145
idx2 = pc.index(name=pod2_name)
150146
try:
151-
await _async_wait_for_pod_warmup(
152-
idx2, "p0", namespace=NAMESPACE, timeout=300
153-
)
147+
await _async_wait_for_pod_warmup(idx2, "p0", namespace=NAMESPACE, timeout=300)
154148
stats = await idx2.describe_index_stats()
155149
ns = stats.namespaces.get(NAMESPACE)
156150
assert ns is not None

0 commit comments

Comments
 (0)