Skip to content

Commit 1ed5665

Browse files
committed
Fix false positive for arguments-differ when overriding __init_subclass__.
Closes #8919
1 parent 64cc5c2 commit 1ed5665

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix false positive for ``arguments-differ`` when overriding `__init_subclass__`.
2+
3+
Closes #8919

pylint/checkers/classes/class_checker.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,6 @@ def _different_parameters(
370370
if different_kwonly:
371371
output_messages += different_kwonly
372372

373-
if original.name in PYMETHODS:
374-
# Ignore the difference for special methods. If the parameter
375-
# numbers are different, then that is going to be caught by
376-
# unexpected-special-method-signature.
377-
# If the names are different, it doesn't matter, since they can't
378-
# be used as keyword arguments anyway.
379-
output_messages.clear()
380-
381373
# Arguments will only violate LSP if there are variadics in the original
382374
# that are then removed from the overridden
383375
kwarg_lost = original.args.kwarg and not overridden.args.kwarg
@@ -386,6 +378,14 @@ def _different_parameters(
386378
if kwarg_lost or vararg_lost:
387379
output_messages += ["Variadics removed in"]
388380

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

391391

tests/functional/a/arguments_differ.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,13 @@ def method(self, *, arg1):
358358
class ClassWithNewNonDefaultKeywordOnly(AClass):
359359
def method(self, *, arg2, arg1=None): # [arguments-differ]
360360
...
361+
362+
363+
# Exclude `__init_subclass__` from the check:
364+
class InitSubclassParent:
365+
def __init_subclass__(cls, *args, **kwargs):
366+
...
367+
368+
class InitSubclassChild(InitSubclassParent):
369+
def __init_subclass__(cls, /, **kwargs) -> None:
370+
super().__init_subclass__(**kwargs)

0 commit comments

Comments
 (0)