From a75323a75d876eb907893dab04cfb28b4cc10e3e Mon Sep 17 00:00:00 2001 From: Jun Komoda <45822440+junkmd@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:08:39 +0000 Subject: [PATCH 1/5] Fixes https://github.com/python/typeshed/issues/12736 --- stdlib/_ctypes.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/_ctypes.pyi b/stdlib/_ctypes.pyi index 5313195a0ba8..985c2cb88b5e 100644 --- a/stdlib/_ctypes.pyi +++ b/stdlib/_ctypes.pyi @@ -99,6 +99,9 @@ class _Pointer(_PointerLike, _CData, Generic[_CT]): def __getitem__(self, key: slice, /) -> list[Any]: ... def __setitem__(self, key: int, value: Any, /) -> None: ... +@overload +def POINTER(type: None, /) -> type[c_void_p]: ... +@overload def POINTER(type: type[_CT], /) -> type[_Pointer[_CT]]: ... def pointer(obj: _CT, /) -> _Pointer[_CT]: ... From 61ff16ed711387096df5c285a4a5a90871cc0f04 Mon Sep 17 00:00:00 2001 From: Jun Komoda <45822440+junkmd@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:13:54 +0000 Subject: [PATCH 2/5] Update import part. --- stdlib/_ctypes.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_ctypes.pyi b/stdlib/_ctypes.pyi index 985c2cb88b5e..f4d26d05323a 100644 --- a/stdlib/_ctypes.pyi +++ b/stdlib/_ctypes.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import ReadableBuffer, WriteableBuffer from abc import abstractmethod from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence -from ctypes import CDLL, ArgumentError as ArgumentError +from ctypes import CDLL, ArgumentError as ArgumentError, c_void_p from typing import Any, ClassVar, Generic, TypeVar, overload from typing_extensions import Self, TypeAlias From ec5297955fe8d7895587fb6740e53dbb0a6e1156 Mon Sep 17 00:00:00 2001 From: Jun Komoda <45822440+junkmd@users.noreply.github.com> Date: Wed, 9 Oct 2024 12:54:33 +0000 Subject: [PATCH 3/5] Add a regression test. --- stdlib/@tests/test_cases/check_ctypes.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 stdlib/@tests/test_cases/check_ctypes.py diff --git a/stdlib/@tests/test_cases/check_ctypes.py b/stdlib/@tests/test_cases/check_ctypes.py new file mode 100644 index 000000000000..966a6462f7d7 --- /dev/null +++ b/stdlib/@tests/test_cases/check_ctypes.py @@ -0,0 +1,9 @@ +from __future__ import annotations + +import ctypes +from typing import Type +from typing_extensions import assert_type + + +assert_type(ctypes.POINTER(None), Type[ctypes.c_void_p]) +assert_type(ctypes.POINTER(ctypes.c_int), Type[ctypes._Pointer[ctypes.c_int]]) From 96566c373a4e05a2dbff622ea31a38269e172e50 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 9 Oct 2024 12:56:22 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/@tests/test_cases/check_ctypes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/stdlib/@tests/test_cases/check_ctypes.py b/stdlib/@tests/test_cases/check_ctypes.py index 966a6462f7d7..55f6e1365e57 100644 --- a/stdlib/@tests/test_cases/check_ctypes.py +++ b/stdlib/@tests/test_cases/check_ctypes.py @@ -4,6 +4,5 @@ from typing import Type from typing_extensions import assert_type - assert_type(ctypes.POINTER(None), Type[ctypes.c_void_p]) assert_type(ctypes.POINTER(ctypes.c_int), Type[ctypes._Pointer[ctypes.c_int]]) From e93791f3055ce59d40eee9861e259752d465c6af Mon Sep 17 00:00:00 2001 From: Jun Komoda <45822440+junkmd@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:15:16 +0000 Subject: [PATCH 5/5] `check_ctypes.py` -> `ctypes/check_pointer.py` --- .../test_cases/{check_ctypes.py => ctypes/check_pointer.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename stdlib/@tests/test_cases/{check_ctypes.py => ctypes/check_pointer.py} (100%) diff --git a/stdlib/@tests/test_cases/check_ctypes.py b/stdlib/@tests/test_cases/ctypes/check_pointer.py similarity index 100% rename from stdlib/@tests/test_cases/check_ctypes.py rename to stdlib/@tests/test_cases/ctypes/check_pointer.py