Type hinting Python dataclasses subclass without redefining default value
When using keyword only dataclasses to define fields of a base class that are inherited by subclasses, how should the fields be type hinted in the subclasses to denote that the fields have a limited set of permissible values without re-assigning the default value? Example (for illustrative purposes - not a real world example): from dataclasses import dataclass from enum import auto, StrEnum from typing import Literal class Direction(StrEnum): DOWN = auto() LEFT = auto() UP = auto() RIGHT = auto() UNKNOWN = auto() @dataclass(kw_only=True) class Base: direction: Direction = Direction.UNKNOWN @da
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.