Skip to content

Commit ca6251a

Browse files
authored
stdlib: new signature for CDLL in 3.12 (#13313)
1 parent ebc9ff8 commit ca6251a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import ctypes
2+
import sys
3+
from pathlib import Path
4+
from typing_extensions import assert_type
5+
6+
assert_type(ctypes.CDLL(None), ctypes.CDLL)
7+
assert_type(ctypes.CDLL("."), ctypes.CDLL)
8+
9+
# https://github.com/python/cpython/pull/7032
10+
if sys.version_info >= (3, 12):
11+
assert_type(ctypes.CDLL(Path(".")), ctypes.CDLL)

stdlib/ctypes/__init__.pyi

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ from _ctypes import (
2424
set_errno as set_errno,
2525
sizeof as sizeof,
2626
)
27+
from _typeshed import StrPath
2728
from ctypes._endian import BigEndianStructure as BigEndianStructure, LittleEndianStructure as LittleEndianStructure
2829
from typing import Any, ClassVar, Generic, TypeVar, type_check_only
2930
from typing_extensions import Self, TypeAlias, deprecated
@@ -57,6 +58,11 @@ class _CDLLFuncPointer(_CFuncPtr):
5758
class _NamedFuncPointer(_CDLLFuncPointer):
5859
__name__: str
5960

61+
if sys.version_info >= (3, 12):
62+
_NameTypes: TypeAlias = StrPath | None
63+
else:
64+
_NameTypes: TypeAlias = str | None
65+
6066
class CDLL:
6167
_func_flags_: ClassVar[int]
6268
_func_restype_: ClassVar[type[_CDataType]]
@@ -65,7 +71,7 @@ class CDLL:
6571
_FuncPtr: type[_CDLLFuncPointer]
6672
def __init__(
6773
self,
68-
name: str | None,
74+
name: _NameTypes,
6975
mode: int = ...,
7076
handle: int | None = None,
7177
use_errno: bool = False,

0 commit comments

Comments
 (0)