gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / pylint / test / functional / abstract_class_instantiated_py2.py @ 745
History | View | Annotate | Download (1.71 KB)
1 |
"""Check that instantiating a class with
|
---|---|
2 |
`abc.ABCMeta` as metaclass fails if it defines
|
3 |
abstract methods.
|
4 |
"""
|
5 |
|
6 |
# pylint: disable=too-few-public-methods, missing-docstring
|
7 |
# pylint: disable=no-absolute-import, metaclass-assignment
|
8 |
# pylint: disable=abstract-method, import-error, wildcard-import
|
9 |
|
10 |
import abc |
11 |
from abc import ABCMeta |
12 |
from lala import Bala |
13 |
|
14 |
|
15 |
class GoodClass(object): |
16 |
__metaclass__ = abc.ABCMeta |
17 |
|
18 |
class SecondGoodClass(object): |
19 |
__metaclass__ = abc.ABCMeta |
20 |
|
21 |
def test(self): |
22 |
""" do nothing. """
|
23 |
|
24 |
class ThirdGoodClass(object): |
25 |
__metaclass__ = abc.ABCMeta |
26 |
|
27 |
def test(self): |
28 |
raise NotImplementedError() |
29 |
|
30 |
class FourthGoodClass(object): |
31 |
__metaclass__ = ABCMeta |
32 |
|
33 |
class BadClass(object): |
34 |
__metaclass__ = abc.ABCMeta |
35 |
|
36 |
@abc.abstractmethod
|
37 |
def test(self): |
38 |
""" do nothing. """
|
39 |
|
40 |
class SecondBadClass(object): |
41 |
__metaclass__ = abc.ABCMeta |
42 |
|
43 |
@property
|
44 |
@abc.abstractmethod
|
45 |
def test(self): |
46 |
""" do nothing. """
|
47 |
|
48 |
class ThirdBadClass(object): |
49 |
__metaclass__ = ABCMeta |
50 |
|
51 |
@abc.abstractmethod
|
52 |
def test(self): |
53 |
pass
|
54 |
|
55 |
class FourthBadClass(ThirdBadClass): |
56 |
pass
|
57 |
|
58 |
|
59 |
class SomeMetaclass(object): |
60 |
__metaclass__ = ABCMeta |
61 |
|
62 |
@abc.abstractmethod
|
63 |
def prop(self): |
64 |
pass
|
65 |
|
66 |
class FifthGoodClass(SomeMetaclass): |
67 |
"""Don't consider this abstract if some attributes are
|
68 |
there, but can't be inferred.
|
69 |
"""
|
70 |
prop = Bala # missing
|
71 |
|
72 |
|
73 |
def main(): |
74 |
""" do nothing """
|
75 |
GoodClass() |
76 |
SecondGoodClass() |
77 |
ThirdGoodClass() |
78 |
FourthGoodClass() |
79 |
BadClass() # [abstract-class-instantiated]
|
80 |
SecondBadClass() # [abstract-class-instantiated]
|
81 |
ThirdBadClass() # [abstract-class-instantiated]
|
82 |
FourthBadClass() # [abstract-class-instantiated]
|
83 |
|