mirror of
https://github.com/python/cpython.git
synced 2024-11-27 03:45:08 +08:00
gh-109599: Add types.CapsuleType (#109600)
--------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
This commit is contained in:
parent
bc06743533
commit
88a6137cdb
@ -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
|
||||
----------------------------------------
|
||||
|
@ -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'))
|
||||
|
@ -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):
|
||||
|
||||
|
@ -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']
|
||||
|
@ -0,0 +1 @@
|
||||
Expose the type of PyCapsule objects as ``types.CapsuleType``.
|
Loading…
Reference in New Issue
Block a user