aboutsummaryrefslogtreecommitdiff
path: root/tests/functional/e/enum_subclasses.py
blob: c8493da785f647e445d35c4a0ebc20d1203d0484 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# pylint: disable=missing-docstring, invalid-name
from enum import Enum, IntEnum, auto


class Issue1932(IntEnum):
    """https://github.com/PyCQA/pylint/issues/1932"""

    FOO = 1

    def whats_my_name(self):
        return self.name.lower()


class Issue2062(Enum):
    """https://github.com/PyCQA/pylint/issues/2062"""

    FOO = 1
    BAR = 2

    def __str__(self):
        return self.name.lower()


class OrderedEnum(Enum):
    def __ge__(self, other):
        if self.__class__ is other.__class__:
            return self.value >= other.value  # line 11
        return NotImplemented

    def __gt__(self, other):
        if self.__class__ is other.__class__:
            return self.value > other.value  # line 16
        return NotImplemented


class Color(OrderedEnum):
    red = 0
    green = 1


class People(Enum):
    jack = 0
    john = 1


print(Color.red.value)  # line 29
print(People.jack.name)


class BaseEnum(Enum):
    def some_behavior(self):
        pass


class MyEnum(BaseEnum):

    FOO = 1
    BAR = 2


print(MyEnum.FOO.value)

class TestBase(Enum):
    """Adds a special method to enums."""

    def hello_pylint(self) -> str:
        """False positive."""
        return self.name


class TestEnum(TestBase):
    """Tests the false positive for enums."""

    a = auto()
    b = auto()


test_enum = TestEnum.a
assert test_enum.hello_pylint() == test_enum.name