-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Don't emit super-init-not-called
for abstract __init__
methods
#7227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Don't report ``super-init-not-called`` for abstract ``__init__`` methods. | ||
|
||
Closes #3975 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
super-init-not-called:32:4:32:16:ZZZZ.__init__:__init__ method from base class 'BBBB' is not called:INFERENCE | ||
super-init-not-called:64:4:64:16:AssignedInit.__init__:__init__ method from base class 'NewStyleC' is not called:INFERENCE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
"""Tests for super-init-not-called.""" | ||
# pylint: disable=too-few-public-methods, missing-class-docstring | ||
|
||
import abc | ||
import ctypes | ||
|
||
|
||
|
@@ -53,5 +54,45 @@ def __init__(self): # [super-init-not-called] | |
# Regression test as reported in | ||
# https://github.com/PyCQA/pylint/issues/6027 | ||
class MyUnion(ctypes.Union): | ||
def __init__(self): # [super-init-not-called] | ||
def __init__(self): | ||
pass | ||
|
||
|
||
# Should not be called on abstract __init__ methods | ||
# https://github.com/PyCQA/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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a regression test for the coverage that dropped. We try to infer bases which fails here. |
||
def __init__(self) -> None: | ||
print("Called") | ||
|
||
|
||
class DerivedFromUnknownGrandparent(DerivedFrom): | ||
def __init__(self) -> None: | ||
DerivedFrom.__init__(self) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[testoptions] | ||
# ctypes has a different implementation in PyPy and does have an inferable | ||
# __init__ method for ctypes.Union. | ||
except_implementations=PyPy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
undefined-variable:18:23:18:40:UninferableChild:Undefined variable 'UninferableParent':UNDEFINED | ||
super-init-not-called:49:4:49:16:ChildThree.__init__:__init__ method from base class 'ParentWithoutInit' is not called:INFERENCE | ||
super-init-not-called:56:4:56:16:MyUnion.__init__:__init__ method from base class 'Union' is not called:INFERENCE | ||
undefined-variable:19:23:19:40:UninferableChild:Undefined variable 'UninferableParent':UNDEFINED | ||
super-init-not-called:50:4:50:16:ChildThree.__init__:__init__ method from base class 'ParentWithoutInit' is not called:INFERENCE | ||
super-init-not-called:84:4:84:16:DerivedFromAbstract.__init__:__init__ method from base class 'AbstractBase' is not called:INFERENCE | ||
undefined-variable:91:18:91:31:DerivedFrom:Undefined variable 'UnknownParent':UNDEFINED |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lines below are no longer necessary now that we skip
object.__init__
because of its abstractness.