Skip to content

Commit

Permalink
Don't require super call from typing.overload-ed __init__
Browse files Browse the repository at this point in the history
  • Loading branch information
gyermolenko committed Aug 10, 2019
1 parent a6b1e81 commit f9a2746
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pylint/checkers/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,7 @@ def is_abstract(method):

def _check_init(self, node):
"""check that the __init__ method call super or ancestors'__init__
method
method (unless it is used for type hinting with `typing.overload`)
"""
if not self.linter.is_message_enabled(
"super-init-not-called"
Expand Down Expand Up @@ -1600,6 +1600,8 @@ def _check_init(self, node):
except astroid.InferenceError:
continue
for klass, method in not_called_yet.items():
if decorated_with(node, ["typing.overload"]):
continue
cls = node_frame_class(method)
if klass.name == "object" or (cls and cls.name == "object"):
continue
Expand Down
22 changes: 22 additions & 0 deletions tests/functional/init_not_called.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,25 @@ def __init__(self): # [super-init-not-called]

class UnknownBases(Missing):
"""Don't emit no-init if the bases aren't known."""


from typing import overload # pylint: disable=wrong-import-order

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))

0 comments on commit f9a2746

Please sign in to comment.