https://github.com/python/cpython/commit/e2476398ee9911b6b0b80e3ca182647805fde81f
commit: e2476398ee9911b6b0b80e3ca182647805fde81f
branch: main
author: Brian Schubert <[email protected]>
committer: AA-Turner <[email protected]>
date: 2025-04-06T22:05:19+01:00
summary:
gh-132168: Add `__class_getitem__` to `ctypes.py_object` (#132169)
files:
A Misc/NEWS.d/next/Library/2025-04-06-13-23-41.gh-issue-132168.6UMEpo.rst
M Doc/library/ctypes.rst
M Doc/whatsnew/3.14.rst
M Lib/ctypes/__init__.py
M Lib/test/test_genericalias.py
diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst
index 1a7b456a8fc6ab..a550da9c976696 100644
--- a/Doc/library/ctypes.rst
+++ b/Doc/library/ctypes.rst
@@ -2632,6 +2632,9 @@ These are the fundamental ctypes data types:
Represents the C :c:expr:`PyObject *` datatype. Calling this without an
argument creates a ``NULL`` :c:expr:`PyObject *` pointer.
+ .. versionchanged:: next
+ :class:`!py_object` is now a :term:`generic type`.
+
The :mod:`!ctypes.wintypes` module provides quite some other Windows specific
data types, for example :c:type:`!HWND`, :c:type:`!WPARAM`, or
:c:type:`!DWORD`.
Some useful structures like :c:type:`!MSG` or :c:type:`!RECT` are also defined.
diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst
index de76e253eb9264..3223dde270f60b 100644
--- a/Doc/whatsnew/3.14.rst
+++ b/Doc/whatsnew/3.14.rst
@@ -622,6 +622,11 @@ ctypes
loaded by the current process.
(Contributed by Brian Ward in :gh:`119349`.)
+* The :class:`ctypes.py_object` type now supports subscription,
+ making it a :term:`generic type`.
+ (Contributed by Brian Schubert in :gh:`132168`.)
+
+
datetime
--------
diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py
index d9e55816211737..bba08b99b95b8b 100644
--- a/Lib/ctypes/__init__.py
+++ b/Lib/ctypes/__init__.py
@@ -162,6 +162,7 @@ def __repr__(self):
return super().__repr__()
except ValueError:
return "%s(<NULL>)" % type(self).__name__
+ __class_getitem__ = classmethod(_types.GenericAlias)
_check_size(py_object, "P")
class c_short(_SimpleCData):
diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py
index 61547d98ba6666..5c13897b8d9d4f 100644
--- a/Lib/test/test_genericalias.py
+++ b/Lib/test/test_genericalias.py
@@ -139,7 +139,7 @@ class BaseTest(unittest.TestCase):
DictReader, DictWriter,
array]
if ctypes is not None:
- generic_types.extend((ctypes.Array, ctypes.LibraryLoader))
+ generic_types.extend((ctypes.Array, ctypes.LibraryLoader,
ctypes.py_object))
if ValueProxy is not None:
generic_types.extend((ValueProxy, DictProxy, ListProxy, ApplyResult,
MPSimpleQueue, MPQueue, MPJoinableQueue))
diff --git
a/Misc/NEWS.d/next/Library/2025-04-06-13-23-41.gh-issue-132168.6UMEpo.rst
b/Misc/NEWS.d/next/Library/2025-04-06-13-23-41.gh-issue-132168.6UMEpo.rst
new file mode 100644
index 00000000000000..5e8f95b18921c7
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-04-06-13-23-41.gh-issue-132168.6UMEpo.rst
@@ -0,0 +1,2 @@
+The :class:`ctypes.py_object` type now supports subscription, making it a
+:term:`generic type`.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]