From 9430260770b627c04313d4edbe75b5b9b0a7f310 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 17 May 2025 10:43:22 -0700 Subject: [PATCH] builtins: improve builtins.function (#14094) Remove two differences from types.FunctionType that should be safe to clean up. --- stdlib/builtins.pyi | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index caf208e5d..8e1e02ac3 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -1028,7 +1028,7 @@ class function: __annotations__: dict[str, AnnotationForm] if sys.version_info >= (3, 14): __annotate__: AnnotateFunc | None - __kwdefaults__: dict[str, Any] + __kwdefaults__: dict[str, Any] | None if sys.version_info >= (3, 10): @property def __builtins__(self) -> dict[str, Any]: ... @@ -1036,6 +1036,26 @@ class function: __type_params__: tuple[TypeVar | ParamSpec | TypeVarTuple, ...] __module__: str + if sys.version_info >= (3, 13): + def __new__( + cls, + code: CodeType, + globals: dict[str, Any], + name: str | None = None, + argdefs: tuple[object, ...] | None = None, + closure: tuple[CellType, ...] | None = None, + kwdefaults: dict[str, object] | None = None, + ) -> Self: ... + else: + def __new__( + cls, + code: CodeType, + globals: dict[str, Any], + name: str | None = None, + argdefs: tuple[object, ...] | None = None, + closure: tuple[CellType, ...] | None = None, + ) -> Self: ... + # mypy uses `builtins.function.__get__` to represent methods, properties, and getset_descriptors so we type the return as Any. def __get__(self, instance: object, owner: type | None = None, /) -> Any: ...