summaryrefslogtreecommitdiff
path: root/pylint/test/functional/abstract_class_instantiated_py2.py
blob: d30c1a5f7fb96ce0dff63956905761cd7248beb1 (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
"""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, import-error, wildcard-import

import abc
from abc import ABCMeta
from lala import Bala


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


class SomeMetaclass(object):
    __metaclass__ = ABCMeta

    @abc.abstractmethod
    def prop(self):
        pass

class FifthGoodClass(SomeMetaclass):
    """Don't consider this abstract if some attributes are
    there, but can't be inferred.
    """
    prop = Bala # missing


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