-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
3087917
to
74232bc
Compare
Signed-off-by: Sylvain Leclerc <[email protected]>
74232bc
to
19b1fde
Compare
src/antares/craft/model/area.py
Outdated
@@ -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) |
There was a problem hiding this comment.
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
@@ -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): |
There was a problem hiding this comment.
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
There was a problem hiding this 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 :)
src/antares/craft/model/area.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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
src/antares/craft/model/area.py
Outdated
@@ -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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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/link.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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/renewable.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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/thermal.py
Outdated
area_id: str, | ||
name: str, | ||
properties: Optional[ThermalClusterProperties] = None, | ||
): # TODO: Find a way to avoid circular imports |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
To be actually implemented