Skip to content

Commit

Permalink
fix: wip mypy errors (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdiwahada committed Feb 4, 2025
1 parent 9844a46 commit 573095a
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 25 deletions.
19 changes: 12 additions & 7 deletions src/antares/craft/model/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@
from antares.craft.model.renewable import RenewableCluster, RenewableClusterProperties
from antares.craft.model.st_storage import STStorage, STStorageProperties
from antares.craft.model.thermal import ThermalCluster, ThermalClusterProperties
from antares.craft.service.base_services import BaseThermalService, BaseAreaService, BaseShortTermStorageService, \
BaseRenewableService, BaseHydroService
from antares.craft.service.base_services import (
BaseAreaService,
BaseHydroService,
BaseRenewableService,
BaseShortTermStorageService,
BaseThermalService,
)
from antares.craft.tools.alias_generators import to_space
from antares.craft.tools.all_optional_meta import all_optional_model
from antares.craft.tools.contents_tool import EnumIgnoreCase, transform_name_to_id
Expand Down Expand Up @@ -191,14 +196,14 @@ def yield_area_ui(self) -> AreaUi:


class Area:
def __init__( # TODO: Find a way to avoid circular imports
def __init__( # TODO: Find a way to avoid circular imports
self,
name: str,
area_service: BaseAreaService,
storage_service: Optional[BaseShortTermStorageService],
thermal_service: Optional[BaseThermalService],
renewable_service: Optional[BaseRenewableService],
hydro_service: Optional[BaseHydroService],
storage_service: BaseShortTermStorageService,
thermal_service: BaseThermalService,
renewable_service: BaseRenewableService,
hydro_service: BaseHydroService,
*,
renewables: Optional[Dict[str, RenewableCluster]] = None,
thermals: Optional[Dict[str, ThermalCluster]] = None,
Expand Down
5 changes: 3 additions & 2 deletions src/antares/craft/model/binding_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import pandas as pd

from antares.craft.service.base_services import BaseBindingConstraintService
from antares.craft.tools.all_optional_meta import all_optional_model
from antares.craft.tools.contents_tool import EnumIgnoreCase, transform_name_to_id
from pydantic import BaseModel, Field, model_validator
Expand Down Expand Up @@ -120,10 +121,10 @@ class BindingConstraintProperties(DefaultBindingConstraintProperties):


class BindingConstraint:
def __init__( # TODO: Find a way to avoid circular imports
def __init__( # TODO: Find a way to avoid circular imports
self,
name: str,
binding_constraint_service,
binding_constraint_service: BaseBindingConstraintService,
properties: Optional[BindingConstraintProperties] = None,
terms: Optional[List[ConstraintTerm]] = None,
):
Expand Down
5 changes: 3 additions & 2 deletions src/antares/craft/model/hydro.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import pandas as pd

from antares.craft.service.base_services import BaseHydroService
from antares.craft.tools.all_optional_meta import all_optional_model
from pydantic import BaseModel
from pydantic.alias_generators import to_camel
Expand Down Expand Up @@ -90,9 +91,9 @@ def yield_hydro_properties(self) -> HydroProperties:


class Hydro:
def __init__( #
def __init__( #
self,
service,
service: BaseHydroService,
area_id: str,
properties: Optional[HydroProperties] = None,
matrices: Optional[Dict[HydroMatrixName, pd.DataFrame]] = None,
Expand Down
5 changes: 3 additions & 2 deletions src/antares/craft/model/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import pandas as pd

from antares.craft.model.commons import FilterOption, sort_filter_values
from antares.craft.service.base_services import BaseLinkService
from antares.craft.tools.alias_generators import to_kebab
from antares.craft.tools.all_optional_meta import all_optional_model
from antares.craft.tools.contents_tool import transform_name_to_id
Expand Down Expand Up @@ -133,11 +134,11 @@ def yield_link_ui(self) -> LinkUi:


class Link:
def __init__( # TODO: Find a way to avoid circular imports
def __init__( # TODO: Find a way to avoid circular imports
self,
area_from: str,
area_to: str,
link_service,
link_service: BaseLinkService,
properties: Optional[LinkProperties] = None,
ui: Optional[LinkUi] = None,
):
Expand Down
3 changes: 1 addition & 2 deletions src/antares/craft/model/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@

import pandas as pd

from pydantic import BaseModel

from antares.craft.service.base_services import BaseOutputService
from pydantic import BaseModel


class MCIndAreas(Enum):
Expand Down
5 changes: 3 additions & 2 deletions src/antares/craft/model/renewable.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import pandas as pd

from antares.craft.model.cluster import ClusterProperties
from antares.craft.service.base_services import BaseRenewableService
from antares.craft.tools.all_optional_meta import all_optional_model
from antares.craft.tools.contents_tool import transform_name_to_id

Expand Down Expand Up @@ -90,9 +91,9 @@ def yield_renewable_cluster_properties(self) -> RenewableClusterProperties:


class RenewableCluster:
def __init__( # TODO: Find a way to avoid circular imports
def __init__( # TODO: Find a way to avoid circular imports
self,
renewable_service,
renewable_service: BaseRenewableService,
area_id: str,
name: str,
properties: Optional[RenewableClusterProperties] = None,
Expand Down
1 change: 1 addition & 0 deletions src/antares/craft/model/settings/adequacy_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class DefaultAdequacyPatchParameters(BaseModel, populate_by_name=True, alias_gen
class AdequacyPatchParameters(DefaultAdequacyPatchParameters):
pass


# TODO : généraliser les attributs communs aux paramètres et faire une classe générique
class AdequacyPatchParametersLocal(DefaultAdequacyPatchParameters):
@property
Expand Down
1 change: 1 addition & 0 deletions src/antares/craft/model/settings/advanced_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class RenewableGenerationModeling(Enum):
AGGREGATED = "aggregated"
CLUSTERS = "clusters"


# TODO : généraliser les attributs communs aux paramètres et faire une classe générique
class DefaultAdvancedParameters(BaseModel, alias_generator=to_camel):
model_config = ConfigDict(use_enum_values=True)
Expand Down
1 change: 1 addition & 0 deletions src/antares/craft/model/settings/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class OutputFormat(EnumIgnoreCase):
TXT = "txt-files"
ZIP = "zip-files"


# TODO : généraliser les attributs communs aux paramètres et faire une classe générique
class DefaultGeneralParameters(BaseModel, extra="forbid", populate_by_name=True, alias_generator=to_camel):
model_config = ConfigDict(use_enum_values=True)
Expand Down
1 change: 1 addition & 0 deletions src/antares/craft/model/settings/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ExportMPS(Enum):
BOTH_OPTIMS = "both-optims"
TRUE = True


# TODO : généraliser les attributs communs aux paramètres et faire une classe générique
class DefaultOptimizationParameters(BaseModel, alias_generator=to_camel):
model_config = ConfigDict(use_enum_values=True)
Expand Down
1 change: 1 addition & 0 deletions src/antares/craft/model/settings/playlist_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class PlaylistData(BaseModel):
status: bool = True
weight: float = 1.0


# TODO : généraliser les attributs communs aux paramètres et faire une classe générique
class PlaylistParameters(BaseModel):
"""
Expand Down
1 change: 1 addition & 0 deletions src/antares/craft/model/settings/thematic_trimming.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pydantic import BaseModel
from pydantic.alias_generators import to_camel


# TODO : généraliser les attributs communs aux paramètres et faire une classe générique
class DefaultThematicTrimmingParameters(BaseModel, alias_generator=to_camel):
"""
Expand Down
1 change: 1 addition & 0 deletions src/antares/craft/model/settings/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SeasonCorrelation(Enum):
MONTHLY = "monthly"
ANNUAL = "annual"


# TODO : généraliser les attributs communs aux paramètres et faire une classe générique
class _DefaultParameters(BaseModel, alias_generator=to_camel):
stochastic_ts_status: bool = False
Expand Down
10 changes: 9 additions & 1 deletion src/antares/craft/model/st_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import pandas as pd

from antares.craft.service.base_services import BaseShortTermStorageService
from antares.craft.tools.all_optional_meta import all_optional_model
from antares.craft.tools.contents_tool import transform_name_to_id
from pydantic import BaseModel
Expand Down Expand Up @@ -90,9 +91,16 @@ def yield_st_storage_properties(self) -> STStorageProperties:


class STStorage:
def __init__(self, storage_service: BaseShortTermService, area_id: str, name: str, properties: Optional[STStorageProperties] = None): # type: ignore # TODO: Find a way to avoid circular imports
def __init__(
self,
storage_service: BaseShortTermStorageService,
area_id: str,
name: str,
properties: Optional[STStorageProperties] = None,
): # TODO: Find a way to avoid circular imports
self._area_id = area_id
self._storage_service = storage_service
self._storage_service = storage_service
self._name = name
self._id = transform_name_to_id(name)
self._properties = properties or STStorageProperties()
Expand Down
9 changes: 8 additions & 1 deletion src/antares/craft/model/thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import pandas as pd

from antares.craft.model.cluster import ClusterProperties
from antares.craft.service.base_services import BaseThermalService
from antares.craft.tools.all_optional_meta import all_optional_model
from antares.craft.tools.contents_tool import transform_name_to_id

Expand Down Expand Up @@ -171,7 +172,13 @@ class ThermalClusterMatrixName(Enum):


class ThermalCluster:
def __init__(self, thermal_service, area_id: str, name: str, properties: Optional[ThermalClusterProperties] = None): # type: ignore # TODO: Find a way to avoid circular imports
def __init__(
self,
thermal_service: BaseThermalService,
area_id: str,
name: str,
properties: Optional[ThermalClusterProperties] = None,
): # TODO: Find a way to avoid circular imports
self._area_id = area_id
self._thermal_service = thermal_service
self._name = name
Expand Down
4 changes: 2 additions & 2 deletions src/antares/craft/service/api_services/run_api.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 time

from typing import Any, Optional
from typing import Any, Optional, cast

from antares.craft.api_conf.api_conf import APIconf
from antares.craft.api_conf.request_wrapper import RequestWrapper
Expand Down Expand Up @@ -103,5 +103,5 @@ def _get_unarchiving_task_id(self, job: Job, tasks: list[dict[str, Any]]) -> str
task_name = task["name"]
output_id = task_name.split("/")[-1].split(" ")[0]
if output_id == job.output_id:
return task["id"]
return cast(str, task["id"])
raise AntaresSimulationUnzipError(self.study_id, job.job_id, "Could not find task for unarchiving job")
10 changes: 9 additions & 1 deletion src/antares/craft/service/base_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from antares.craft.model.renewable import RenewableCluster, RenewableClusterProperties
from antares.craft.model.settings.study_settings import StudySettings
from antares.craft.model.simulation import AntaresSimulationParameters, Job
from antares.craft.model.st_storage import STStorage, STStorageProperties
from antares.craft.model.st_storage import STStorage, STStorageMatrixName, STStorageProperties
from antares.craft.model.thermal import ThermalCluster, ThermalClusterMatrixName, ThermalClusterProperties

if TYPE_CHECKING:
Expand Down Expand Up @@ -681,6 +681,14 @@ def update_st_storage_properties(
def read_st_storages(self, area_id: str) -> List[STStorage]:
pass

@abstractmethod
def get_storage_matrix(self, storage: STStorage, ts_name: STStorageMatrixName) -> pd.DataFrame:
pass

@abstractmethod
def upload_storage_matrix(self, storage: STStorage, ts_name: STStorageMatrixName, matrix: pd.DataFrame) -> None:
pass


class BaseRunService(ABC):
@abstractmethod
Expand Down
10 changes: 9 additions & 1 deletion src/antares/craft/service/local_services/st_storage_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

from typing import Any, List

import pandas as pd

from antares.craft.config.local_configuration import LocalConfiguration
from antares.craft.model.st_storage import STStorage, STStorageProperties
from antares.craft.model.st_storage import STStorage, STStorageProperties, STStorageMatrixName
from antares.craft.service.base_services import BaseShortTermStorageService


Expand All @@ -30,3 +32,9 @@ def update_st_storage_properties(

def read_st_storages(self, area_id: str) -> List[STStorage]:
raise NotImplementedError

def upload_storage_matrix(self, storage: STStorage, ts_name: STStorageMatrixName, matrix: pd.DataFrame) -> None:
raise NotImplementedError

def get_storage_matrix(self, storage: STStorage, ts_name: STStorageMatrixName) -> pd.DataFrame:
raise NotImplementedError
6 changes: 4 additions & 2 deletions src/antares/craft/tools/custom_raw_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ def __init__(self, special_keys: Optional[list[str]] = None, **kwargs: Any) -> N
def optionxform(self, optionstr: str) -> str:
return optionstr

def _write_line(self, file_path: "SupportsWrite", section_name: str, delimiter: str, key: str, value: str) -> None:
def _write_line(
self, file_path: "SupportsWrite[str]", section_name: str, delimiter: str, key: str, value: str
) -> None:
"""Writes a single line of the provided section to the specified `file_path`."""
value = self._interpolation.before_write(self, section_name, key, value)
if value is not None or not self._allow_no_value: # type:ignore
if value is not None or not self._allow_no_value:
value = delimiter + str(value).replace("\n", "\n\t")
else:
value = ""
Expand Down

0 comments on commit 573095a

Please sign in to comment.