blob: eb6e1bebb08d1400832afa64e73af673e87aae2e (
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# pylint: disable=missing-docstring, invalid-name
from enum import Enum, Flag, IntEnum, auto
class Issue1932(IntEnum):
"""https://github.com/pylint-dev/pylint/issues/1932"""
FOO = 1
def whats_my_name(self):
return self.name.lower()
class Issue2062(Enum):
"""https://github.com/pylint-dev/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
# Check combinations of Flag members using the bitwise operators (&, |, ^, ~)
# https://github.com/pylint-dev/pylint/issues/7381
class Colour(Flag):
NONE = 0
RED = 2
GREEN = 2
BLUE = 4
and_expr = Colour.RED & Colour.GREEN & Colour.BLUE
and_expr_with_complement = ~Colour.RED & ~Colour.GREEN & ~Colour.BLUE
or_expr = Colour.RED | Colour.GREEN | Colour.BLUE
xor_expr = Colour.RED ^ Colour.GREEN ^ Colour.BLUE
|