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(mypy): enforce strict typing check #62

Merged
merged 14 commits into from
Feb 10, 2025
Merged

fix(mypy): enforce strict typing check #62

merged 14 commits into from
Feb 10, 2025

Conversation

sylvlecl
Copy link
Member

To be actually implemented

@salemsd salemsd force-pushed the fix/mypy-strict branch 2 times, most recently from 3087917 to 74232bc Compare February 7, 2025 14:48
@@ -253,7 +253,7 @@ def create_thermal_cluster(
) -> ThermalCluster:
thermal = self._area_service.create_thermal_cluster(self.id, thermal_name, properties)
self._thermals[thermal.id] = thermal
return thermal
return cast(ThermalCluster, thermal)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible it would be better to do: thermal: ThermalCluster = IMO

src/antares/craft/model/study.py Show resolved Hide resolved
@@ -85,6 +85,9 @@ def create_variant(self, variant_name: str) -> "Study":
raise StudyVariantCreationError(self.study_id, e.message) from e

def read_outputs(self) -> list[Output]:
if not isinstance(self.output_service, BaseOutputService):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what we should do instead is instanciating the studyService with the output service. By doing so, we could also remove the set_output_service method

Copy link
Contributor

@MartinBelthle MartinBelthle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice that the import trick works :)

@@ -189,18 +196,18 @@ def yield_area_ui(self) -> AreaUi:


class Area:
def __init__( # type: ignore # TODO: Find a way to avoid circular imports
def __init__( # TODO: Find a way to avoid circular imports
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this TODO

@@ -251,7 +258,7 @@ def ui(self) -> AreaUi:
def create_thermal_cluster(
self, thermal_name: str, properties: Optional[ThermalClusterProperties] = None
) -> ThermalCluster:
thermal = self._area_service.create_thermal_cluster(self.id, thermal_name, properties)
thermal: ThermalCluster = self._area_service.create_thermal_cluster(self.id, thermal_name, properties)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to type anymore I believe

@@ -120,12 +121,12 @@ class BindingConstraintProperties(DefaultBindingConstraintProperties):


class BindingConstraint:
def __init__( # type: ignore # TODO: Find a way to avoid circular imports
def __init__( # TODO: Find a way to avoid circular imports
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@@ -133,11 +134,11 @@ def yield_link_ui(self) -> LinkUi:


class Link:
def __init__( # type: ignore # TODO: Find a way to avoid circular imports
def __init__( # TODO: Find a way to avoid circular imports
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

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


class RenewableCluster:
def __init__( # type: ignore # TODO: Find a way to avoid circular imports
def __init__( # TODO: Find a way to avoid circular imports
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

area_id: str,
name: str,
properties: Optional[STStorageProperties] = None,
): # TODO: Find a way to avoid circular imports
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

src/antares/craft/model/study.py Show resolved Hide resolved
area_id: str,
name: str,
properties: Optional[ThermalClusterProperties] = None,
): # TODO: Find a way to avoid circular imports
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@@ -39,30 +39,42 @@ def get_renewable_matrix(self, cluster_id: str, area_id: str) -> pd.DataFrame:
TimeSeriesFileType.RENEWABLE_DATA_SERIES, self.config.study_path, area_id=area_id, cluster_id=cluster_id
)

def read_renewables(self, area_id: str) -> List[RenewableCluster]:
def _extract_renewable_properties(self, renewable_data: dict[str, Any]) -> RenewableClusterProperties:
# get_type_hints will yield a dict with every property with every local property as key and its type as the value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove a with every: will yield a dict with every local property as keys and their types as values

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we don't care as this code will probably disappear soon

# for each property in renewable_data, we will type it according to property_types while making sure it's not None
# because it's Optional. If it's "name" then we get its mapping from the property_mapping dict
parsed_data = {
property_mapping.get(property, property): property_types[property_mapping.get(property, property)](value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we'll refactor the classes we won't have to do this so it's okay for me

@MartinBelthle MartinBelthle marked this pull request as ready for review February 10, 2025 14:46
@MartinBelthle MartinBelthle merged commit 05bacae into main Feb 10, 2025
8 checks passed
@MartinBelthle MartinBelthle deleted the fix/mypy-strict branch February 10, 2025 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants