Skip to content

Commit b91f804

Browse files
authored
Added type hint to all submodel attributes (#424)
* Added type hint to all submodel attributes * Updated CHANGELOG.md * Fix type hints to include None
1 parent 3b4809a commit b91f804

8 files changed

Lines changed: 26 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ If upgrading from v2.x, see the [v3.0.0 release notes](https://github.com/flixOp
7474
### 📝 Docs
7575
7676
### 👷 Development
77+
- Added type hints for submodel in all Interface classes
7778
7879
### 🚧 Known Issues
7980

flixopt/calculation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class for defined way of solving a flow_system optimization
5353
active_timesteps: Deprecated. Use FlowSystem.sel(time=...) or FlowSystem.isel(time=...) instead.
5454
"""
5555

56+
model: FlowSystemModel | None
57+
5658
def __init__(
5759
self,
5860
name: str,
@@ -87,7 +89,7 @@ def __init__(
8789
flow_system._used_in_calculation = True
8890

8991
self.flow_system = flow_system
90-
self.model: FlowSystemModel | None = None
92+
self.model = None
9193

9294
self.durations = {'modeling': 0.0, 'solving': 0.0, 'saving': 0.0}
9395
self.folder = pathlib.Path.cwd() / 'results' if folder is None else pathlib.Path(folder)

flixopt/components.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ class LinearConverter(Component):
161161
162162
"""
163163

164+
submodel: LinearConverterModel | None
165+
164166
def __init__(
165167
self,
166168
label: str,
@@ -377,6 +379,8 @@ class Storage(Component):
377379
With flow rates in m3/h, the charge state is therefore in m3.
378380
"""
379381

382+
submodel: StorageModel | None
383+
380384
def __init__(
381385
self,
382386
label: str,
@@ -650,6 +654,8 @@ class Transmission(Component):
650654
651655
"""
652656

657+
submodel: TransmissionModel | None
658+
653659
def __init__(
654660
self,
655661
label: str,

flixopt/effects.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ class Effect(Element):
160160
161161
"""
162162

163+
submodel: EffectModel | None
164+
163165
def __init__(
164166
self,
165167
label: str,
@@ -454,12 +456,14 @@ class EffectCollection(ElementContainer[Effect]):
454456
Handling all Effects
455457
"""
456458

459+
submodel: EffectCollectionModel | None
460+
457461
def __init__(self, *effects: Effect):
458462
super().__init__(element_type_name='effects')
459463
self._standard_effect: Effect | None = None
460464
self._objective_effect: Effect | None = None
461465

462-
self.submodel: EffectCollectionModel | None = None
466+
self.submodel = None
463467
self.add_effects(*effects)
464468

465469
def create_model(self, model: FlowSystemModel) -> EffectCollectionModel:

flixopt/elements.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ class Bus(Element):
223223
by the FlowSystem during system setup.
224224
"""
225225

226+
submodel: BusModel | None
227+
226228
def __init__(
227229
self,
228230
label: str,
@@ -411,6 +413,8 @@ class Flow(Element):
411413
412414
"""
413415

416+
submodel: FlowModel | None
417+
414418
def __init__(
415419
self,
416420
label: str,

flixopt/flow_system.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ class FlowSystem(Interface, CompositeContainerMixin[Element]):
143143
connected_and_transformed automatically when trying to solve a calculation.
144144
"""
145145

146+
model: FlowSystemModel | None
147+
146148
def __init__(
147149
self,
148150
timesteps: pd.DatetimeIndex,

flixopt/results.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ class CalculationResults(CompositeContainerMixin['ComponentResults | BusResults
148148
149149
"""
150150

151+
model: linopy.Model | None
152+
151153
@classmethod
152154
def from_file(cls, folder: str | pathlib.Path, name: str) -> CalculationResults:
153155
"""Load CalculationResults from saved files.

flixopt/structure.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,8 @@ def __deepcopy__(self, memo):
850850
class Element(Interface):
851851
"""This class is the basic Element of flixopt. Every Element has a label"""
852852

853+
submodel: ElementModel | None
854+
853855
def __init__(self, label: str, meta_data: dict | None = None):
854856
"""
855857
Args:
@@ -858,7 +860,7 @@ def __init__(self, label: str, meta_data: dict | None = None):
858860
"""
859861
self.label = Element._valid_label(label)
860862
self.meta_data = meta_data if meta_data is not None else {}
861-
self.submodel: ElementModel | None = None
863+
self.submodel = None
862864

863865
def _plausibility_checks(self) -> None:
864866
"""This function is used to do some basic plausibility checks for each Element during initialization.

0 commit comments

Comments
 (0)