Skip to content

Commit 5b91eb7

Browse files
committed
Fix ruff lint errors for Python 3.11+ target
Replace Optional[X] with X | None (UP045) and add strict=True to zip() call (B905), as required by ruff with target-version py311.
1 parent fbdabd7 commit 5b91eb7

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

spicepy/_client.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import platform
44
import threading
55
from pathlib import Path
6-
from typing import Any, Optional, Union
6+
from typing import Any
77

88
import certifi
99
import pyarrow as pa
@@ -54,8 +54,8 @@ class _ADBCClient:
5454
def __init__(
5555
self,
5656
uri: str,
57-
api_key: Optional[str] = None,
58-
user_agent: Optional[str] = None,
57+
api_key: str | None = None,
58+
user_agent: str | None = None,
5959
):
6060
if not ADBC_AVAILABLE:
6161
raise ImportError(
@@ -120,7 +120,7 @@ def _create_param_batch(
120120

121121
# Create parameter arrays (each with a single row)
122122
param_arrays = []
123-
for value, arrow_type in zip(param_values, param_types):
123+
for value, arrow_type in zip(param_values, param_types, strict=True):
124124
param_arrays.append(pa.array([value], type=arrow_type))
125125

126126
# Create parameter schema with positional field names ($1, $2, etc.)
@@ -268,19 +268,19 @@ class Client:
268268
# pylint: disable=R0917
269269
def __init__(
270270
self,
271-
api_key: Optional[str] = None,
271+
api_key: str | None = None,
272272
flight_url: str = config.DEFAULT_LOCAL_FLIGHT_URL,
273273
http_url: str = config.DEFAULT_HTTP_URL,
274-
tls_root_cert: Union[str, Path, None] = None,
275-
user_agent: Optional[str] = None,
274+
tls_root_cert: str | Path | None = None,
275+
user_agent: str | None = None,
276276
): # pylint: disable=R0913
277277
tls_root_certs = _Cert(tls_root_cert).tls_root_certs
278278
self._flight = _SpiceFlight(flight_url, api_key or "", tls_root_certs, user_agent)
279279

280280
self.api_key = api_key
281281
self._flight_url = flight_url
282282
self._user_agent = user_agent
283-
self._adbc_client: Optional[_ADBCClient] = None
283+
self._adbc_client: _ADBCClient | None = None
284284
self.http = HttpRequests(http_url, self._headers(user_agent))
285285

286286
def _headers(self, user_agent=None) -> dict[str, str]:
@@ -373,7 +373,7 @@ def query_with_params(
373373
adbc = self._ensure_adbc_client()
374374
return adbc.query_with_params(sql, params)
375375

376-
def refresh_dataset(self, dataset: str, refresh_opts: Optional[RefreshOpts] = None) -> Any:
376+
def refresh_dataset(self, dataset: str, refresh_opts: RefreshOpts | None = None) -> Any:
377377
response = self.http.send_request(
378378
"POST",
379379
f"/v1/datasets/{dataset}/acceleration/refresh",

spicepy/_http.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
2+
from collections.abc import Callable
23
from dataclasses import dataclass
3-
from typing import Any, Callable, Literal, Optional
4+
from typing import Any, Literal
45

56
from requests import Response, Session
67
from requests.adapters import HTTPAdapter, Retry
@@ -11,9 +12,9 @@
1112

1213
@dataclass
1314
class RefreshOpts:
14-
refresh_sql: Optional[str] = None
15-
refresh_mode: Optional[str] = None
16-
refresh_jitter_max: Optional[str] = None
15+
refresh_sql: str | None = None
16+
refresh_mode: str | None = None
17+
refresh_jitter_max: str | None = None
1718

1819
def to_dict(self) -> dict[str, Any]:
1920
return {
@@ -42,9 +43,9 @@ def send_request(
4243
self,
4344
method: HttpMethod,
4445
path: str,
45-
param: Optional[dict[str, Any]] = None,
46-
headers: Optional[dict[str, Any]] = None,
47-
body: Optional[str] = None,
46+
param: dict[str, Any] | None = None,
47+
headers: dict[str, Any] | None = None,
48+
body: str | None = None,
4849
) -> Any:
4950
if headers is None:
5051
headers = {}

spicepy/config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
22
import platform
33
from importlib.metadata import version
4-
from typing import Optional
54

65

76
DEFAULT_FLIGHT_URL = os.environ.get("SPICE_FLIGHT_URL", "grpc+tls://flight.spiceai.io")
@@ -20,7 +19,7 @@
2019
# Default is the system information of the current system, e.g. `Linux/5.4.0-1043-aws x86_64`.
2120
###
2221
def get_user_agent(
23-
client_name: Optional[str] = None, client_version: Optional[str] = None, client_system: Optional[str] = None
22+
client_name: str | None = None, client_version: str | None = None, client_system: str | None = None
2423
) -> str:
2524
package_version = version("spicepy") if client_version is None else client_version
2625
system = platform.system()

0 commit comments

Comments
 (0)