]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109599: Add types.CapsuleType (#109600)
authorAntoine Pitrou <antoine@python.org>
Mon, 25 Sep 2023 17:50:39 +0000 (19:50 +0200)
committerGitHub <noreply@github.com>
Mon, 25 Sep 2023 17:50:39 +0000 (19:50 +0200)
---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Doc/library/types.rst
Lib/test/test_sys.py
Lib/test/test_types.py
Lib/types.py
Misc/NEWS.d/next/Library/2023-09-20-07-38-14.gh-issue-109599.IaSLJz.rst [new file with mode: 0644]

index 875916be1049a31794f628070e0fe61070405a53..54c3907dec98ccba380f72ed95538577da253606 100644 (file)
@@ -472,6 +472,12 @@ Standard names are defined for the following types:
 
       .. versionadded:: 3.12
 
+.. class:: CapsuleType
+
+   The type of :ref:`capsule objects <capsules>`.
+
+   .. versionadded:: 3.13
+
 
 Additional Utility Classes and Functions
 ----------------------------------------
index f4948ceec66226d7ed71a8af80c5aa65bd2acf35..c616a27364b494ab84736c4c3f3f51526226b4aa 100644 (file)
@@ -1,5 +1,6 @@
 import builtins
 import codecs
+import _datetime
 import gc
 import locale
 import operator
@@ -1581,7 +1582,7 @@ class SizeofTest(unittest.TestCase):
             x = property(getx, setx, delx, "")
             check(x, size('5Pi'))
         # PyCapsule
-        # XXX
+        check(_datetime.datetime_CAPI, size('6P'))
         # rangeiterator
         check(iter(range(1)), size('3l'))
         check(iter(range(2**65)), size('3P'))
index c6bff79f9038283d902209768d190c4c1e8282fc..da32c4ea6477ced9b5d499c714f6d1db0d3be41e 100644 (file)
@@ -4,6 +4,7 @@ from test.support import run_with_locale, cpython_only
 import collections.abc
 from collections import namedtuple
 import copy
+import _datetime
 import gc
 import inspect
 import pickle
@@ -636,6 +637,9 @@ class TypesTests(unittest.TestCase):
         self.assertIsInstance(exc.__traceback__, types.TracebackType)
         self.assertIsInstance(exc.__traceback__.tb_frame, types.FrameType)
 
+    def test_capsule_type(self):
+        self.assertIsInstance(_datetime.datetime_CAPI, types.CapsuleType)
+
 
 class UnionTests(unittest.TestCase):
 
index b4aa19cec40c8986f911b653a43c60afd8c37a66..1484c22ee9dffab216d187a8a20fd61351621855 100644 (file)
@@ -1,6 +1,7 @@
 """
 Define names for built-in types that aren't directly accessible as a builtin.
 """
+
 import sys
 
 # Iterators in Python aren't a matter of type but of protocol.  A large
@@ -330,4 +331,11 @@ EllipsisType = type(Ellipsis)
 NoneType = type(None)
 NotImplementedType = type(NotImplemented)
 
+def __getattr__(name):
+    if name == 'CapsuleType':
+        import _socket
+        return type(_socket.CAPI)
+    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
+
 __all__ = [n for n in globals() if n[:1] != '_']
+__all__ += ['CapsuleType']
diff --git a/Misc/NEWS.d/next/Library/2023-09-20-07-38-14.gh-issue-109599.IaSLJz.rst b/Misc/NEWS.d/next/Library/2023-09-20-07-38-14.gh-issue-109599.IaSLJz.rst
new file mode 100644 (file)
index 0000000..8a15e76
--- /dev/null
@@ -0,0 +1 @@
+Expose the type of PyCapsule objects as ``types.CapsuleType``.