|
|
@@ -12,7 +12,6 @@ from types import SimpleNamespace, NoneType
|
|
|
from typing import Annotated, Any, Callable, Iterator, Literal, overload
|
|
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
-from pydantic_core import core_schema
|
|
|
|
|
|
|
|
|
class Status(Enum):
|
|
|
@@ -39,6 +38,7 @@ class Outputs(BaseModel):
|
|
|
@dataclasses.dataclass
|
|
|
class Ref:
|
|
|
"""Annotation class describing a reference into Context or another place"""
|
|
|
+
|
|
|
path: list[Annotated[str, Field(pattern="\\w*(_\\w*)*")]]
|
|
|
|
|
|
def __init__(self, pathstr: str) -> None:
|
|
|
@@ -95,7 +95,7 @@ class Context(SimpleNamespace):
|
|
|
self,
|
|
|
state: BaseModel,
|
|
|
attr: Literal["inputs"],
|
|
|
- extra: dict[str, Any] = {},
|
|
|
+ extra: dict[str, Any] | None = None,
|
|
|
) -> Inputs: ...
|
|
|
|
|
|
@overload
|
|
|
@@ -103,16 +103,19 @@ class Context(SimpleNamespace):
|
|
|
self,
|
|
|
state: BaseModel,
|
|
|
attr: Literal["outputs"],
|
|
|
- extra: dict[str, Any] = {},
|
|
|
+ extra: dict[str, Any] | None = None,
|
|
|
) -> Outputs: ...
|
|
|
|
|
|
def fabricate(
|
|
|
self,
|
|
|
state: BaseModel,
|
|
|
attr: Literal["inputs"] | Literal["outputs"],
|
|
|
- extra: dict[str, Ref | Factory] = {},
|
|
|
+ extra: dict[str, Ref | Factory] | None = None,
|
|
|
) -> Inputs | Outputs:
|
|
|
"""Fabricate and validate an Inputs or Outputs object"""
|
|
|
+ if extra is None:
|
|
|
+ extra = {}
|
|
|
+
|
|
|
model = getattr(state, attr)
|
|
|
if model is None:
|
|
|
annotation = state.__pydantic_fields__[attr].annotation
|
|
|
@@ -171,6 +174,7 @@ class Action(BaseModel, abc.ABC):
|
|
|
level: int = logging.INFO,
|
|
|
**kwargs: Any,
|
|
|
) -> None:
|
|
|
+ """Write a log message describing what this action is doing..."""
|
|
|
logger = logging.getLogger(cls.__name__)
|
|
|
logger.log(level, (" " * indent) + message, *args, **kwargs)
|
|
|
|
|
|
@@ -198,5 +202,6 @@ def _validate(model: BaseModel):
|
|
|
raise TypeError(f"fld '{k}' in {type(model).__qualname__} is unset")
|
|
|
if not isinstance(attr, fld.annotation):
|
|
|
raise TypeError(
|
|
|
- f"field '{k}' in {type(model).__qualname__} is of the wrong type (should be {fld.annotation})"
|
|
|
+ f"field '{k}' in {type(model).__qualname__} is of the wrong type "
|
|
|
+ f"(should be {fld.annotation})"
|
|
|
)
|