From dd559394d3973a85eb3fe40cf7efa146031d98dd Mon Sep 17 00:00:00 2001 From: Krzysztof Godlewski Date: Wed, 18 Dec 2024 17:14:03 +0100 Subject: [PATCH] Python 3.9 typehints fixes --- src/neptune_scale/api/attribute.py | 2 +- src/neptune_scale/net/ingest_code.py | 9 ++------- src/neptune_scale/sync/errors_tracking.py | 1 + src/neptune_scale/sync/files/worker.py | 12 ++++++------ 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/neptune_scale/api/attribute.py b/src/neptune_scale/api/attribute.py index 8b228df..8b11e47 100644 --- a/src/neptune_scale/api/attribute.py +++ b/src/neptune_scale/api/attribute.py @@ -29,7 +29,7 @@ __all__ = ("Attribute", "AttributeStore") -def _extract_named_kwargs(fn: Callable) -> Set[str]: +def _extract_named_kwargs(fn: Callable) -> set[str]: """Return a set of named arguments of a function, that are not positional-only.""" import inspect diff --git a/src/neptune_scale/net/ingest_code.py b/src/neptune_scale/net/ingest_code.py index e853db2..74fe179 100644 --- a/src/neptune_scale/net/ingest_code.py +++ b/src/neptune_scale/net/ingest_code.py @@ -1,8 +1,3 @@ -from typing import ( - Dict, - Type, -) - from neptune_api.proto.neptune_pb.ingest.v1.ingest_pb2 import IngestCode from neptune_scale.exceptions import ( @@ -29,7 +24,7 @@ NeptuneUnexpectedError, ) -CODE_TO_ERROR: Dict[IngestCode.ValueType, Type[Exception]] = { +CODE_TO_ERROR: dict[IngestCode.ValueType, type[Exception]] = { IngestCode.PROJECT_NOT_FOUND: NeptuneProjectNotFound, IngestCode.PROJECT_INVALID_NAME: NeptuneProjectInvalidName, IngestCode.RUN_NOT_FOUND: NeptuneRunNotFound, @@ -53,7 +48,7 @@ } -def code_to_exception(code: IngestCode.ValueType) -> Type[Exception]: +def code_to_exception(code: IngestCode.ValueType) -> type[Exception]: if exc_class := CODE_TO_ERROR.get(code): return exc_class diff --git a/src/neptune_scale/sync/errors_tracking.py b/src/neptune_scale/sync/errors_tracking.py index fc341ed..f8182e1 100644 --- a/src/neptune_scale/sync/errors_tracking.py +++ b/src/neptune_scale/sync/errors_tracking.py @@ -5,6 +5,7 @@ import multiprocessing import queue import time +import traceback from collections.abc import Callable from typing import Optional diff --git a/src/neptune_scale/sync/files/worker.py b/src/neptune_scale/sync/files/worker.py index 5183afc..31d6463 100644 --- a/src/neptune_scale/sync/files/worker.py +++ b/src/neptune_scale/sync/files/worker.py @@ -2,18 +2,18 @@ import mimetypes import time import uuid +from collections.abc import ( + Callable, + Sequence, +) from concurrent import futures from datetime import datetime from pathlib import Path from queue import Empty from typing import ( BinaryIO, - Callable, - List, Literal, Optional, - Sequence, - Tuple, ) import backoff @@ -167,7 +167,7 @@ def _submit_attribute(self, attribute_path: str, file_path: str, timestamp: date @backoff.on_exception(backoff.expo, NeptuneRetryableError, max_time=MAX_REQUEST_RETRY_SECONDS) @with_api_errors_handling - def _wait_for_completion(self, request_ids: List[str]) -> None: + def _wait_for_completion(self, request_ids: list[str]) -> None: assert self._backend is not None # mypy while self.is_running(): @@ -212,7 +212,7 @@ def determine_path_and_mime_type( local_path: Optional[Path], target_path: Optional[str], target_basename: Optional[str], -) -> Tuple[str, str]: +) -> tuple[str, str]: mime_type = guess_mime_type(attribute_path, local_path) # Target path always takes precedence as-is