gh-132168: Add `__class_getitem__` to `ctypes.py_object` (#132169)

This commit is contained in:
Brian Schubert 2025-04-06 17:05:19 -04:00 committed by GitHub
parent 0788948dcb
commit e2476398ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 12 additions and 1 deletions

View File

@ -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.

View File

@ -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
--------

View File

@ -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):

View File

@ -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))

View File

@ -0,0 +1,2 @@
The :class:`ctypes.py_object` type now supports subscription, making it a
:term:`generic type`.