|
1 | 1 | """Tests for super-init-not-called."""
|
2 | 2 | # pylint: disable=too-few-public-methods, missing-class-docstring
|
3 | 3 |
|
| 4 | +import abc |
4 | 5 | import ctypes
|
5 | 6 |
|
6 | 7 |
|
@@ -53,5 +54,45 @@ def __init__(self): # [super-init-not-called]
|
53 | 54 | # Regression test as reported in
|
54 | 55 | # https://github.com/PyCQA/pylint/issues/6027
|
55 | 56 | class MyUnion(ctypes.Union):
|
56 |
| - def __init__(self): # [super-init-not-called] |
| 57 | + def __init__(self): |
57 | 58 | pass
|
| 59 | + |
| 60 | + |
| 61 | +# Should not be called on abstract __init__ methods |
| 62 | +# https://github.com/PyCQA/pylint/issues/3975 |
| 63 | +class Base: |
| 64 | + def __init__(self, param: int, param_two: str) -> None: |
| 65 | + raise NotImplementedError() |
| 66 | + |
| 67 | + |
| 68 | +class Derived(Base): |
| 69 | + def __init__(self, param: int, param_two: str) -> None: |
| 70 | + self.param = param + 1 |
| 71 | + self.param_two = param_two[::-1] |
| 72 | + |
| 73 | + |
| 74 | +class AbstractBase(abc.ABC): |
| 75 | + def __init__(self, param: int) -> None: |
| 76 | + self.param = param + 1 |
| 77 | + |
| 78 | + def abstract_method(self) -> str: |
| 79 | + """This needs to be implemented.""" |
| 80 | + raise NotImplementedError() |
| 81 | + |
| 82 | + |
| 83 | +class DerivedFromAbstract(AbstractBase): |
| 84 | + def __init__(self, param: int) -> None: # [super-init-not-called] |
| 85 | + print("Called") |
| 86 | + |
| 87 | + def abstract_method(self) -> str: |
| 88 | + return "Implemented" |
| 89 | + |
| 90 | + |
| 91 | +class DerivedFrom(UnknownParent): # [undefined-variable] |
| 92 | + def __init__(self) -> None: |
| 93 | + print("Called") |
| 94 | + |
| 95 | + |
| 96 | +class DerivedFromUnknownGrandparent(DerivedFrom): |
| 97 | + def __init__(self) -> None: |
| 98 | + DerivedFrom.__init__(self) |
0 commit comments