summaryrefslogtreecommitdiff
path: root/tests/functional/n/no/no_member_subclassed_dataclasses.py
blob: 0dee108407127f9a0ac800294e4f47fa774a0498 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# pylint: disable=fixme,logging-too-many-args,logging-fstring-interpolation,missing-docstring,no-else-return
# pylint: disable=too-few-public-methods

# Disabled because of a bug with pypy 3.8 see
# https://github.com/PyCQA/pylint/pull/7918#issuecomment-1352737369
# pylint: disable=multiple-statements

from abc import ABCMeta, abstractmethod
import dataclasses as dc
from typing import Any, Dict

@dc.dataclass(frozen=True)
class DeploymentState(metaclass=ABCMeta):
    type: str

    @abstractmethod
    def to_dict(self) -> Dict:
        """
        Serializes given DeploymentState instance to Dict.
        :return:
        """

@dc.dataclass(frozen=True)
class DeploymentStateEcs(DeploymentState):
    blue: Any
    green: Any
    candidate: Any

    def to_dict(self) -> Dict:
        return {
            'type': self.type,
            'blue': dc.asdict(self.blue),
            'green': dc.asdict(self.green),
            'candidate': self.candidate.value,
        }

@dc.dataclass(frozen=True)
class DeploymentStateLambda(DeploymentState):
    current: Any
    candidate: Any

    def to_dict(self) -> Dict:
        return {
            'type': self.type,
            'current': dc.asdict(self.current),
            'candidate': dc.asdict(self.candidate) if self.candidate else None,
        }