Skip to content

Provide better typing of VariableFactory #1341

Closed
@williambdean

Description

@williambdean

The VariableFactory just requires the create_variable method and dims attribute to a class. However, if the class has to_dict and is registered for deserialize function, then that gives the additional benefit of serialization and deserialization. I don't know the best way to type this or if it is even an issue

Maybe there a protocol with optional methods? or something like below should also be specified:

@runtime_checkable
class SerializableVariableFactory(Protocol):
    dims: tuple[str, ...]

    def create_variable(self, name: str) -> Variable:
        ...

    def to_dict(self) -> dict[str, Any]:
        ...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions