From 2a030be2e9caa1384f1ad8888310e6d8339962e8 Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Thu, 9 Jan 2025 19:03:56 -0800 Subject: [PATCH] fix ctypes.GetLastError (#13379) --- stdlib/@tests/stubtest_allowlists/win32.txt | 1 - stdlib/ctypes/__init__.pyi | 9 ++++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/win32.txt b/stdlib/@tests/stubtest_allowlists/win32.txt index 2dd91482f..ec42a17db 100644 --- a/stdlib/@tests/stubtest_allowlists/win32.txt +++ b/stdlib/@tests/stubtest_allowlists/win32.txt @@ -2,7 +2,6 @@ # TODO: Allowlist entries that should be fixed # ============================================ -ctypes.GetLastError # Is actually a pointer # alias for a class defined elsewhere, # mypy infers the variable has type `(*args) -> DupHandle` but stubtest infers the runtime type as multiprocessing.reduction.AbstractReducer.DupHandle diff --git a/stdlib/ctypes/__init__.pyi b/stdlib/ctypes/__init__.pyi index 5533a2277..4f44975d6 100644 --- a/stdlib/ctypes/__init__.pyi +++ b/stdlib/ctypes/__init__.pyi @@ -159,7 +159,14 @@ def ARRAY(typ: _CT, len: int) -> Array[_CT]: ... # Soft Deprecated, no plans to if sys.platform == "win32": def DllCanUnloadNow() -> int: ... def DllGetClassObject(rclsid: Any, riid: Any, ppv: Any) -> int: ... # TODO not documented - def GetLastError() -> int: ... + + # Actually just an instance of _NamedFuncPointer (aka _CDLLFuncPointer), + # but we want to set a more specific __call__ + @type_check_only + class _GetLastErrorFunctionType(_NamedFuncPointer): + def __call__(self) -> int: ... + + GetLastError: _GetLastErrorFunctionType # Actually just an instance of _CFunctionType, but we want to set a more # specific __call__.