It is sometimes useful when working with dataclasses in a generic way to be able to have a type-hint that will detect passing non-dataclasses by mypy instead of at runtime.
Proposed solution
Add a new class to frequenz.core.typing like:
from typing import Protocol
class Dataclass(Protocol):
__dataclass_fields__: dict
Use cases
Wrappers using marshmallow_dataclass, where we want to make sure we take a dataclass, for example for loading as if it where a schema.
What's needed?
It is sometimes useful when working with dataclasses in a generic way to be able to have a type-hint that will detect passing non-dataclasses by
mypy
instead of at runtime.Proposed solution
Add a new class to
frequenz.core.typing
like:Use cases
Wrappers using
marshmallow_dataclass
, where we want to make sure we take a dataclass, for example for loading as if it where a schema.Alternatives and workarounds
No response
Additional context
No response