diff --git a/dffml/df/base.py b/dffml/df/base.py index fa6327968a..5dd42d316f 100644 --- a/dffml/df/base.py +++ b/dffml/df/base.py @@ -13,7 +13,7 @@ Optional, Set, ) -from dataclasses import is_dataclass +from dataclasses import dataclass, is_dataclass, replace from contextlib import asynccontextmanager from .exceptions import NotOpImp @@ -988,13 +988,17 @@ class OperationException(Exception): """ -class BaseOrchestratorConfig(BaseConfig, NamedTuple): +@dataclass(frozen=True) +class BaseOrchestratorConfig: input_network: BaseInputNetwork operation_network: BaseOperationNetwork lock_network: BaseLockNetwork opimp_network: BaseOperationImplementationNetwork rchecker: BaseRedundancyChecker + def _replace(self, **kwargs): + return replace(self, **kwargs) + class BaseOrchestratorContext(BaseDataFlowObjectContext): @abc.abstractmethod diff --git a/dffml/df/types.py b/dffml/df/types.py index 6ae8534f30..6e4123e2c5 100644 --- a/dffml/df/types.py +++ b/dffml/df/types.py @@ -3,7 +3,7 @@ import itertools import pkg_resources from enum import Enum -from dataclasses import dataclass, field, asdict +from dataclasses import dataclass, field, asdict, replace from typing import ( NamedTuple, Union, @@ -167,18 +167,22 @@ class FailedToLoadOperation(Exception): """ +@dataclass(frozen=True) @base_entry_point("dffml.operation", "operation") -class Operation(NamedTuple, Entrypoint): +class Operation(Entrypoint): name: str - inputs: Dict[str, Definition] = {} - outputs: Dict[str, Definition] = {} + inputs: Dict[str, Definition] = field(default_factory=lambda: {}) + outputs: Dict[str, Definition] = field(default_factory=lambda: {}) stage: Stage = Stage.PROCESSING - conditions: Optional[List[Definition]] = [] - expand: Optional[List[str]] = [] + conditions: Optional[List[Definition]] = field(default_factory=lambda: []) + expand: Optional[List[str]] = field(default_factory=lambda: []) instance_name: Optional[str] = None validator: bool = False retry: int = 0 + def _replace(self, **kwargs): + return replace(self, **kwargs) + def export(self): exported = { "name": self.name,