Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-109599: Add types.CapsuleType #109600

Merged
merged 4 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-109599: Add types.CapsuleType
  • Loading branch information
pitrou committed Sep 20, 2023
commit 563aca2a1bd03bfa7191d921a6b4d58200431080
6 changes: 6 additions & 0 deletions Doc/library/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,12 @@ Standard names are defined for the following types:

.. versionadded:: 3.12

.. class:: CapsuleType

The type of :ref:`capsule objects<capsules>`.
pitrou marked this conversation as resolved.
Show resolved Hide resolved

.. versionadded:: 3.13


Additional Utility Classes and Functions
----------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_sys.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import builtins
import codecs
import _datetime
import gc
import locale
import operator
Expand Down Expand Up @@ -1581,7 +1582,7 @@ def delx(self): del self.__x
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'))
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import collections.abc
from collections import namedtuple
import copy
import _datetime
import gc
import inspect
import pickle
Expand Down Expand Up @@ -636,6 +637,9 @@ def test_traceback_and_frame_types(self):
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):

Expand Down
4 changes: 4 additions & 0 deletions Lib/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Define names for built-in types that aren't directly accessible as a builtin.
"""

import _socket
import sys

# Iterators in Python aren't a matter of type but of protocol. A large
Expand Down Expand Up @@ -330,4 +332,6 @@ def wrapped(*args, **kwargs):
NoneType = type(None)
NotImplementedType = type(NotImplemented)

CapsuleType = type(_socket.CAPI)

__all__ = [n for n in globals() if n[:1] != '_']
Loading