Skip to content

Commit

Permalink
style: pyupgrade --py311-plus
Browse files Browse the repository at this point in the history
  • Loading branch information
fstagni committed Aug 23, 2024
1 parent d96651d commit 634078e
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 34 deletions.
10 changes: 5 additions & 5 deletions diracx-cli/src/diracx/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import os
from datetime import datetime, timedelta, timezone
from typing import Annotated, Optional
from typing import Annotated

import typer

Expand Down Expand Up @@ -38,9 +38,9 @@ def vo_callback(vo: str | None) -> str:

@app.async_command()
async def login(
vo: Annotated[Optional[str], typer.Argument(callback=vo_callback)] = None,
group: Optional[str] = None,
property: Optional[list[str]] = typer.Option(
vo: Annotated[str | None, typer.Argument(callback=vo_callback)] = None,
group: str | None = None,
property: list[str] | None = typer.Option(
None, help="Override the default(s) with one or more properties"
),
):
Expand Down Expand Up @@ -110,7 +110,7 @@ async def logout():


@app.callback()
def callback(output_format: Optional[str] = None):
def callback(output_format: str | None = None):
if output_format is not None:
os.environ["DIRACX_OUTPUT_FORMAT"] = output_format

Expand Down
6 changes: 3 additions & 3 deletions diracx-cli/src/diracx/cli/internal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import Annotated, Optional
from typing import Annotated

import git
import typer
Expand Down Expand Up @@ -54,7 +54,7 @@ def add_vo(
config_repo: str,
*,
vo: Annotated[str, typer.Option()],
default_group: Optional[str] = "user",
default_group: str | None = "user",
idp_url: Annotated[str, typer.Option()],
idp_client_id: Annotated[str, typer.Option()],
):
Expand Down Expand Up @@ -133,7 +133,7 @@ def add_user(
config_repo: str,
*,
vo: Annotated[str, typer.Option()],
groups: Annotated[Optional[list[str]], typer.Option("--group")] = None,
groups: Annotated[list[str] | None, typer.Option("--group")] = None,
sub: Annotated[str, typer.Option()],
preferred_username: Annotated[str, typer.Option()],
):
Expand Down
4 changes: 2 additions & 2 deletions diracx-cli/tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def jdl_file():

async def test_submit(with_cli_login, jdl_file, capfd):
"""Test submitting a job using a JDL file."""
with open(jdl_file, "r") as temp_file:
with open(jdl_file) as temp_file:
await cli.jobs.submit([temp_file])

cap = capfd.readouterr()
Expand All @@ -52,7 +52,7 @@ async def test_submit(with_cli_login, jdl_file, capfd):
async def test_search(with_cli_login, jdl_file, capfd):
"""Test searching for jobs."""
# Submit 20 jobs
with open(jdl_file, "r") as temp_file:
with open(jdl_file) as temp_file:
await cli.jobs.submit([temp_file] * 20)

cap = capfd.readouterr()
Expand Down
6 changes: 3 additions & 3 deletions diracx-core/src/diracx/core/config/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
3 changes: 2 additions & 1 deletion diracx-core/src/diracx/core/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion diracx-core/src/diracx/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion diracx-db/src/diracx/db/os/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 3 additions & 5 deletions diracx-db/src/diracx/db/sql/jobs/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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."""
Expand Down
3 changes: 2 additions & 1 deletion diracx-db/src/diracx/db/sql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 7 additions & 9 deletions diracx-routers/src/diracx/routers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion diracx-routers/src/diracx/routers/access_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 2 additions & 1 deletion diracx-routers/src/diracx/routers/job_manager/sandboxes.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 634078e

Please sign in to comment.