Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(all): multiple warnings fix #2318

Merged
merged 26 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8ecc6b5
fix: multiple warnings fix
TheoPascoli Jan 27, 2025
d3c01ea
fix: multiple warnings fix
TheoPascoli Jan 27, 2025
2b33b6f
Merge branch 'dev' into fix/remove-some-deprecated-methods
TheoPascoli Jan 30, 2025
9bad46c
Merge branch 'fix/remove-some-deprecated-methods' of https://github.c…
TheoPascoli Jan 30, 2025
81fc4f7
Merge remote-tracking branch 'origin/dev' into fix/remove-some-deprec…
TheoPascoli Jan 30, 2025
bd671ed
fix(bc): sonar blocker fix
TheoPascoli Jan 30, 2025
3776096
fix(bc): sonar blocker fix
TheoPascoli Jan 30, 2025
4d67159
fix(bc): sonar blocker fix
TheoPascoli Jan 30, 2025
55eceee
fix(bc): sonar warning fix
TheoPascoli Jan 30, 2025
1618464
fix(all): remove unused import
TheoPascoli Jan 30, 2025
11821a9
fix(bc): sonar warning fix
TheoPascoli Jan 31, 2025
49adc9d
Merge remote-tracking branch 'origin/dev' into fix/remove-some-deprec…
TheoPascoli Feb 5, 2025
76b10bc
Merge remote-tracking branch 'origin/dev' into fix/remove-some-deprec…
TheoPascoli Feb 5, 2025
957b066
fix(all): refactor deprecated method
TheoPascoli Feb 5, 2025
960eb1b
Merge remote-tracking branch 'origin/dev' into fix/remove-some-deprec…
TheoPascoli Feb 6, 2025
6aa746e
fix(all): refactor deprecated method
TheoPascoli Feb 6, 2025
6b1fdd8
Merge remote-tracking branch 'origin/dev' into fix/remove-some-deprec…
TheoPascoli Feb 6, 2025
2ba8fdf
fix(all): remove unused imports
TheoPascoli Feb 6, 2025
67171b2
Merge remote-tracking branch 'origin/dev' into fix/remove-some-deprec…
TheoPascoli Feb 10, 2025
f58812e
fix(all): remove typing prefix
TheoPascoli Feb 10, 2025
7fd1bb8
fix(all): remove typing prefix
TheoPascoli Feb 10, 2025
b42ca8d
fix(all): remove typing prefix
TheoPascoli Feb 10, 2025
5144742
Merge branch 'dev' into fix/remove-some-deprecated-methods
TheoPascoli Feb 10, 2025
5f2d54b
fix(all): remove typing prefix
TheoPascoli Feb 10, 2025
8a08cc3
Merge remote-tracking branch 'origin/dev' into fix/remove-some-deprec…
TheoPascoli Feb 10, 2025
42aeedb
Merge branch 'dev' into fix/remove-some-deprecated-methods
TheoPascoli Feb 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions antarest/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
# This file is part of the Antares project.

import re
import typing as t
from http import HTTPStatus
from typing import Optional, Sequence

from fastapi.exceptions import HTTPException
from typing_extensions import override
Expand Down Expand Up @@ -337,7 +337,7 @@ def __init__(self) -> None:


class StudyDeletionNotAllowed(HTTPException):
def __init__(self, uuid: str, message: t.Optional[str] = None) -> None:
def __init__(self, uuid: str, message: Optional[str] = None) -> None:
msg = f"Study {uuid} (not managed) is not allowed to be deleted"
if message:
msg += f"\n{message}"
Expand Down Expand Up @@ -384,7 +384,7 @@ class ReferencedObjectDeletionNotAllowed(HTTPException):
other objects: areas, links or thermal clusters.
"""

def __init__(self, object_id: str, binding_ids: t.Sequence[str], *, object_type: str) -> None:
def __init__(self, object_id: str, binding_ids: Sequence[str], *, object_type: str) -> None:
"""
Initialize the exception.
Expand Down
22 changes: 11 additions & 11 deletions antarest/core/filesystem_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import os
import shutil
import stat
import typing as t
from pathlib import Path
from typing import Iterator, Mapping, Sequence, Tuple

import typing_extensions as te
from fastapi import APIRouter, Depends, HTTPException
Expand Down Expand Up @@ -58,7 +58,7 @@ class FilesystemDTO(
"""

name: FilesystemName
mount_dirs: t.Mapping[str, Path] = Field(description="Full path of the mount points in Antares Web Server")
mount_dirs: Mapping[str, Path] = Field(description="Full path of the mount points in Antares Web Server")


class MountPointDTO(
Expand Down Expand Up @@ -203,7 +203,7 @@ async def from_path(cls, full_path: Path, *, details: bool = False) -> "FileInfo
return obj


async def _calc_details(full_path: t.Union[str, Path]) -> t.Tuple[int, int]:
async def _calc_details(full_path: str | Path) -> Tuple[int, int]:
"""Calculate the number of files and the total size of a directory recursively."""

full_path = Path(full_path)
Expand Down Expand Up @@ -271,7 +271,7 @@ def create_file_system_blueprint(config: Config) -> APIRouter:
# Utility functions
# =================

def _get_mount_dirs(fs: str) -> t.Mapping[str, Path]:
def _get_mount_dirs(fs: str) -> Mapping[str, Path]:
try:
return filesystems[fs]
except KeyError:
Expand Down Expand Up @@ -299,9 +299,9 @@ def _get_full_path(mount_dir: Path, path: str) -> Path:
@bp.get(
"",
summary="Get filesystems information",
response_model=t.Sequence[FilesystemDTO],
response_model=Sequence[FilesystemDTO],
)
async def list_filesystems() -> t.Sequence[FilesystemDTO]:
async def list_filesystems() -> Sequence[FilesystemDTO]:
"""
Get the list of filesystems and their mount points.
Expand All @@ -316,9 +316,9 @@ async def list_filesystems() -> t.Sequence[FilesystemDTO]:
@bp.get(
"/{fs}",
summary="Get information of a filesystem",
response_model=t.Sequence[MountPointDTO],
response_model=Sequence[MountPointDTO],
)
async def list_mount_points(fs: FilesystemName) -> t.Sequence[MountPointDTO]:
async def list_mount_points(fs: FilesystemName) -> Sequence[MountPointDTO]:
"""
Get the path and the disk usage of the mount points in a filesystem.
Expand Down Expand Up @@ -373,14 +373,14 @@ async def get_mount_point(fs: FilesystemName, mount: MountPointName) -> MountPoi
@bp.get(
"/{fs}/{mount}/ls",
summary="List files in a mount point",
response_model=t.Sequence[FileInfoDTO],
response_model=Sequence[FileInfoDTO],
)
async def list_files(
fs: FilesystemName,
mount: MountPointName,
path: str = "",
details: bool = False,
) -> t.Sequence[FileInfoDTO]:
) -> Sequence[FileInfoDTO]:
"""
List files and directories in a mount point.
Expand Down Expand Up @@ -532,7 +532,7 @@ async def download_file(

elif full_path.is_file():

def iter_file() -> t.Iterator[bytes]:
def iter_file() -> Iterator[bytes]:
with full_path.open(mode="rb") as file:
yield from file

Expand Down
2 changes: 0 additions & 2 deletions antarest/core/filetransfer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

from typing import Optional

from fastapi import APIRouter, FastAPI

from antarest.core.application import AppBuildContext
from antarest.core.config import Config
from antarest.core.filetransfer.repository import FileDownloadRepository
Expand Down
2 changes: 0 additions & 2 deletions antarest/core/maintenance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

from typing import Optional

from fastapi import APIRouter, FastAPI

from antarest.core.application import AppBuildContext
from antarest.core.config import Config
from antarest.core.interfaces.cache import ICache
Expand Down
4 changes: 2 additions & 2 deletions antarest/core/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# This file is part of the Antares project.

import logging
import typing as t
from typing import Dict, Sequence

from antarest.core.jwt import JWTUser
from antarest.core.model import PermissionInfo, PublicMode, StudyPermissionType
Expand All @@ -20,7 +20,7 @@
logger = logging.getLogger(__name__)


permission_matrix: t.Dict[str, t.Dict[str, t.Sequence[t.Union[RoleType, PublicMode]]]] = {
permission_matrix: Dict[str, Dict[str, Sequence[RoleType | PublicMode]]] = {
StudyPermissionType.READ.value: {
"roles": [
RoleType.ADMIN,
Expand Down
19 changes: 9 additions & 10 deletions antarest/core/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
#
# This file is part of the Antares project.

import typing as t
from collections import OrderedDict
from dataclasses import dataclass
from typing import Any, Generator, Tuple
from typing import Any, Generator, Mapping, MutableMapping, Optional, Tuple

from fastapi import HTTPException
from markupsafe import escape
Expand All @@ -32,27 +31,27 @@
}


class CaseInsensitiveDict(t.MutableMapping[str, t.Any]): # copy of the requests class to avoid importing the package
class CaseInsensitiveDict(MutableMapping[str, Any]): # copy of the requests class to avoid importing the package
def __init__(self, data=None, **kwargs) -> None: # type: ignore
self._store: OrderedDict[str, t.Any] = OrderedDict()
self._store: OrderedDict[str, Any] = OrderedDict()
if data is None:
data = {}
self.update(data, **kwargs)

@override
def __setitem__(self, key: str, value: t.Any) -> None:
def __setitem__(self, key: str, value: Any) -> None:
self._store[key.lower()] = (key, value)

@override
def __getitem__(self, key: str) -> t.Any:
def __getitem__(self, key: str) -> Any:
return self._store[key.lower()][1]

@override
def __delitem__(self, key: str) -> None:
del self._store[key.lower()]

@override
def __iter__(self) -> t.Any:
def __iter__(self) -> Any:
return (casedkey for casedkey, mappedvalue in self._store.values())

@override
Expand All @@ -63,8 +62,8 @@ def lower_items(self) -> Generator[Tuple[Any, Any], Any, None]:
return ((lowerkey, keyval[1]) for (lowerkey, keyval) in self._store.items())

@override
def __eq__(self, other: t.Any) -> bool:
if isinstance(other, t.Mapping):
def __eq__(self, other: Any) -> bool:
if isinstance(other, Mapping):
other = CaseInsensitiveDict(other)
else:
return NotImplemented
Expand All @@ -84,7 +83,7 @@ class RequestParameters:
DTO object to handle data inside request to send to service
"""

user: t.Optional[JWTUser] = None
user: Optional[JWTUser] = None

def get_user_id(self) -> str:
return str(escape(str(self.user.id))) if self.user else "Unknown"
Expand Down
12 changes: 6 additions & 6 deletions antarest/core/serialization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.
import typing as t
from typing import Any, Dict, Optional

import pydantic

ADAPTER: pydantic.TypeAdapter[t.Any] = pydantic.TypeAdapter(
type=t.Any, config=pydantic.config.ConfigDict(ser_json_inf_nan="constants")
ADAPTER: pydantic.TypeAdapter[Any] = pydantic.TypeAdapter(
type=Any, config=pydantic.config.ConfigDict(ser_json_inf_nan="constants")
) # ser_json_inf_nan="constants" means infinity and NaN values will be serialized as `Infinity` and `NaN`.


# These utility functions allow to serialize with pydantic instead of using the built-in python "json" library.
# Since pydantic v2 is written in RUST it's way faster.


def from_json(data: t.Union[str, bytes, bytearray]) -> t.Dict[str, t.Any]:
def from_json(data: str | bytes | bytearray) -> Dict[str, Any]:
return ADAPTER.validate_json(data) # type: ignore


def to_json(data: t.Any, indent: t.Optional[int] = None) -> bytes:
def to_json(data: Any, indent: Optional[int] = None) -> bytes:
return ADAPTER.dump_json(data, indent=indent)


def to_json_string(data: t.Any, indent: t.Optional[int] = None) -> str:
def to_json_string(data: Any, indent: Optional[int] = None) -> str:
return to_json(data, indent=indent).decode("utf-8")


Expand Down
6 changes: 3 additions & 3 deletions antarest/core/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# This file is part of the Antares project.

import typing as t
from typing import Dict, List, Tuple

from fastapi import FastAPI
from fastapi.openapi.models import Example
Expand All @@ -22,7 +22,7 @@
attachment = "User-defined file attachment <br/>"

# noinspection SpellCheckingInspection
urls: t.List[t.Tuple[str, str]] = [
urls: List[Tuple[str, str]] = [
("layers/layers", ""),
("settings/generaldata", ""),
("output/{sim}/about-the-study/parameters", sim),
Expand All @@ -42,7 +42,7 @@
]


def get_path_examples() -> t.Dict[str, Example]:
def get_path_examples() -> Dict[str, Example]:
return {url: {"value": url, "description": des} for url, des in urls}


Expand Down
2 changes: 0 additions & 2 deletions antarest/core/tasks/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

from typing import Optional

from fastapi import APIRouter, FastAPI

from antarest.core.application import AppBuildContext
from antarest.core.config import Config
from antarest.core.interfaces.eventbus import DummyEventBusService, IEventBus
Expand Down
Loading
Loading