blob: 03bfd3b435b64c504fe40c964a1e95d9fbc5d778 (
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
|
"""Tests for super-init-not-called."""
# pylint: disable=too-few-public-methods, missing-class-docstring
import abc
import ctypes
class Foo(ctypes.BigEndianStructure):
"""This class should not emit a super-init-not-called warning.
It previously did, because ``next(node.infer())`` was used in that checker's logic
and the first inferred node was an Uninferable object, leading to this false positive.
"""
def __init__(self):
ctypes.BigEndianStructure.__init__(self)
class UninferableChild(UninferableParent): # [undefined-variable]
"""An implementation that test if we don't crash on uninferable parents."""
def __init__(self):
...
# Tests for not calling the init of a parent that does not define one
# but inherits it.
class GrandParentWithInit:
def __init__(self):
print(self)
class ParentWithoutInit(GrandParentWithInit):
pass
class ChildOne(ParentWithoutInit, GrandParentWithInit):
"""Since ParentWithoutInit calls GrandParentWithInit it doesn't need to be called."""
def __init__(self):
GrandParentWithInit.__init__(self)
class ChildTwo(ParentWithoutInit):
def __init__(self):
ParentWithoutInit.__init__(self)
class ChildThree(ParentWithoutInit):
def __init__(self): # [super-init-not-called]
...
# Regression test as reported in
# https://github.com/pylint-dev/pylint/issues/6027
class MyUnion(ctypes.Union):
def __init__(self):
pass
# Should not be called on abstract __init__ methods
# https://github.com/pylint-dev/pylint/issues/3975
class Base:
def __init__(self, param: int, param_two: str) -> None:
raise NotImplementedError()
class Derived(Base):
def __init__(self, param: int, param_two: str) -> None:
self.param = param + 1
self.param_two = param_two[::-1]
class AbstractBase(abc.ABC):
def __init__(self, param: int) -> None:
self.param = param + 1
def abstract_method(self) -> str:
"""This needs to be implemented."""
raise NotImplementedError()
class DerivedFromAbstract(AbstractBase):
def __init__(self, param: int) -> None: # [super-init-not-called]
print("Called")
def abstract_method(self) -> str:
return "Implemented"
class DerivedFrom(UnknownParent): # [undefined-variable]
def __init__(self) -> None:
print("Called")
class DerivedFromUnknownGrandparent(DerivedFrom):
def __init__(self) -> None:
DerivedFrom.__init__(self)
|