Skip to content

Commit

Permalink
IO maps (#559)
Browse files Browse the repository at this point in the history
* Refactor Workflow map setter

Signed-off-by: liamhuber <[email protected]>

* Remove return hint

The method is in-place

Signed-off-by: liamhuber <[email protected]>

* Move the None check around

Signed-off-by: liamhuber <[email protected]>

---------

Signed-off-by: liamhuber <[email protected]>
  • Loading branch information
liamhuber authored Jan 17, 2025
1 parent 44d68b2 commit b09d0ef
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions pyiron_workflow/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,8 @@ def __init__(
automate_execution: bool = True,
**kwargs,
):
self._inputs_map = None
self._outputs_map = None
self.inputs_map = inputs_map
self.outputs_map = outputs_map
self._inputs_map = self._sanitize_map(inputs_map)
self._outputs_map = self._sanitize_map(outputs_map)
self._inputs = None
self._outputs = None
self.automate_execution: bool = automate_execution
Expand Down Expand Up @@ -264,34 +262,36 @@ def _after_node_setup(

@property
def inputs_map(self) -> bidict | None:
self._deduplicate_nones(self._inputs_map)
if self._inputs_map is not None:
self._deduplicate_nones(self._inputs_map)
return self._inputs_map

@inputs_map.setter
def inputs_map(self, new_map: dict | bidict | None):
self._deduplicate_nones(new_map)
if new_map is not None:
new_map = bidict(new_map)
self._inputs_map = new_map
self._inputs_map = self._sanitize_map(new_map)

@property
def outputs_map(self) -> bidict | None:
self._deduplicate_nones(self._outputs_map)
if self._outputs_map is not None:
self._deduplicate_nones(self._outputs_map)
return self._outputs_map

@outputs_map.setter
def outputs_map(self, new_map: dict | bidict | None):
self._deduplicate_nones(new_map)
self._outputs_map = self._sanitize_map(new_map)

def _sanitize_map(self, new_map: dict | bidict | None) -> bidict | None:
if new_map is not None:
if isinstance(new_map, dict):
self._deduplicate_nones(new_map)
new_map = bidict(new_map)
self._outputs_map = new_map
return new_map

@staticmethod
def _deduplicate_nones(some_map: dict | bidict | None) -> dict | bidict | None:
if some_map is not None:
for k, v in some_map.items():
if v is None:
some_map[k] = (None, f"{k} disabled")
def _deduplicate_nones(some_map: dict | bidict):
for k, v in some_map.items():
if v is None:
some_map[k] = (None, f"{k} disabled")

@property
def inputs(self) -> Inputs:
Expand Down

0 comments on commit b09d0ef

Please sign in to comment.