Skip to content

Commit e247639

Browse files
gh-132168: Add __class_getitem__ to ctypes.py_object (#132169)
1 parent 0788948 commit e247639

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

Doc/library/ctypes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,6 +2632,9 @@ These are the fundamental ctypes data types:
26322632
Represents the C :c:expr:`PyObject *` datatype. Calling this without an
26332633
argument creates a ``NULL`` :c:expr:`PyObject *` pointer.
26342634

2635+
.. versionchanged:: next
2636+
:class:`!py_object` is now a :term:`generic type`.
2637+
26352638
The :mod:`!ctypes.wintypes` module provides quite some other Windows specific
26362639
data types, for example :c:type:`!HWND`, :c:type:`!WPARAM`, or :c:type:`!DWORD`.
26372640
Some useful structures like :c:type:`!MSG` or :c:type:`!RECT` are also defined.

Doc/whatsnew/3.14.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,11 @@ ctypes
622622
loaded by the current process.
623623
(Contributed by Brian Ward in :gh:`119349`.)
624624

625+
* The :class:`ctypes.py_object` type now supports subscription,
626+
making it a :term:`generic type`.
627+
(Contributed by Brian Schubert in :gh:`132168`.)
628+
629+
625630
datetime
626631
--------
627632

Lib/ctypes/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def __repr__(self):
162162
return super().__repr__()
163163
except ValueError:
164164
return "%s(<NULL>)" % type(self).__name__
165+
__class_getitem__ = classmethod(_types.GenericAlias)
165166
_check_size(py_object, "P")
166167

167168
class c_short(_SimpleCData):

Lib/test/test_genericalias.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class BaseTest(unittest.TestCase):
139139
DictReader, DictWriter,
140140
array]
141141
if ctypes is not None:
142-
generic_types.extend((ctypes.Array, ctypes.LibraryLoader))
142+
generic_types.extend((ctypes.Array, ctypes.LibraryLoader, ctypes.py_object))
143143
if ValueProxy is not None:
144144
generic_types.extend((ValueProxy, DictProxy, ListProxy, ApplyResult,
145145
MPSimpleQueue, MPQueue, MPJoinableQueue))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The :class:`ctypes.py_object` type now supports subscription, making it a
2+
:term:`generic type`.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy