From d16d8642a15de98c17760ec2fc56118f77a6467f Mon Sep 17 00:00:00 2001 From: Jan-Lukas Wynen Date: Fri, 19 Apr 2024 15:31:43 +0200 Subject: [PATCH] Run updated ruff --- pyproject.toml | 1 + src/scitacean/_internal/docker.py | 4 ++-- src/scitacean/client.py | 8 ++++---- src/scitacean/model.py | 2 +- src/scitacean/testing/backend/_backend.py | 4 ++-- src/scitacean/testing/strategies.py | 6 +++--- src/scitacean/typing.py | 9 ++++++--- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6033589a..4e0ea23b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -107,6 +107,7 @@ ignore = [ "B905", # `zip()` without an explicit `strict=` parameter "S324", # insecure hsh function; we don't use hashing for security "E741", "E742", "E743", # do not use names ‘l’, ‘O’, or ‘I’; they are not a problem with a proper font + "UP038", # does not seem to work and leads to slower code "E111", "E114", "E117", "D206", "D300", # conflict with ruff format "D105", ] diff --git a/src/scitacean/_internal/docker.py b/src/scitacean/_internal/docker.py index 009ba5c9..dc4e47a8 100644 --- a/src/scitacean/_internal/docker.py +++ b/src/scitacean/_internal/docker.py @@ -9,9 +9,9 @@ import json import os import subprocess -from typing import Any, Union +from typing import Any -_PathLike = Union[str, os.PathLike[str]] +_PathLike = str | os.PathLike[str] def docker_compose_up(config_file: _PathLike, *services: str) -> None: diff --git a/src/scitacean/client.py b/src/scitacean/client.py index 1465fd80..4e9506cd 100644 --- a/src/scitacean/client.py +++ b/src/scitacean/client.py @@ -11,7 +11,7 @@ from collections.abc import Callable, Iterable, Iterator from contextlib import contextmanager from pathlib import Path -from typing import Any, Union +from typing import Any from urllib.parse import quote_plus import requests @@ -1162,9 +1162,9 @@ def _get_token( raise ScicatLoginError(response.content) -FileSelector = Union[ - bool, str, list[str], tuple[str], re.Pattern[str], Callable[[File], bool] -] +FileSelector = ( + bool | str | list[str] | tuple[str] | re.Pattern[str] | Callable[[File], bool] +) def _file_selector(select: FileSelector) -> Callable[[File], bool]: diff --git a/src/scitacean/model.py b/src/scitacean/model.py index d500972c..f170ff7e 100644 --- a/src/scitacean/model.py +++ b/src/scitacean/model.py @@ -127,7 +127,7 @@ class DownloadDataset( dataQualityMetrics: int | None = None description: str | None = None endTime: datetime | None = None - history: None | None = None + history: None = None instrumentGroup: str | None = None instrumentId: str | None = None isPublished: bool | None = None diff --git a/src/scitacean/testing/backend/_backend.py b/src/scitacean/testing/backend/_backend.py index b0c6b8a1..c76798e1 100644 --- a/src/scitacean/testing/backend/_backend.py +++ b/src/scitacean/testing/backend/_backend.py @@ -5,7 +5,7 @@ import time from copy import deepcopy from pathlib import Path -from typing import Any, Union +from typing import Any from urllib.parse import urljoin import requests @@ -14,7 +14,7 @@ from ..._internal.docker import docker_compose_down, docker_compose_up from . import config -_PathLike = Union[str, os.PathLike[str]] +_PathLike = str | os.PathLike[str] def _read_yaml(filename: str) -> Any: diff --git a/src/scitacean/testing/strategies.py b/src/scitacean/testing/strategies.py index 54958677..b6d73681 100644 --- a/src/scitacean/testing/strategies.py +++ b/src/scitacean/testing/strategies.py @@ -31,7 +31,7 @@ import string from functools import partial -from typing import Any, Optional +from typing import Any from email_validator import EmailNotValidError, ValidatedEmail, validate_email from hypothesis import strategies as st @@ -151,7 +151,7 @@ def _scientific_metadata_strategy( def _job_parameters_strategy( field: Dataset.Field, ) -> st.SearchStrategy[dict[str, str] | None]: - return st.from_type(Optional[dict[str, str]]) # type: ignore[arg-type] + return st.from_type(dict[str, str] | None) # type: ignore[arg-type] def _lifecycle_strategy( @@ -192,7 +192,7 @@ def _field_strategy(field: Dataset.Field) -> st.SearchStrategy[Any]: if (strategy := _SPECIAL_FIELDS.get(field.name)) is not None: return strategy(field) - typ = field.type if field.required else Optional[field.type] + typ = field.type if field.required else field.type | None return st.from_type(typ) # type:ignore[arg-type] diff --git a/src/scitacean/typing.py b/src/scitacean/typing.py index b608d618..10598d20 100644 --- a/src/scitacean/typing.py +++ b/src/scitacean/typing.py @@ -3,8 +3,9 @@ """Definitions for type checking.""" +from contextlib import AbstractContextManager from pathlib import Path -from typing import ContextManager, Protocol +from typing import Protocol from .dataset import Dataset from .file import File @@ -29,7 +30,7 @@ def download_files(self, *, remote: list[RemotePath], local: list[Path]) -> None class Downloader(Protocol): """Handler for file downloads.""" - def connect_for_download(self) -> ContextManager[DownloadConnection]: + def connect_for_download(self) -> AbstractContextManager[DownloadConnection]: """Open a connection to the file server. Returns @@ -90,7 +91,9 @@ def source_folder_for(self, dataset: Dataset) -> RemotePath: The source folder for ``dataset``. """ - def connect_for_upload(self, dataset: Dataset) -> ContextManager[UploadConnection]: + def connect_for_upload( + self, dataset: Dataset + ) -> AbstractContextManager[UploadConnection]: """Open a connection to the file server. Parameters