diff --git a/pyagentspec/src/pyagentspec/component.py b/pyagentspec/src/pyagentspec/component.py index a9381c68..4e7f5499 100644 --- a/pyagentspec/src/pyagentspec/component.py +++ b/pyagentspec/src/pyagentspec/component.py @@ -519,11 +519,11 @@ def build_from_partial_config( partial_component, validation_errors = deserializer.from_partial_dict(partial_config) # Deserialization ignores min and max agentspec versions (besides validation), so we set them manually if "min_agentspec_version" in partial_config: - partial_component.min_agentspec_version = AgentSpecVersionEnum( # type: ignore + partial_component.min_agentspec_version = AgentSpecVersionEnum( partial_config["min_agentspec_version"] ) if "max_agentspec_version" in partial_config: - partial_component.max_agentspec_version = AgentSpecVersionEnum( # type: ignore + partial_component.max_agentspec_version = AgentSpecVersionEnum( partial_config["max_agentspec_version"] ) return cast(ComponentT, partial_component) diff --git a/pyagentspec/src/pyagentspec/serialization/deserializer.py b/pyagentspec/src/pyagentspec/serialization/deserializer.py index 314334f2..81200efd 100644 --- a/pyagentspec/src/pyagentspec/serialization/deserializer.py +++ b/pyagentspec/src/pyagentspec/serialization/deserializer.py @@ -253,7 +253,7 @@ def from_dict(self, dict_content: ComponentAsDictT) -> Component: ... def from_dict( self, dict_content: ComponentAsDictT, - components_registry: Optional[ComponentsRegistryT], + components_registry: ComponentsRegistryT | None, ) -> Component: ... @overload @@ -270,7 +270,7 @@ def from_dict( dict_content: ComponentAsDictT, *, import_only_referenced_components: Literal[True], - ) -> Dict[str, Component]: ... + ) -> dict[str, Component]: ... @overload def from_dict( @@ -278,13 +278,13 @@ def from_dict( dict_content: ComponentAsDictT, *, import_only_referenced_components: bool, - ) -> Union[Component, Dict[str, Component]]: ... + ) -> Component | dict[str, Component]: ... @overload def from_dict( self, dict_content: ComponentAsDictT, - components_registry: Optional[ComponentsRegistryT], + components_registry: ComponentsRegistryT | None, import_only_referenced_components: Literal[False], ) -> Component: ... @@ -292,9 +292,9 @@ def from_dict( def from_dict( self, dict_content: ComponentAsDictT, - components_registry: Optional[ComponentsRegistryT], + components_registry: ComponentsRegistryT | None, import_only_referenced_components: Literal[True], - ) -> Dict[str, Component]: ... + ) -> dict[str, Component]: ... @overload def from_dict( @@ -302,14 +302,14 @@ def from_dict( dict_content: ComponentAsDictT, components_registry: Optional[ComponentsRegistryT], import_only_referenced_components: bool, - ) -> Union[Component, Dict[str, Component]]: ... + ) -> Component | dict[str, Component]: ... def from_dict( self, dict_content: ComponentAsDictT, - components_registry: Optional[ComponentsRegistryT] = None, + components_registry: ComponentsRegistryT | None = None, import_only_referenced_components: bool = False, - ) -> Union[Component, Dict[str, Component]]: + ) -> Component | dict[str, Component]: """ Load a component and its sub-components from dictionary. @@ -422,6 +422,67 @@ def from_dict( return referenced_components + @overload + def from_partial_dict( + self, + dict_content: ComponentAsDictT, + ) -> tuple[Component, list[PyAgentSpecErrorDetails]]: ... + + @overload + def from_partial_dict( + self, + dict_content: ComponentAsDictT, + components_registry: ComponentsRegistryT | None, + ) -> tuple[Component, list[PyAgentSpecErrorDetails]]: ... + + @overload + def from_partial_dict( + self, + dict_content: ComponentAsDictT, + *, + import_only_referenced_components: Literal[False], + ) -> tuple[Component, list[PyAgentSpecErrorDetails]]: ... + + @overload + def from_partial_dict( + self, + dict_content: ComponentAsDictT, + *, + import_only_referenced_components: Literal[True], + ) -> tuple[dict[str, Component], list[PyAgentSpecErrorDetails]]: ... + + @overload + def from_partial_dict( + self, + dict_content: ComponentAsDictT, + *, + import_only_referenced_components: bool, + ) -> tuple[Component | dict[str, Component], list[PyAgentSpecErrorDetails]]: ... + + @overload + def from_partial_dict( + self, + dict_content: ComponentAsDictT, + components_registry: ComponentsRegistryT | None, + import_only_referenced_components: Literal[False], + ) -> tuple[Component, list[PyAgentSpecErrorDetails]]: ... + + @overload + def from_partial_dict( + self, + dict_content: ComponentAsDictT, + components_registry: ComponentsRegistryT | None, + import_only_referenced_components: Literal[True], + ) -> tuple[dict[str, Component], list[PyAgentSpecErrorDetails]]: ... + + @overload + def from_partial_dict( + self, + dict_content: ComponentAsDictT, + components_registry: ComponentsRegistryT | None, + import_only_referenced_components: bool, + ) -> tuple[Component | dict[str, Component], list[PyAgentSpecErrorDetails]]: ... + def from_partial_dict( self, dict_content: ComponentAsDictT,