summaryrefslogtreecommitdiff
path: root/pylint/test/functional/abstract_class_instantiated_py2.py
blob: 9b3f315caa2594407a88d89e47628f6527633a9d (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
"""Check that instantiating a class with
`abc.ABCMeta` as metaclass fails if it defines
abstract methods.
"""

# pylint: disable=too-few-public-methods, missing-docstring
# pylint: disable=no-absolute-import, metaclass-assignment
# pylint: disable=abstract-method

__revision__ = 0

import abc
from abc import ABCMeta

class GoodClass(object):
    __metaclass__ = abc.ABCMeta

class SecondGoodClass(object):
    __metaclass__ = abc.ABCMeta

    def test(self):
        """ do nothing. """

class ThirdGoodClass(object):
    __metaclass__ = abc.ABCMeta

    def test(self):
        raise NotImplementedError()

class FourthGoodClass(object):
    __metaclass__ = ABCMeta

class BadClass(object):
    __metaclass__ = abc.ABCMeta

    @abc.abstractmethod
    def test(self):
        """ do nothing. """

class SecondBadClass(object):
    __metaclass__ = abc.ABCMeta

    @property
    @abc.abstractmethod
    def test(self):
        """ do nothing. """

class ThirdBadClass(object):
    __metaclass__ = ABCMeta

    @abc.abstractmethod
    def test(self):
        pass

class FourthBadClass(ThirdBadClass):
    pass


def main():
    """ do nothing """
    GoodClass()
    SecondGoodClass()
    ThirdGoodClass()
    FourthGoodClass()
    BadClass() # [abstract-class-instantiated]
    SecondBadClass() # [abstract-class-instantiated]
    ThirdBadClass() # [abstract-class-instantiated]
    FourthBadClass() # [abstract-class-instantiated]