Skip to content

Fix false positive for arguments-differ #8927

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 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/8919.false_positive
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix false positive for ``arguments-differ`` when overriding `__init_subclass__`.

Closes #8919
16 changes: 8 additions & 8 deletions pylint/checkers/classes/class_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,6 @@ def _different_parameters(
if different_kwonly:
output_messages += different_kwonly

if original.name in PYMETHODS:
# Ignore the difference for special methods. If the parameter
# numbers are different, then that is going to be caught by
# unexpected-special-method-signature.
# If the names are different, it doesn't matter, since they can't
# be used as keyword arguments anyway.
output_messages.clear()

# Arguments will only violate LSP if there are variadics in the original
# that are then removed from the overridden
kwarg_lost = original.args.kwarg and not overridden.args.kwarg
Expand All @@ -386,6 +378,14 @@ def _different_parameters(
if kwarg_lost or vararg_lost:
output_messages += ["Variadics removed in"]

if original.name in PYMETHODS:
# Ignore the difference for special methods. If the parameter
# numbers are different, then that is going to be caught by
# unexpected-special-method-signature.
# If the names are different, it doesn't matter, since they can't
# be used as keyword arguments anyway.
output_messages.clear()

return output_messages


Expand Down
10 changes: 10 additions & 0 deletions tests/functional/a/arguments_differ.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,13 @@ def method(self, *, arg1):
class ClassWithNewNonDefaultKeywordOnly(AClass):
def method(self, *, arg2, arg1=None): # [arguments-differ]
...


# Exclude `__init_subclass__` from the check:
class InitSubclassParent:
def __init_subclass__(cls, *args, **kwargs):
...

class InitSubclassChild(InitSubclassParent):
def __init_subclass__(cls, /, **kwargs) -> None:
super().__init_subclass__(**kwargs)