Skip to content

Commit c4b8f43

Browse files
authored
Fix pipeline seal checking
1 parent 04de6ea commit c4b8f43

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

pcs/pipeline.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
import inspect
22
from collections.abc import Mapping
3-
from typing import Callable, TypeAlias
3+
from typing import Callable, TypeAlias, TypeVar
44

55
from pcs.component import Component
66

77
System: TypeAlias = Callable[..., None | Mapping[str, object]]
88

9+
T = TypeVar("T")
10+
911

1012
class Pipeline:
1113
def __init__(
1214
self,
13-
component: Component,
15+
component: Component[T],
1416
systems: list[System],
1517
do_null_checks: bool = True,
1618
do_seal_check: bool = True,
1719
):
1820
assert len(systems) > 0, "Systems in an empty list"
19-
if do_seal_check:
20-
assert component.is_sealed(), "You need to call seal on the component object to make the config objects static, or otherwise set `do_seal_check` to false for this pipeline"
2121
self.component = component
2222
self.systems = systems
2323
self.do_null_checks = do_null_checks
2424
self.current_system = systems[0]
25+
self.do_seal_check = do_seal_check
2526

2627
def execute(self) -> None:
28+
if self.do_seal_check:
29+
assert self.component.is_sealed(), (
30+
"You need to call seal on the component object to make the config objects static, or otherwise set `do_seal_check` to false for this pipeline"
31+
)
2732
for system in self.systems:
2833
self.current_system = system
2934
self.check_for_nulls(system)
@@ -39,9 +44,9 @@ def check_for_nulls(self, system: System) -> None:
3944
if not self.do_null_checks:
4045
return
4146
for parameter in inspect.signature(system).parameters:
42-
assert (
43-
getattr(self.component, parameter) is not None
44-
), f"System: {system.__name__} - Parameter {parameter} was None"
47+
assert getattr(self.component, parameter) is not None, (
48+
f"System: {system.__name__} - Parameter {parameter} was None"
49+
)
4550

4651
def set_component(self, result: None | Mapping[str, object]) -> None:
4752
if result is None:

0 commit comments

Comments
 (0)