How to use the mashumaro.DataClassDictMixin function in mashumaro

To help you get started, we’ve selected a few mashumaro examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Fatal1ty / mashumaro / tests / entities / dataclasses.py View on Github external
x: frozenset


@dataclass
class DataClassWithGenericFrozenSet(DataClassDictMixin):
    x: FrozenSet[int]


@dataclass
class DataClassWithCustomSerializableFrozenSet(DataClassDictMixin):
    x: CustomSerializableFrozenSet


# ChainMap
@dataclass
class DataClassWithChainMap(DataClassDictMixin):
    x: collections.ChainMap


@dataclass
class DataClassWithGenericChainMap(DataClassDictMixin):
    x: ChainMap[int, int]


@dataclass
class DataClassWithCustomSerializableChainMap(DataClassDictMixin):
    x: CustomSerializableChainMap


# dict
@dataclass
class DataClassWithDict(DataClassDictMixin):
github Fatal1ty / mashumaro / tests / entities / dataclasses.py View on Github external
# str
@dataclass
class DataClassWithStr(DataClassDictMixin):
    x: str


# sequence
@dataclass
class DataClassWithCustomSerializableSequence(DataClassDictMixin):
    x: CustomSerializableSequence


@dataclass
class DataClassWithCustomSerializableMutableSequence(DataClassDictMixin):
    x: CustomSerializableMutableSequence


@dataclass
class DataClassWithAbstractSequence(DataClassDictMixin):
    x: AbstractSequence


@dataclass
class DataClassWithAbstractMutableSequence(DataClassDictMixin):
    x: AbstractMutableSequence


@dataclass
class DataClassWithEnum(DataClassDictMixin):
    x: MyEnum
github Fatal1ty / mashumaro / tests / entities / dataclasses.py View on Github external
x: CustomSerializableSet


@dataclass
class DataClassWithAbstractSet(DataClassDictMixin):
    x: AbstractSet


@dataclass
class DataClassWithAbstractMutableSet(DataClassDictMixin):
    x: AbstractMutableSet


# frozenset
@dataclass
class DataClassWithFrozenSet(DataClassDictMixin):
    x: frozenset


@dataclass
class DataClassWithGenericFrozenSet(DataClassDictMixin):
    x: FrozenSet[int]


@dataclass
class DataClassWithCustomSerializableFrozenSet(DataClassDictMixin):
    x: CustomSerializableFrozenSet


# ChainMap
@dataclass
class DataClassWithChainMap(DataClassDictMixin):
github Fatal1ty / mashumaro / tests / test_data_types.py View on Github external
def test_derived_dataclass_with_ancestors_defaults():

    @dataclass
    class A:
        x: int
        y: int = 1

    @dataclass
    class B(A, DataClassDictMixin):
        z: int = 3

    @dataclass
    class C(B, DataClassDictMixin):
        y: int = 4

    @dataclass
    class D(C):
        pass

    assert B.from_dict({'x': 0}) == B(x=0, y=1, z=3)
    assert C.from_dict({'x': 0}) == C(x=0, y=4, z=3)
    assert D.from_dict({'x': 0}) == D(x=0, y=4, z=3)
github Fatal1ty / mashumaro / tests / entities / dataclasses.py View on Github external
x: FrozenSet[int]


@dataclass
class DataClassWithCustomSerializableFrozenSet(DataClassDictMixin):
    x: CustomSerializableFrozenSet


# ChainMap
@dataclass
class DataClassWithChainMap(DataClassDictMixin):
    x: collections.ChainMap


@dataclass
class DataClassWithGenericChainMap(DataClassDictMixin):
    x: ChainMap[int, int]


@dataclass
class DataClassWithCustomSerializableChainMap(DataClassDictMixin):
    x: CustomSerializableChainMap


# dict
@dataclass
class DataClassWithDict(DataClassDictMixin):
    x: dict


@dataclass
class DataClassWithGenericDict(DataClassDictMixin):
github Fatal1ty / mashumaro / tests / entities / dataclasses.py View on Github external
class DataClassWithCustomSerializableMutableSequence(DataClassDictMixin):
    x: CustomSerializableMutableSequence


@dataclass
class DataClassWithAbstractSequence(DataClassDictMixin):
    x: AbstractSequence


@dataclass
class DataClassWithAbstractMutableSequence(DataClassDictMixin):
    x: AbstractMutableSequence


@dataclass
class DataClassWithEnum(DataClassDictMixin):
    x: MyEnum


@dataclass
class DataClassWithIntEnum(DataClassDictMixin):
    x: MyIntEnum


@dataclass
class DataClassWithFlag(DataClassDictMixin):
    x: MyFlag


@dataclass
class DataClassWithIntFlag(DataClassDictMixin):
    x: MyIntFlag
github Fatal1ty / mashumaro / tests / entities / dataclasses.py View on Github external
class DataClassWithAbstractMutableSequence(DataClassDictMixin):
    x: AbstractMutableSequence


@dataclass
class DataClassWithEnum(DataClassDictMixin):
    x: MyEnum


@dataclass
class DataClassWithIntEnum(DataClassDictMixin):
    x: MyIntEnum


@dataclass
class DataClassWithFlag(DataClassDictMixin):
    x: MyFlag


@dataclass
class DataClassWithIntFlag(DataClassDictMixin):
    x: MyIntFlag
github Fatal1ty / mashumaro / tests / entities / dataclasses.py View on Github external
x: CustomSerializableDeque


# tuple
@dataclass
class DataClassWithTuple(DataClassDictMixin):
    x: tuple


@dataclass
class DataClassWithGenericTuple(DataClassDictMixin):
    x: Tuple[int]


@dataclass
class DataClassWithCustomSerializableTuple(DataClassDictMixin):
    x: CustomSerializableTuple


# set
@dataclass
class DataClassWithSet(DataClassDictMixin):
    x: set


@dataclass
class DataClassWithGenericSet(DataClassDictMixin):
    x: Set[int]


@dataclass
class DataClassWithCustomSerializableSet(DataClassDictMixin):
github Fatal1ty / mashumaro / tests / entities.py View on Github external
a = 1
    b = 2


class MyFlag(Flag):
    a = 1
    b = 2


class MyIntFlag(IntFlag):
    a = 1
    b = 2


@dataclass
class MyDataClass(DataClassDictMixin):
    a: int
    b: int


class MutableString(SerializableType):
    def __init__(self, value: str):
        self.characters = [c for c in value]

    def _serialize(self) -> str:
        return str(self)

    @classmethod
    def _deserialize(cls, value: str) -> 'MutableString':
        return MutableString(value)

    def __str__(self):
github Fatal1ty / mashumaro / tests / entities / dataclasses.py View on Github external
x: CustomSerializableList


# deque
@dataclass
class DataClassWithDeque(DataClassDictMixin):
    x: collections.deque


@dataclass
class DataClassWithGenericDeque(DataClassDictMixin):
    x: Deque[int]


@dataclass
class DataClassWithCustomSerializableDeque(DataClassDictMixin):
    x: CustomSerializableDeque


# tuple
@dataclass
class DataClassWithTuple(DataClassDictMixin):
    x: tuple


@dataclass
class DataClassWithGenericTuple(DataClassDictMixin):
    x: Tuple[int]


@dataclass
class DataClassWithCustomSerializableTuple(DataClassDictMixin):