From 9614cc2d88f5b0ffa45dee105bfa158a27339ef3 Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Sat, 23 Nov 2024 16:00:49 -0800 Subject: [PATCH] Fix some CAPI annotations (#13081) --- stdlib/@tests/stubtest_allowlists/common.txt | 2 -- stdlib/@tests/stubtest_allowlists/py38.txt | 1 - stdlib/_socket.pyi | 4 ++-- stdlib/datetime.pyi | 4 +++- stdlib/pyexpat/__init__.pyi | 4 +++- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index bb1337d9e..e87ba193c 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -58,7 +58,6 @@ multiprocessing.synchronize.SemLock.release numbers.Number.__hash__ # typeshed marks this as abstract but code just sets this as None optparse.Values.__getattr__ # Some attributes are set in __init__ using setattr pickle.Pickler.reducer_override # implemented in C pickler -pyexpat.expat_CAPI select.poll # Depends on configuration selectors.DevpollSelector # Depends on configuration shutil.rmtree # stubtest doesn't like that we have this as an instance of a callback protocol instead of a function @@ -77,7 +76,6 @@ typing.type_check_only # typing decorator that is not available at runtime unittest.mock.patch # It's a complicated overload and I haven't been able to figure out why stubtest doesn't like it weakref.WeakKeyDictionary.update weakref.WeakValueDictionary.update -xml.parsers.expat.expat_CAPI # ========== # TODO: Modules that exist at runtime, but are missing from stubs diff --git a/stdlib/@tests/stubtest_allowlists/py38.txt b/stdlib/@tests/stubtest_allowlists/py38.txt index 2e3b7bd77..88042bb6e 100644 --- a/stdlib/@tests/stubtest_allowlists/py38.txt +++ b/stdlib/@tests/stubtest_allowlists/py38.txt @@ -110,7 +110,6 @@ tkinter.Tk.__init__ # Exists at runtime, but missing from stubs _?contextvars.ContextVar.__class_getitem__ -datetime.datetime_CAPI dummy_threading.ExceptHookArgs dummy_threading.Lock dummy_threading.RLock diff --git a/stdlib/_socket.pyi b/stdlib/_socket.pyi index 454fd6cb2..36bc5c31c 100644 --- a/stdlib/_socket.pyi +++ b/stdlib/_socket.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer, WriteableBuffer from collections.abc import Iterable from socket import error as error, gaierror as gaierror, herror as herror, timeout as timeout from typing import Any, SupportsIndex, overload -from typing_extensions import TypeAlias +from typing_extensions import CapsuleType, TypeAlias _CMSG: TypeAlias = tuple[int, int, bytes] _CMSGArg: TypeAlias = tuple[int, int, ReadableBuffer] @@ -842,4 +842,4 @@ def if_nameindex() -> list[tuple[int, str]]: ... def if_nametoindex(oname: str, /) -> int: ... def if_indextoname(index: int, /) -> str: ... -CAPI: object +CAPI: CapsuleType diff --git a/stdlib/datetime.pyi b/stdlib/datetime.pyi index 95a25ebb8..87037ef39 100644 --- a/stdlib/datetime.pyi +++ b/stdlib/datetime.pyi @@ -2,7 +2,7 @@ import sys from abc import abstractmethod from time import struct_time from typing import ClassVar, Final, NoReturn, SupportsIndex, final, overload, type_check_only -from typing_extensions import Self, TypeAlias, deprecated +from typing_extensions import CapsuleType, Self, TypeAlias, deprecated if sys.version_info >= (3, 11): __all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo", "MINYEAR", "MAXYEAR", "UTC") @@ -332,3 +332,5 @@ class datetime(date): def __sub__(self, value: Self, /) -> timedelta: ... @overload def __sub__(self, value: timedelta, /) -> Self: ... + +datetime_CAPI: CapsuleType diff --git a/stdlib/pyexpat/__init__.pyi b/stdlib/pyexpat/__init__.pyi index d38259a20..21e676052 100644 --- a/stdlib/pyexpat/__init__.pyi +++ b/stdlib/pyexpat/__init__.pyi @@ -2,7 +2,7 @@ from _typeshed import ReadableBuffer, SupportsRead from collections.abc import Callable from pyexpat import errors as errors, model as model from typing import Any, Final, final -from typing_extensions import TypeAlias +from typing_extensions import CapsuleType, TypeAlias from xml.parsers.expat import ExpatError as ExpatError EXPAT_VERSION: Final[str] # undocumented @@ -78,3 +78,5 @@ def ErrorString(code: int, /) -> str: ... def ParserCreate( encoding: str | None = None, namespace_separator: str | None = None, intern: dict[str, Any] | None = None ) -> XMLParserType: ... + +expat_CAPI: CapsuleType