From c383253cd90b18fd0823a1aa3a32acebb960fc16 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 10 May 2025 14:40:21 -0700 Subject: [PATCH 1/2] builtins: remove `object.__annotations__` Not all objects have annotations, so I think this shouldn't exist. We already have `__annotations__` attributes explicitly set on the objects that do have them (e.g., functions, classes, and modules). --- stdlib/builtins.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 5a1d4dd8afb9..dc1315d4e8b8 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -107,7 +107,6 @@ class object: __doc__: str | None __dict__: dict[str, Any] __module__: str - __annotations__: dict[str, Any] @property def __class__(self) -> type[Self]: ... @__class__.setter From ead6dab0b03079f6e3ac910b8b788ac79ce48a2d Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 10 May 2025 15:36:33 -0700 Subject: [PATCH 2/2] tweaks --- stdlib/@tests/stubtest_allowlists/py314.txt | 2 -- stdlib/builtins.pyi | 6 ++++++ stdlib/functools.pyi | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/py314.txt b/stdlib/@tests/stubtest_allowlists/py314.txt index 9f79c767bf7d..b8b2b8419316 100644 --- a/stdlib/@tests/stubtest_allowlists/py314.txt +++ b/stdlib/@tests/stubtest_allowlists/py314.txt @@ -60,13 +60,11 @@ builtins.BaseExceptionGroup.subgroup builtins.ExceptionGroup.split builtins.ExceptionGroup.subgroup builtins.bytearray.resize -builtins.classmethod.__annotate__ builtins.classmethod.__class_getitem__ builtins.complex.from_number builtins.float.from_number builtins.int.__round__ builtins.memoryview.__class_getitem__ -builtins.staticmethod.__annotate__ builtins.staticmethod.__class_getitem__ code.compile_command codeop.compile_command diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index dc1315d4e8b8..ceed9306e623 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -153,6 +153,9 @@ class staticmethod(Generic[_P, _R_co]): @property def __wrapped__(self) -> Callable[_P, _R_co]: ... def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R_co: ... + __annotations__: dict[str, AnnotationForm] + if sys.version_info >= (3, 14): + __annotate__: AnnotateFunc | None class classmethod(Generic[_T, _P, _R_co]): @property @@ -169,6 +172,9 @@ class classmethod(Generic[_T, _P, _R_co]): __qualname__: str @property def __wrapped__(self) -> Callable[Concatenate[type[_T], _P], _R_co]: ... + __annotations__: dict[str, AnnotationForm] + if sys.version_info >= (3, 14): + __annotate__: AnnotateFunc | None class type: # object.__base__ is None. Otherwise, it would be a type. diff --git a/stdlib/functools.pyi b/stdlib/functools.pyi index d35c295754e5..1659c91614f8 100644 --- a/stdlib/functools.pyi +++ b/stdlib/functools.pyi @@ -1,6 +1,6 @@ import sys import types -from _typeshed import SupportsAllComparisons, SupportsItems +from _typeshed import AnnotationForm, SupportsAllComparisons, SupportsItems from collections.abc import Callable, Hashable, Iterable, Sized from types import GenericAlias from typing import Any, Generic, Literal, NamedTuple, TypedDict, TypeVar, final, overload @@ -85,6 +85,7 @@ class _Wrapped(Generic[_PWrapped, _RWrapped, _PWrapper, _RWrapper]): class _Wrapper(Generic[_PWrapped, _RWrapped]): def __call__(self, f: Callable[_PWrapper, _RWrapper]) -> _Wrapped[_PWrapped, _RWrapped, _PWrapper, _RWrapper]: ... + __annotations__: dict[str, AnnotationForm] if sys.version_info >= (3, 12): def update_wrapper(