From f526a06d877b1e4a85fa3f3acc2490061d1d5153 Mon Sep 17 00:00:00 2001 From: Federico Stagni Date: Fri, 23 Aug 2024 17:26:28 +0200 Subject: [PATCH] style: pyupgrade --py311-plus --- diracx-core/src/diracx/core/config/schema.py | 6 +++--- diracx-core/src/diracx/core/properties.py | 3 ++- diracx-core/src/diracx/core/settings.py | 3 ++- diracx-db/src/diracx/db/os/utils.py | 3 ++- diracx-db/src/diracx/db/sql/jobs/db.py | 8 +++----- diracx-db/src/diracx/db/sql/utils.py | 3 ++- diracx-routers/src/diracx/routers/__init__.py | 16 +++++++--------- .../src/diracx/routers/access_policies.py | 3 ++- .../routers/job_manager/access_policies.py | 3 ++- .../src/diracx/routers/job_manager/sandboxes.py | 3 ++- 10 files changed, 27 insertions(+), 24 deletions(-) diff --git a/diracx-core/src/diracx/core/config/schema.py b/diracx-core/src/diracx/core/config/schema.py index 29c1c514d..84c24720d 100644 --- a/diracx-core/src/diracx/core/config/schema.py +++ b/diracx-core/src/diracx/core/config/schema.py @@ -2,7 +2,7 @@ import os from datetime import datetime -from typing import Annotated, Any, Optional, TypeVar +from typing import Annotated, Any, TypeVar from pydantic import BaseModel as _BaseModel from pydantic import ConfigDict, EmailStr, Field, PrivateAttr, model_validator @@ -65,10 +65,10 @@ class GroupConfig(BaseModel): AutoUploadProxy: bool = False JobShare: int = 1000 Properties: SerializableSet[SecurityProperty] - Quota: Optional[int] = None + Quota: int | None = None Users: SerializableSet[str] AllowBackgroundTQs: bool = False - VOMSRole: Optional[str] = None + VOMSRole: str | None = None AutoSyncVOMS: bool = False diff --git a/diracx-core/src/diracx/core/properties.py b/diracx-core/src/diracx/core/properties.py index 3a80b8794..c75c014ec 100644 --- a/diracx-core/src/diracx/core/properties.py +++ b/diracx-core/src/diracx/core/properties.py @@ -6,7 +6,8 @@ import inspect import operator -from typing import Any, Callable +from collections.abc import Callable +from typing import Any from pydantic import GetCoreSchemaHandler from pydantic_core import CoreSchema, core_schema diff --git a/diracx-core/src/diracx/core/settings.py b/diracx-core/src/diracx/core/settings.py index 936dad05e..3ee37df88 100644 --- a/diracx-core/src/diracx/core/settings.py +++ b/diracx-core/src/diracx/core/settings.py @@ -7,8 +7,9 @@ ) import contextlib +from collections.abc import AsyncIterator from pathlib import Path -from typing import Annotated, Any, AsyncIterator, Self, TypeVar +from typing import Annotated, Any, Self, TypeVar from authlib.jose import JsonWebKey from cryptography.fernet import Fernet diff --git a/diracx-db/src/diracx/db/os/utils.py b/diracx-db/src/diracx/db/os/utils.py index 1033a9440..659c20bdb 100644 --- a/diracx-db/src/diracx/db/os/utils.py +++ b/diracx-db/src/diracx/db/os/utils.py @@ -7,9 +7,10 @@ import logging import os from abc import ABCMeta, abstractmethod +from collections.abc import AsyncIterator from contextvars import ContextVar from datetime import datetime -from typing import Any, AsyncIterator, Self +from typing import Any, Self from opensearchpy import AsyncOpenSearch diff --git a/diracx-db/src/diracx/db/sql/jobs/db.py b/diracx-db/src/diracx/db/sql/jobs/db.py index 38938ddbb..36ba6cc11 100644 --- a/diracx-db/src/diracx/db/sql/jobs/db.py +++ b/diracx-db/src/diracx/db/sql/jobs/db.py @@ -503,9 +503,7 @@ async def set_properties( """ # Check that all we always update the same set of properties - required_parameters_set = set( - [tuple(sorted(k.keys())) for k in properties.values()] - ) + required_parameters_set = {tuple(sorted(k.keys())) for k in properties.values()} if len(required_parameters_set) != 1: raise NotImplementedError( @@ -682,10 +680,10 @@ async def get_tq_infos_for_jobs( .join(JobsQueue, TaskQueues.TQId == JobsQueue.TQId) .where(JobsQueue.JobId.in_(job_ids)) ) - return set( + return { (int(row[0]), str(row[1]), str(row[2]), str(row[3])) for row in (await self.conn.execute(stmt)).all() - ) + } async def get_owner_for_task_queue(self, tq_id: int) -> dict[str, str]: """Get the owner and owner group for a task queue.""" diff --git a/diracx-db/src/diracx/db/sql/utils.py b/diracx-db/src/diracx/db/sql/utils.py index 9dba7b8a9..6c16e385f 100644 --- a/diracx-db/src/diracx/db/sql/utils.py +++ b/diracx-db/src/diracx/db/sql/utils.py @@ -6,10 +6,11 @@ import logging import os from abc import ABCMeta +from collections.abc import AsyncIterator from contextvars import ContextVar from datetime import datetime, timedelta, timezone from functools import partial -from typing import TYPE_CHECKING, AsyncIterator, Self, cast +from typing import TYPE_CHECKING, Self, cast from pydantic import TypeAdapter from sqlalchemy import Column as RawColumn diff --git a/diracx-routers/src/diracx/routers/__init__.py b/diracx-routers/src/diracx/routers/__init__.py index 2ff15cded..26a832636 100644 --- a/diracx-routers/src/diracx/routers/__init__.py +++ b/diracx-routers/src/diracx/routers/__init__.py @@ -10,10 +10,10 @@ import inspect import logging import os -from collections.abc import AsyncGenerator +from collections.abc import AsyncGenerator, Awaitable, Callable, Iterable, Sequence from functools import partial from logging import Formatter, StreamHandler -from typing import Any, Awaitable, Callable, Iterable, Sequence, TypeVar, cast +from typing import Any, TypeVar, cast import dotenv from cachetools import TTLCache @@ -346,12 +346,10 @@ def create_app() -> DiracFastAPI: # Find all the access policies - available_access_policy_names = set( - [ - entry_point.name - for entry_point in select_from_extension(group="diracx.access_policies") - ] - ) + available_access_policy_names = { + entry_point.name + for entry_point in select_from_extension(group="diracx.access_policies") + } all_access_policies = {} @@ -428,7 +426,7 @@ async def is_db_unavailable(db: BaseSQLDB | BaseOSDB) -> str: return _db_alive_cache[db] -async def db_transaction(db: T2) -> AsyncGenerator[T2, None]: +async def db_transaction(db: T2) -> AsyncGenerator[T2]: """Initiate a DB transaction.""" # Entering the context already triggers a connection to the DB # that may fail diff --git a/diracx-routers/src/diracx/routers/access_policies.py b/diracx-routers/src/diracx/routers/access_policies.py index cb4d5a7f3..b7605fe7f 100644 --- a/diracx-routers/src/diracx/routers/access_policies.py +++ b/diracx-routers/src/diracx/routers/access_policies.py @@ -21,7 +21,8 @@ import os import time from abc import ABCMeta, abstractmethod -from typing import Annotated, Callable, Self +from collections.abc import Callable +from typing import Annotated, Self from fastapi import Depends diff --git a/diracx-routers/src/diracx/routers/job_manager/access_policies.py b/diracx-routers/src/diracx/routers/job_manager/access_policies.py index 40d6a75b9..68ff4a913 100644 --- a/diracx-routers/src/diracx/routers/job_manager/access_policies.py +++ b/diracx-routers/src/diracx/routers/job_manager/access_policies.py @@ -1,7 +1,8 @@ from __future__ import annotations +from collections.abc import Callable from enum import StrEnum, auto -from typing import Annotated, Callable +from typing import Annotated from fastapi import Depends, HTTPException, status diff --git a/diracx-routers/src/diracx/routers/job_manager/sandboxes.py b/diracx-routers/src/diracx/routers/job_manager/sandboxes.py index 6e62379c5..43f3545ea 100644 --- a/diracx-routers/src/diracx/routers/job_manager/sandboxes.py +++ b/diracx-routers/src/diracx/routers/job_manager/sandboxes.py @@ -1,8 +1,9 @@ from __future__ import annotations import contextlib +from collections.abc import AsyncIterator from http import HTTPStatus -from typing import TYPE_CHECKING, Annotated, AsyncIterator, Literal +from typing import TYPE_CHECKING, Annotated, Literal from aiobotocore.session import get_session from botocore.config import Config