From d43d9f93308d55e35d58b9e4e677488adea15593 Mon Sep 17 00:00:00 2001 From: Theo Pascoli Date: Mon, 27 Jan 2025 15:35:12 +0100 Subject: [PATCH] fix: multiple warnings fix --- antarest/core/maintenance/main.py | 2 -- antarest/core/tasks/main.py | 2 -- antarest/eventbus/main.py | 1 - antarest/eventbus/service.py | 1 - antarest/fastapi_jwt_auth/auth_jwt.py | 5 ++++- antarest/front.py | 3 +-- antarest/launcher/main.py | 2 -- antarest/matrixstore/main.py | 2 -- .../study/business/advanced_parameters_management.py | 2 +- antarest/study/business/allocation_management.py | 4 ++-- antarest/study/business/area_management.py | 2 +- antarest/study/business/areas/hydro_management.py | 4 ++-- antarest/study/business/areas/renewable_management.py | 2 +- antarest/study/business/areas/st_storage_management.py | 2 +- antarest/study/business/areas/thermal_management.py | 2 +- antarest/study/business/binding_constraint_management.py | 2 +- antarest/study/business/model/link_model.py | 9 +++++---- antarest/study/business/optimization_management.py | 1 - antarest/study/main.py | 2 -- .../storage/rawstudy/model/filesystem/config/files.py | 8 +------- .../model/filesystem/root/input/hydro/hydro_ini.py | 2 -- antarest/study/storage/rawstudy/watcher.py | 1 - .../storage/variantstudy/variant_command_generator.py | 2 +- antarest/tools/lib.py | 2 +- 24 files changed, 23 insertions(+), 42 deletions(-) diff --git a/antarest/core/maintenance/main.py b/antarest/core/maintenance/main.py index a962d1b013..92fe373304 100644 --- a/antarest/core/maintenance/main.py +++ b/antarest/core/maintenance/main.py @@ -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 diff --git a/antarest/core/tasks/main.py b/antarest/core/tasks/main.py index 92b0929413..41ad8b35cd 100644 --- a/antarest/core/tasks/main.py +++ b/antarest/core/tasks/main.py @@ -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 diff --git a/antarest/eventbus/main.py b/antarest/eventbus/main.py index e1268dc374..6107d770a6 100644 --- a/antarest/eventbus/main.py +++ b/antarest/eventbus/main.py @@ -12,7 +12,6 @@ from typing import Optional -from fastapi import APIRouter, FastAPI from redis import Redis from antarest.core.application import AppBuildContext diff --git a/antarest/eventbus/service.py b/antarest/eventbus/service.py index f414712743..f5f5b38a29 100644 --- a/antarest/eventbus/service.py +++ b/antarest/eventbus/service.py @@ -14,7 +14,6 @@ import logging import random import threading -import time import uuid from typing import Awaitable, Callable, Dict, List, Optional diff --git a/antarest/fastapi_jwt_auth/auth_jwt.py b/antarest/fastapi_jwt_auth/auth_jwt.py index 19fa3173b4..55f226c427 100644 --- a/antarest/fastapi_jwt_auth/auth_jwt.py +++ b/antarest/fastapi_jwt_auth/auth_jwt.py @@ -525,12 +525,15 @@ def _verify_and_get_jwt_in_cookies( if not isinstance(request, (Request, WebSocket)): raise TypeError("request must be an instance of 'Request' or 'WebSocket'") + cookie = None + cookie_key = None + if type_token == "access": cookie_key = self._access_cookie_key cookie = request.cookies.get(cookie_key) if not isinstance(request, WebSocket): csrf_token = request.headers.get(self._access_csrf_header_name) - if type_token == "refresh": + elif type_token == "refresh": cookie_key = self._refresh_cookie_key cookie = request.cookies.get(cookie_key) if not isinstance(request, WebSocket): diff --git a/antarest/front.py b/antarest/front.py index 98f5ab83d8..b8772a82e1 100644 --- a/antarest/front.py +++ b/antarest/front.py @@ -20,9 +20,8 @@ what are the API and websocket prefixes """ -import re from pathlib import Path -from typing import Any, List, Optional, Sequence +from typing import Any, List, Optional from fastapi import FastAPI from starlette.middleware.base import BaseHTTPMiddleware, DispatchFunction, RequestResponseEndpoint diff --git a/antarest/launcher/main.py b/antarest/launcher/main.py index 7f794b9a9c..076253a6ba 100644 --- a/antarest/launcher/main.py +++ b/antarest/launcher/main.py @@ -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.service import FileTransferManager diff --git a/antarest/matrixstore/main.py b/antarest/matrixstore/main.py index 4987e8f8a0..c4a2464341 100644 --- a/antarest/matrixstore/main.py +++ b/antarest/matrixstore/main.py @@ -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.service import FileTransferManager diff --git a/antarest/study/business/advanced_parameters_management.py b/antarest/study/business/advanced_parameters_management.py index 31a8d880e5..0b5c9dc809 100644 --- a/antarest/study/business/advanced_parameters_management.py +++ b/antarest/study/business/advanced_parameters_management.py @@ -240,7 +240,7 @@ def get_value(field_info: FieldInfo) -> Any: parent = seeds return parent.get(target_name, field_info["default_value"]) - return AdvancedParamsFormFields.construct(**{name: get_value(info) for name, info in FIELDS_INFO.items()}) + return AdvancedParamsFormFields.model_construct(**{name: get_value(info) for name, info in FIELDS_INFO.items()}) def set_field_values(self, study: Study, field_values: AdvancedParamsFormFields) -> None: """ diff --git a/antarest/study/business/allocation_management.py b/antarest/study/business/allocation_management.py index eafec7f479..e2cafca773 100644 --- a/antarest/study/business/allocation_management.py +++ b/antarest/study/business/allocation_management.py @@ -210,7 +210,7 @@ def set_allocation_form_fields( updated_allocations = self.get_allocation_data(study, area_id) - return AllocationFormFields.construct( + return AllocationFormFields.model_construct( allocation=[ AllocationField.construct(area_id=area, coefficient=value) for area, value in updated_allocations.items() @@ -250,4 +250,4 @@ def get_allocation_matrix(self, study: Study, all_areas: List[AreaInfoDTO]) -> A col_idx = columns.index(prod_area) array[row_idx][col_idx] = coefficient - return AllocationMatrix.construct(index=rows, columns=columns, data=array.tolist()) + return AllocationMatrix.model_construct(index=rows, columns=columns, data=array.tolist()) diff --git a/antarest/study/business/area_management.py b/antarest/study/business/area_management.py index c607be980d..ea05da37bb 100644 --- a/antarest/study/business/area_management.py +++ b/antarest/study/business/area_management.py @@ -414,7 +414,7 @@ def update_areas_props( @staticmethod def get_table_schema() -> JSON: - return AreaOutput.schema() + return AreaOutput.model_json_schema() def get_all_areas(self, study: RawStudy, area_type: t.Optional[AreaType] = None) -> t.List[AreaInfoDTO]: """ diff --git a/antarest/study/business/areas/hydro_management.py b/antarest/study/business/areas/hydro_management.py index 396d2f785c..436947af3f 100644 --- a/antarest/study/business/areas/hydro_management.py +++ b/antarest/study/business/areas/hydro_management.py @@ -10,9 +10,9 @@ # # This file is part of the Antares project. -from typing import Any, Dict, List, Optional, Union +from typing import Any, Dict, List -from pydantic import Field, model_validator +from pydantic import Field from antarest.study.business.all_optional_meta import all_optional_model from antarest.study.business.utils import FieldInfo, FormFieldsBaseModel, execute_or_add_commands diff --git a/antarest/study/business/areas/renewable_management.py b/antarest/study/business/areas/renewable_management.py index e82a13f3db..88c90048b8 100644 --- a/antarest/study/business/areas/renewable_management.py +++ b/antarest/study/business/areas/renewable_management.py @@ -427,4 +427,4 @@ def update_renewables_props( @staticmethod def get_table_schema() -> JSON: - return RenewableClusterOutput.schema() + return RenewableClusterOutput.model_json_schema() diff --git a/antarest/study/business/areas/st_storage_management.py b/antarest/study/business/areas/st_storage_management.py index ef89e345d8..dceeda6956 100644 --- a/antarest/study/business/areas/st_storage_management.py +++ b/antarest/study/business/areas/st_storage_management.py @@ -718,4 +718,4 @@ def validate_matrix(matrix_type: STStorageTimeSeries) -> STStorageMatrix: @staticmethod def get_table_schema() -> JSON: - return STStorageOutput.schema() + return STStorageOutput.model_json_schema() diff --git a/antarest/study/business/areas/thermal_management.py b/antarest/study/business/areas/thermal_management.py index 90c2420881..c78ab6217f 100644 --- a/antarest/study/business/areas/thermal_management.py +++ b/antarest/study/business/areas/thermal_management.py @@ -282,7 +282,7 @@ def update_thermals_props( @staticmethod def get_table_schema() -> JSON: - return ThermalClusterOutput.schema() + return ThermalClusterOutput.model_json_schema() def create_cluster(self, study: Study, area_id: str, cluster_data: ThermalClusterCreation) -> ThermalClusterOutput: """ diff --git a/antarest/study/business/binding_constraint_management.py b/antarest/study/business/binding_constraint_management.py index fd3970b9b1..e18fcc0564 100644 --- a/antarest/study/business/binding_constraint_management.py +++ b/antarest/study/business/binding_constraint_management.py @@ -1150,7 +1150,7 @@ def remove_constraint_term( @staticmethod def get_table_schema() -> JSON: - return ConstraintOutput870.schema() + return ConstraintOutput870.model_json_schema() def _replace_matrices_according_to_frequency_and_version( diff --git a/antarest/study/business/model/link_model.py b/antarest/study/business/model/link_model.py index 9d6f50e1f5..8bb48af215 100644 --- a/antarest/study/business/model/link_model.py +++ b/antarest/study/business/model/link_model.py @@ -10,6 +10,7 @@ # # This file is part of the Antares project. import typing as t +from dataclasses import field from antares.study.version import StudyVersion from pydantic import BeforeValidator, ConfigDict, Field, PlainSerializer, model_validator @@ -154,8 +155,8 @@ class LinkBaseDTO(AntaresBaseModel): colorg: int = Field(default=DEFAULT_COLOR, ge=0, le=255) link_width: float = 1 link_style: LinkStyle = LinkStyle.PLAIN - filter_synthesis: t.Optional[comma_separated_enum_list] = FILTER_VALUES - filter_year_by_year: t.Optional[comma_separated_enum_list] = FILTER_VALUES + filter_synthesis: t.Optional[comma_separated_enum_list] = field(default_factory=lambda: FILTER_VALUES) + filter_year_by_year: t.Optional[comma_separated_enum_list] = field(default_factory=lambda: FILTER_VALUES) class Area(AntaresBaseModel): @@ -203,8 +204,8 @@ class LinkInternal(AntaresBaseModel): colorg: int = Field(default=DEFAULT_COLOR, ge=0, le=255) link_width: float = 1 link_style: LinkStyle = LinkStyle.PLAIN - filter_synthesis: t.Optional[comma_separated_enum_list] = FILTER_VALUES - filter_year_by_year: t.Optional[comma_separated_enum_list] = FILTER_VALUES + filter_synthesis: t.Optional[comma_separated_enum_list] = field(default_factory=lambda: FILTER_VALUES) + filter_year_by_year: t.Optional[comma_separated_enum_list] = field(default_factory=lambda: FILTER_VALUES) def to_dto(self) -> LinkDTO: data = self.model_dump() diff --git a/antarest/study/business/optimization_management.py b/antarest/study/business/optimization_management.py index bbfa50c767..e6cba79056 100644 --- a/antarest/study/business/optimization_management.py +++ b/antarest/study/business/optimization_management.py @@ -12,7 +12,6 @@ from typing import Any, Dict, List, Union, cast -from antares.study.version import StudyVersion from pydantic.types import StrictBool from antarest.study.business.all_optional_meta import all_optional_model diff --git a/antarest/study/main.py b/antarest/study/main.py index b7ddb9715e..f992157597 100644 --- a/antarest/study/main.py +++ b/antarest/study/main.py @@ -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.service import FileTransferManager diff --git a/antarest/study/storage/rawstudy/model/filesystem/config/files.py b/antarest/study/storage/rawstudy/model/filesystem/config/files.py index 52458c9970..ef5ad34184 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/config/files.py +++ b/antarest/study/storage/rawstudy/model/filesystem/config/files.py @@ -20,17 +20,11 @@ from enum import Enum from pathlib import Path -import py7zr from antares.study.version import StudyVersion from antarest.core.model import JSON from antarest.core.serialization import from_json -from antarest.core.utils.archives import ( - ArchiveFormat, - extract_lines_from_archive, - is_archive_format, - read_file_from_archive, -) +from antarest.core.utils.archives import extract_lines_from_archive, is_archive_format, read_file_from_archive from antarest.study.model import STUDY_VERSION_8_1, STUDY_VERSION_8_6 from antarest.study.storage.rawstudy.ini_reader import IniReader from antarest.study.storage.rawstudy.model.filesystem.config.binding_constraint import ( diff --git a/antarest/study/storage/rawstudy/model/filesystem/root/input/hydro/hydro_ini.py b/antarest/study/storage/rawstudy/model/filesystem/root/input/hydro/hydro_ini.py index 02b5c7d62c..55697312af 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/root/input/hydro/hydro_ini.py +++ b/antarest/study/storage/rawstudy/model/filesystem/root/input/hydro/hydro_ini.py @@ -10,8 +10,6 @@ # # This file is part of the Antares project. -from antares.study.version import StudyVersion - from antarest.study.model import STUDY_VERSION_6_5 from antarest.study.storage.rawstudy.model.filesystem.config.model import FileStudyTreeConfig from antarest.study.storage.rawstudy.model.filesystem.context import ContextServer diff --git a/antarest/study/storage/rawstudy/watcher.py b/antarest/study/storage/rawstudy/watcher.py index 40a08f47a4..5a654948f5 100644 --- a/antarest/study/storage/rawstudy/watcher.py +++ b/antarest/study/storage/rawstudy/watcher.py @@ -11,7 +11,6 @@ # This file is part of the Antares project. import logging -import re import tempfile from html import escape from pathlib import Path diff --git a/antarest/study/storage/variantstudy/variant_command_generator.py b/antarest/study/storage/variantstudy/variant_command_generator.py index 42113ead14..d30b77ece0 100644 --- a/antarest/study/storage/variantstudy/variant_command_generator.py +++ b/antarest/study/storage/variantstudy/variant_command_generator.py @@ -14,7 +14,7 @@ import shutil import uuid from pathlib import Path -from typing import Any, Callable, List, Optional, Tuple, Union, cast +from typing import Callable, List, Optional, Tuple, Union, cast from antarest.core.utils.utils import StopWatch from antarest.study.storage.rawstudy.model.filesystem.config.model import FileStudyTreeConfig diff --git a/antarest/tools/lib.py b/antarest/tools/lib.py index 85b1c6c19c..ad54534760 100644 --- a/antarest/tools/lib.py +++ b/antarest/tools/lib.py @@ -39,7 +39,7 @@ from antarest.study.storage.variantstudy.business.matrix_constants_generator import GeneratorMatrixConstants from antarest.study.storage.variantstudy.command_factory import CommandFactory from antarest.study.storage.variantstudy.model.command.icommand import ICommand -from antarest.study.storage.variantstudy.model.model import CommandDTO, CommandDTOAPI, GenerationResultInfoDTO +from antarest.study.storage.variantstudy.model.model import CommandDTO, GenerationResultInfoDTO from antarest.study.storage.variantstudy.variant_command_extractor import VariantCommandsExtractor from antarest.study.storage.variantstudy.variant_command_generator import VariantCommandGenerator