Skip to content

Commit 2707c42

Browse files
committed
Don't promote __init_subclass__ to a classmethod if it's already one.
Fixes a crash in the release dashboard. PiperOrigin-RevId: 623606336
1 parent 8264a14 commit 2707c42

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

pytype/overlays/special_builtins.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,8 @@ def call(self, node, func, args, alias_map=None):
776776
arg = args.posargs[0]
777777
if not _check_method_decorator_arg(arg, "classmethod", self.ctx):
778778
return node, self.ctx.new_unsolvable(node)
779+
if any(isinstance(v, ClassMethodInstance) for v in arg.data):
780+
return node, arg
779781
for d in arg.data:
780782
d.is_classmethod = True
781783
d.is_attribute_of_class = True

pytype/tests/test_classes2.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,18 @@ def __init_subclass__(cls):
593593
super().__init_subclass__()
594594
""")
595595

596+
def test_init_subclass_explicit_classmethod(self):
597+
ty = self.Infer("""
598+
class Foo:
599+
@classmethod
600+
def __init_subclass__(cls):
601+
pass
602+
""")
603+
self.assertTypesMatchPytd(ty, """
604+
class Foo:
605+
def __init_subclass__(cls) -> None: ...
606+
""")
607+
596608

597609
if __name__ == "__main__":
598610
test_base.main()

0 commit comments

Comments
 (0)