Skip to content

Commit 04f9bc1

Browse files
miedzinskiJukkaL
authored andcommitted
Allow arbitrary overriding of __init_subclass__ (#2883)
1 parent fe1056b commit 04f9bc1

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

mypy/checker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,9 @@ def check_method_or_accessor_override_for_base(self, defn: FuncBase,
837837
"""Check if method definition is compatible with a base class."""
838838
if base:
839839
name = defn.name()
840-
if name not in ('__init__', '__new__'):
841-
# Check method override (__init__ and __new__ are special).
840+
if name not in ('__init__', '__new__', '__init_subclass__'):
841+
# Check method override
842+
# (__init__, __new__, __init_subclass__ are special).
842843
self.check_method_override_for_base_with_name(defn, name, base)
843844
if name in nodes.inplace_operator_methods:
844845
# Figure out the name of the corresponding operator method.

test-data/unit/check-classes.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ class B(A):
303303
def g(self) -> None:
304304
def f(self) -> str: pass
305305

306+
[case testOverride__init_subclass__WithDifferentSignature]
307+
class A:
308+
def __init_subclass__(cls, x: int) -> None: pass
309+
class B(A):
310+
def __init_subclass__(cls) -> None: pass
311+
306312

307313
-- Constructors
308314
-- ------------

0 commit comments

Comments
 (0)