-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathabstract_method.py
138 lines (96 loc) · 2.96 KB
/
abstract_method.py
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"""Test abstract-method warning."""
# pylint: disable=missing-docstring
# pylint: disable=too-few-public-methods
import abc
class Abstract(abc.ABC):
def aaaa(self):
"""should be overridden in concrete class"""
raise NotImplementedError()
def bbbb(self):
"""should be overridden in concrete class"""
raise NotImplementedError()
class AbstractB(Abstract, abc.ABC):
"""Abstract class.
this class is checking that it does not output an error msg for
unimplemeted methods in abstract classes
"""
def cccc(self):
"""should be overridden in concrete class"""
raise NotImplementedError()
class AbstractC(AbstractB, abc.ABC):
"""
Abstract class.
Should not trigger a warning for unimplemented
abstract methods, because of explicit abc.ABC inheritance.
"""
class AbstractD(AbstractB, metaclass=abc.ABCMeta):
"""
Abstract class.
Should not trigger a warning for unimplemented
abstract methods, because of explicit metaclass.
"""
class ConcreteA(AbstractC): # [abstract-method, abstract-method, abstract-method]
"""
Incomplete concrete class.
Should trigger a warning for unimplemented abstract
methods due to lack of explicit abc.ABC inheritance.
"""
class ConcreteB(Abstract): # [abstract-method]
"""
Incomplete concrete class.
Should trigger a warning for unimplemented abstract
methods due to lack of explicit abc.ABC inheritance.
"""
def aaaa(self):
"""overridden form Abstract"""
class ConcreteC(AbstractC):
"""
Complete concrete class
Should not trigger a warning as all
abstract methods are implemented.
"""
def aaaa(self):
"""overridden form Abstract"""
def bbbb(self):
"""overridden form Abstract"""
def cccc(self):
"""overridden form AbstractB"""
class Structure(metaclass=abc.ABCMeta):
@abc.abstractmethod
def __iter__(self):
pass
@abc.abstractmethod
def __len__(self):
pass
@abc.abstractmethod
def __contains__(self, _):
pass
@abc.abstractmethod
def __hash__(self):
pass
# +1: [abstract-method, abstract-method, abstract-method]
class Container(Structure):
def __contains__(self, _):
pass
# +1: [abstract-method, abstract-method, abstract-method]
class Sizable(Structure):
def __len__(self):
return 42
# +1: [abstract-method, abstract-method, abstract-method]
class Hashable(Structure):
__hash__ = 42
# +1: [abstract-method, abstract-method, abstract-method]
class Iterator(Structure):
def keys(self):
return iter([1, 2, 3])
__iter__ = keys
class AbstractSizable(Structure):
@abc.abstractmethod
def length(self):
pass
__len__ = length
class GoodComplexMRO(Container, Iterator, Sizable, Hashable):
pass
# +1: [abstract-method, abstract-method, abstract-method]
class BadComplexMro(Container, Iterator, AbstractSizable):
pass