summaryrefslogtreecommitdiff
path: root/tests/functional/a/abstract/abstract_method.py
blob: 2ea751141190dca79430d44173297dfd82e436e6 (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
96
97
98
99
100
101
102
103
104
105
106
107
"""Test abstract-method warning."""
from __future__ import print_function

# pylint: disable=missing-docstring
# pylint: disable=too-few-public-methods, useless-object-inheritance
import abc


class Abstract(object):
    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):
    """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 Concrete(Abstract): # [abstract-method]
    """Concrete class"""

    def aaaa(self):
        """overridden form Abstract"""


class Structure(object, 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