Skip to content

Commit 46b159d

Browse files
AFanaeiJukkaL
authored andcommitted
Treat __class_getitem__ as an implicit classmethod like __init_subclass__ (#7647)
Fixes #7319.
1 parent f86b422 commit 46b159d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ def prepare_method_signature(self, func: FuncDef, info: TypeInfo) -> None:
616616
# Only non-static methods are special.
617617
functype = func.type
618618
if not func.is_static:
619-
if func.name() == '__init_subclass__':
619+
if func.name() in ['__init_subclass__', '__class_getitem__']:
620620
func.is_class = True
621621
if not func.arguments:
622622
self.fail('Method must have at least one argument', func)

test-data/unit/check-super.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,17 @@ class A:
258258
super().__init_subclass__()
259259
[builtins fixtures/__init_subclass__.pyi]
260260

261+
[case testSuperClassGetItem]
262+
from typing import TypeVar, Type, Any
263+
264+
T = TypeVar("T", bound="B")
265+
266+
class A:
267+
def __class_getitem__(cls, item) -> None: pass
268+
269+
class B(A):
270+
def __class_getitem__(cls: Type[T], item: Any) -> None:
271+
super(B, cls).__class_getitem__(item)
261272

262273
-- Invalid uses of super()
263274
-- -----------------------

0 commit comments

Comments
 (0)