summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <antoine@python.org>2023-09-25 17:50:39 (GMT)
committerGitHub <noreply@github.com>2023-09-25 17:50:39 (GMT)
commit88a6137cdb81c80440d9d1ee7dee17ea0b820f11 (patch)
tree270d9673418978c1344c8061d65e0f9ceb9df619 /Lib
parentbc06743533b5fea2d5ecdad6dd3caa372c67439f (diff)
downloadcpython-88a6137cdb81c80440d9d1ee7dee17ea0b820f11.zip
cpython-88a6137cdb81c80440d9d1ee7dee17ea0b820f11.tar.gz
cpython-88a6137cdb81c80440d9d1ee7dee17ea0b820f11.tar.bz2
gh-109599: Add types.CapsuleType (#109600)
--------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_sys.py3
-rw-r--r--Lib/test/test_types.py4
-rw-r--r--Lib/types.py8
3 files changed, 14 insertions, 1 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index f4948ce..c616a27 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -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'))
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index c6bff79..da32c4e 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -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):
diff --git a/Lib/types.py b/Lib/types.py
index b4aa19c..1484c22 100644
--- a/Lib/types.py
+++ b/Lib/types.py
@@ -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']