From d4b1b3210e96c7ad3859ab8bf70c979825fbec98 Mon Sep 17 00:00:00 2001 From: Brian Schubert Date: Sun, 6 Apr 2025 13:24:04 -0400 Subject: [PATCH 1/2] Add __class_getitem__ to ctypes.py_object --- Doc/library/ctypes.rst | 3 +++ Doc/whatsnew/3.14.rst | 4 ++++ Lib/ctypes/__init__.py | 1 + Lib/test/test_genericalias.py | 2 +- .../Library/2025-04-06-13-23-41.gh-issue-132168.6UMEpo.rst | 2 ++ 5 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2025-04-06-13-23-41.gh-issue-132168.6UMEpo.rst 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..41984f150d82d8 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -434,6 +434,10 @@ Other language changes making it a :term:`generic type`. (Contributed by Brian Schubert in :gh:`126012`.) +* The :class:`ctypes.py_object` type now supports subscription, + making it a :term:`generic type`. + (Contributed by Brian Schubert in :gh:`132168`.) + * Support underscore and comma as thousands separators in the fractional part for floating-point presentation types of the new-style string formatting (with :func:`format` or :ref:`f-strings`). 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()" % 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`. From 707c8a15173b9b92c78ff75359fd6b70912d5c15 Mon Sep 17 00:00:00 2001 From: Brian Schubert Date: Sun, 6 Apr 2025 14:51:24 -0400 Subject: [PATCH 2/2] Move whatsnew entry to ctypes --- Doc/whatsnew/3.14.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 41984f150d82d8..3223dde270f60b 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -434,10 +434,6 @@ Other language changes making it a :term:`generic type`. (Contributed by Brian Schubert in :gh:`126012`.) -* The :class:`ctypes.py_object` type now supports subscription, - making it a :term:`generic type`. - (Contributed by Brian Schubert in :gh:`132168`.) - * Support underscore and comma as thousands separators in the fractional part for floating-point presentation types of the new-style string formatting (with :func:`format` or :ref:`f-strings`). @@ -626,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 -------- 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