From f895a3ad1bef66e1795f81c39cb086783727759a Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 25 Aug 2026 11:04:43 +0100 Subject: [PATCH 1/2] Improve the signature of `type.__subclasses__` --- stdlib/builtins.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 3c549d97316c..903b13aa460a 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -218,7 +218,7 @@ class type: ) -> _typeshed.Self: ... def __call__(self, *args: Any, **kwds: Any) -> Any: ... - def __subclasses__(self: _typeshed.Self) -> list[_typeshed.Self]: ... + def __subclasses__(self: type[_T]) -> list[type[_T]]: ... # Note: the documentation doesn't specify what the return type is, the standard # implementation seems to be returning a list. def mro(self) -> list[type]: ... From 4fe13b6852d4fcf03ae904e601b723e5582106bc Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 25 Aug 2026 12:30:26 +0100 Subject: [PATCH 2/2] add tests --- stdlib/@tests/test_cases/builtins/check_type.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stdlib/@tests/test_cases/builtins/check_type.py b/stdlib/@tests/test_cases/builtins/check_type.py index 1eafcf482fb6..e29550169d99 100644 --- a/stdlib/@tests/test_cases/builtins/check_type.py +++ b/stdlib/@tests/test_cases/builtins/check_type.py @@ -1,4 +1,12 @@ +from typing_extensions import assert_type + + class Meta(type): ... call = Meta.__dict__["__call__"] + +# Regression tests for https://github.com/python/typeshed/pull/16299 +assert_type(int.__subclasses__(), list[type[int]]) +assert_type(str.__subclasses__(), list[type[str]]) +assert_type(BaseException.__subclasses__(), list[type[BaseException]])