summaryrefslogtreecommitdiff
path: root/tests/functional/i/init_not_called.py
blob: db677dc4b6f666d4d6fe97eaa52ffac35d275178 (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
# pylint: disable=too-few-public-methods, import-error, missing-docstring, wrong-import-position
# pylint: disable=useless-super-delegation, unnecessary-pass


from typing import overload

from missing import Missing


class AAAA:
    """ancestor 1"""

    def __init__(self):
        print("init", self)


class BBBB:
    """ancestor 2"""

    def __init__(self):
        print("init", self)


class CCCC:
    """ancestor 3"""


class ZZZZ(AAAA, BBBB, CCCC):
    """derived class"""

    def __init__(self):  # [super-init-not-called]
        AAAA.__init__(self)


class NewStyleA:
    """new style class"""

    def __init__(self):
        super().__init__()
        print("init", self)


class NewStyleB(NewStyleA):
    """derived new style class"""

    def __init__(self):
        super().__init__()


class NewStyleC:
    """__init__ defined by assignment."""

    def xx_init(self):
        """Initializer."""
        pass

    __init__ = xx_init


class AssignedInit(NewStyleC):
    """No init called, but abstract so that is fine."""

    def __init__(self):
        self.arg = 0


class UnknownBases(Missing):
    """No false positives if the bases aren't known."""


class Parent:
    def __init__(self, num: int):
        self.number = num


class Child(Parent):
    @overload
    def __init__(self, num: int):
        ...

    @overload
    def __init__(self, num: float):
        ...

    def __init__(self, num):
        super().__init__(round(num))


# https://github.com/pylint-dev/pylint/issues/7742
# Crash when parent class has a class attribute named `__init__`
class NoInitMethod:
    __init__ = 42


class ChildNoInitMethod(NoInitMethod):
    def __init__(self):
        ...