How to use the mashumaro.abc.SerializableChainMap 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 / custom.py View on Github external
self.x = frozenset()

    @classmethod
    def from_sequence(cls, seq):
        inst = cls()
        inst.x = frozenset(seq)
        return inst

    def to_sequence(self):
        return self.x

    def __repr__(self):
        return f"CustomSerializableFrozenSet({str(self.x)})"


class CustomSerializableChainMap(ChainMap, SerializableChainMap):
    def __init__(self):
        super().__init__()
        self.x = ChainMap()

    @classmethod
    def from_maps(cls, maps: List[Mapping]):
        inst = cls()
        inst.x = ChainMap(*maps)
        return inst

    def to_maps(self):
        return self.x.maps

    def __repr__(self):
        return f"CustomSerializableChainMap({str(self.x)})"