Skip to content

Add a Dataclass protocol type #38

Description

@llucax

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:

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.

Alternatives and workarounds

No response

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    part:typingAffects the typing moduletype:enhancementNew feature or enhancement visitble to users

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions