summaryrefslogtreecommitdiff
path: root/pylint/test/functional/inherit_non_class.py
blob: 0929ed1db86212750badef1581feb0654f6fca83 (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
"""Test that inheriting from something which is not
a class emits a warning. """

# pylint: disable=no-init, import-error, invalid-name, using-constant-test
# pylint: disable=missing-docstring, too-few-public-methods, no-absolute-import

from missing import Missing

if 1:
    Ambiguous = None
else:
    Ambiguous = int

class Empty(object):
    """ Empty class. """

def return_class():
    """ Return a class. """
    return Good3

class Bad(1): # [inherit-non-class]
    """ Can't inherit from instance. """

class Bad1(lambda abc: 42): # [inherit-non-class]
    """ Can't inherit from lambda. """

class Bad2(object()): # [inherit-non-class]
    """ Can't inherit from an instance of object. """

class Bad3(return_class): # [inherit-non-class]
    """ Can't inherit from function. """

class Bad4(Empty()): # [inherit-non-class]
    """ Can't inherit from instance. """

class Good(object):
    pass

class Good1(int):
    pass

class Good2(type):
    pass

class Good3(type(int)):
    pass

class Good4(return_class()):
    pass

class Good5(Good4, int, object):
    pass

class Good6(Ambiguous):
    """ Inherits from something ambiguous.

    This could emit a warning when we will have
    flow detection.
    """

class Unknown(Missing):
    pass

class Unknown1(Good5 if True else Bad1):
    pass


class NotInheritableBool(bool): # [inherit-non-class]
    pass


class NotInheritableRange(range): # [inherit-non-class]
    pass


class NotInheritableSlice(slice): # [inherit-non-class]
    pass


class NotInheritableMemoryView(memoryview): # [inherit-non-class]
    pass