Skip to content

Commit 596d359

Browse files
committed
Merge branch 'main' into gh-139103-named-tuple
2 parents f09d89a + 67ddba9 commit 596d359

File tree

90 files changed

+3884
-2280
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+3884
-2280
lines changed

Doc/c-api/intro.rst

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,35 @@ complete listing.
167167

168168
.. versionadded:: 3.3
169169

170+
.. c:macro:: Py_ALIGNED(num)
171+
172+
Specify alignment to *num* bytes on compilers that support it.
173+
174+
Consider using the C11 standard ``_Alignas`` specifier over this macro.
175+
176+
.. c:macro:: Py_ARITHMETIC_RIGHT_SHIFT(type, integer, positions)
177+
178+
Similar to ``integer >> positions``, but forces sign extension, as the C
179+
standard does not define whether a right-shift of a signed integer will
180+
perform sign extension or a zero-fill.
181+
182+
*integer* should be any signed integer type.
183+
*positions* is the number of positions to shift to the right.
184+
185+
Both *integer* and *positions* can be evaluated more than once;
186+
consequently, avoid directly passing a function call or some other
187+
operation with side-effects to this macro. Instead, store the result as a
188+
variable and then pass it.
189+
190+
*type* is unused and only kept for backwards compatibility. Historically,
191+
*type* was used to cast *integer*.
192+
193+
.. versionchanged:: 3.1
194+
195+
This macro is now valid for all signed integer types, not just those for
196+
which ``unsigned type`` is legal. As a result, *type* is no longer
197+
used.
198+
170199
.. c:macro:: Py_ALWAYS_INLINE
171200
172201
Ask the compiler to always inline a static inline function. The compiler can
@@ -189,6 +218,15 @@ complete listing.
189218

190219
.. versionadded:: 3.11
191220

221+
.. c:macro:: Py_CAN_START_THREADS
222+
223+
If this macro is defined, then the current system is able to start threads.
224+
225+
Currently, all systems supported by CPython (per :pep:`11`), with the
226+
exception of some WebAssembly platforms, support starting threads.
227+
228+
.. versionadded:: 3.13
229+
192230
.. c:macro:: Py_CHARMASK(c)
193231
194232
Argument must be a character or an integer in the range [-128, 127] or [0,
@@ -206,11 +244,35 @@ complete listing.
206244
.. versionchanged:: 3.8
207245
MSVC support was added.
208246

247+
.. c:macro:: Py_FORCE_EXPANSION(X)
248+
249+
This is equivalent to ``X``, which is useful for token-pasting in
250+
macros, as macro expansions in *X* are forcefully evaluated by the
251+
preprocessor.
252+
253+
.. c:macro:: Py_GCC_ATTRIBUTE(name)
254+
255+
Use a GCC attribute *name*, hiding it from compilers that don't support GCC
256+
attributes (such as MSVC).
257+
258+
This expands to ``__attribute__((name))`` on a GCC compiler, and expands
259+
to nothing on compilers that don't support GCC attributes.
260+
209261
.. c:macro:: Py_GETENV(s)
210262
211263
Like ``getenv(s)``, but returns ``NULL`` if :option:`-E` was passed on the
212264
command line (see :c:member:`PyConfig.use_environment`).
213265

266+
.. c:macro:: Py_LL(number)
267+
268+
Use *number* as a ``long long`` integer literal.
269+
270+
This usally expands to *number* followed by ``LL``, but will expand to some
271+
compiler-specific suffixes (such as ``I64``) on older compilers.
272+
273+
In modern versions of Python, this macro is not very useful, as C99 and
274+
later require the ``LL`` suffix to be valid for an integer.
275+
214276
.. c:macro:: Py_LOCAL(type)
215277
216278
Declare a function returning the specified *type* using a fast-calling
@@ -268,13 +330,37 @@ complete listing.
268330

269331
.. versionadded:: 3.11
270332

333+
.. c:macro:: Py_SAFE_DOWNCAST(value, larger, smaller)
334+
335+
Cast *value* to type *smaller* from type *larger*, validating that no
336+
information was lost.
337+
338+
On release builds of Python, this is roughly equivalent to
339+
``(smaller) value`` (in C++, ``static_cast<smaller>(value)`` will be
340+
used instead).
341+
342+
On debug builds (implying that :c:macro:`Py_DEBUG` is defined), this asserts
343+
that no information was lost with the cast from *larger* to *smaller*.
344+
345+
*value*, *larger*, and *smaller* may all be evaluated more than once in the
346+
expression; consequently, do not pass an expression with side-effects directly to
347+
this macro.
348+
271349
.. c:macro:: Py_STRINGIFY(x)
272350
273351
Convert ``x`` to a C string. E.g. ``Py_STRINGIFY(123)`` returns
274352
``"123"``.
275353

276354
.. versionadded:: 3.4
277355

356+
.. c:macro:: Py_ULL(number)
357+
358+
Similar to :c:macro:`Py_LL`, but *number* will be an ``unsigned long long``
359+
literal instead. This is done by appending ``U`` to the result of ``Py_LL``.
360+
361+
In modern versions of Python, this macro is not very useful, as C99 and
362+
later require the ``ULL``/``LLU`` suffixes to be valid for an integer.
363+
278364
.. c:macro:: Py_UNREACHABLE()
279365
280366
Use this when you have a code path that cannot be reached by design.
@@ -415,6 +501,16 @@ complete listing.
415501
This macro is intended for defining CPython's C API itself;
416502
extension modules should not use it for their own symbols.
417503

504+
.. c:macro:: Py_VA_COPY
505+
506+
This is a :term:`soft deprecated` alias to the C99-standard ``va_copy``
507+
function.
508+
509+
Historically, this would use a compiler-specific method to copy a ``va_list``.
510+
511+
.. versionchanged:: 3.6
512+
This is now an alias to ``va_copy``.
513+
418514

419515
.. _api-objects:
420516

Doc/glossary.rst

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,19 @@ Glossary
786786
An object that both finds and loads a module; both a
787787
:term:`finder` and :term:`loader` object.
788788

789+
index
790+
A numeric value that represents the position of an element in
791+
a :term:`sequence`.
792+
793+
In Python, indexing starts at zero.
794+
For example, ``things[0]`` names the *first* element of ``things``;
795+
``things[1]`` names the second one.
796+
797+
In some contexts, Python allows negative indexes for counting from the
798+
end of a sequence, and indexing using :term:`slices <slice>`.
799+
800+
See also :term:`subscript`.
801+
789802
interactive
790803
Python has an interactive interpreter which means you can enter
791804
statements and expressions at the interpreter prompt, immediately
@@ -863,6 +876,9 @@ Glossary
863876
CPython does not guarantee :term:`thread-safe` behavior of iterator
864877
operations.
865878

879+
key
880+
A value that identifies an entry in a :term:`mapping`.
881+
See also :term:`subscript`.
866882

867883
key function
868884
A key function or collation function is a callable that returns a value
@@ -1417,10 +1433,11 @@ Glossary
14171433
chosen based on the type of a single argument.
14181434

14191435
slice
1420-
An object usually containing a portion of a :term:`sequence`. A slice is
1421-
created using the subscript notation, ``[]`` with colons between numbers
1422-
when several are given, such as in ``variable_name[1:3:5]``. The bracket
1423-
(subscript) notation uses :class:`slice` objects internally.
1436+
An object of type :class:`slice`, used to describe a portion of
1437+
a :term:`sequence`.
1438+
A slice object is created when using the :ref:`slicing <slicings>` form
1439+
of :ref:`subscript notation <subscriptions>`, with colons inside square
1440+
brackets, such as in ``variable_name[1:3:5]``.
14241441

14251442
soft deprecated
14261443
A soft deprecated API should not be used in new code,
@@ -1478,6 +1495,14 @@ Glossary
14781495

14791496
See also :term:`borrowed reference`.
14801497

1498+
subscript
1499+
The expression in square brackets of a
1500+
:ref:`subscription expression <subscriptions>`, for example,
1501+
the ``3`` in ``items[3]``.
1502+
Usually used to select an element of a container.
1503+
Also called a :term:`key` when subscripting a :term:`mapping`,
1504+
or an :term:`index` when subscripting a :term:`sequence`.
1505+
14811506
synchronization primitive
14821507
A basic building block for coordinating (synchronizing) the execution of
14831508
multiple threads to ensure :term:`thread-safe` access to shared resources.

Doc/library/contextlib.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,10 @@ Functions and classes provided:
564564
Raises :exc:`TypeError` instead of :exc:`AttributeError` if *cm*
565565
is not a context manager.
566566

567+
.. versionchanged:: next
568+
Added support for arbitrary descriptors :meth:`!__enter__` and
569+
:meth:`!__exit__`.
570+
567571
.. method:: push(exit)
568572

569573
Adds a context manager's :meth:`~object.__exit__` method to the callback stack.
@@ -582,6 +586,9 @@ Functions and classes provided:
582586
The passed in object is returned from the function, allowing this
583587
method to be used as a function decorator.
584588

589+
.. versionchanged:: next
590+
Added support for arbitrary descriptors :meth:`!__exit__`.
591+
585592
.. method:: callback(callback, /, *args, **kwds)
586593

587594
Accepts an arbitrary callback function and arguments and adds it to
@@ -639,11 +646,17 @@ Functions and classes provided:
639646
Raises :exc:`TypeError` instead of :exc:`AttributeError` if *cm*
640647
is not an asynchronous context manager.
641648

649+
.. versionchanged:: next
650+
Added support for arbitrary descriptors :meth:`!__aenter__` and :meth:`!__aexit__`.
651+
642652
.. method:: push_async_exit(exit)
643653

644654
Similar to :meth:`ExitStack.push` but expects either an asynchronous context manager
645655
or a coroutine function.
646656

657+
.. versionchanged:: next
658+
Added support for arbitrary descriptors :meth:`!__aexit__`.
659+
647660
.. method:: push_async_callback(callback, /, *args, **kwds)
648661

649662
Similar to :meth:`ExitStack.callback` but expects a coroutine function.

Doc/library/functions.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,19 +1824,19 @@ are always available. They are listed here in alphabetical order.
18241824
``range(start, stop, step)``. The *start* and *step* arguments default to
18251825
``None``.
18261826

1827-
Slice objects have read-only data attributes :attr:`!start`,
1828-
:attr:`!stop`, and :attr:`!step` which merely return the argument
1829-
values (or their default). They have no other explicit functionality;
1830-
however, they are used by NumPy and other third-party packages.
1827+
Slice objects are also generated when :ref:`slicing syntax <slicings>`
1828+
is used. For example: ``a[start:stop:step]`` or ``a[start:stop, i]``.
1829+
1830+
See :func:`itertools.islice` for an alternate version that returns an
1831+
:term:`iterator`.
18311832

18321833
.. attribute:: slice.start
1833-
.. attribute:: slice.stop
1834-
.. attribute:: slice.step
1834+
slice.stop
1835+
slice.step
18351836

1836-
Slice objects are also generated when extended indexing syntax is used. For
1837-
example: ``a[start:stop:step]`` or ``a[start:stop, i]``. See
1838-
:func:`itertools.islice` for an alternate version that returns an
1839-
:term:`iterator`.
1837+
These read-only attributes are set to the argument values
1838+
(or their default). They have no other explicit functionality;
1839+
however, they are used by NumPy and other third-party packages.
18401840

18411841
.. versionchanged:: 3.12
18421842
Slice objects are now :term:`hashable` (provided :attr:`~slice.start`,

Doc/library/inspect.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
262262
| | | ``yield from``, or |
263263
| | | ``None`` |
264264
+-----------------+-------------------+---------------------------+
265+
| | gi_state | state of the generator, |
266+
| | | one of ``GEN_CREATED``, |
267+
| | | ``GEN_RUNNING``, |
268+
| | | ``GEN_SUSPENDED``, or |
269+
| | | ``GEN_CLOSED`` |
270+
+-----------------+-------------------+---------------------------+
265271
| async generator | __name__ | name |
266272
+-----------------+-------------------+---------------------------+
267273
| | __qualname__ | qualified name |
@@ -278,6 +284,13 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
278284
+-----------------+-------------------+---------------------------+
279285
| | ag_code | code |
280286
+-----------------+-------------------+---------------------------+
287+
| | ag_state | state of the async |
288+
| | | generator, one of |
289+
| | | ``AGEN_CREATED``, |
290+
| | | ``AGEN_RUNNING``, |
291+
| | | ``AGEN_SUSPENDED``, or |
292+
| | | ``AGEN_CLOSED`` |
293+
+-----------------+-------------------+---------------------------+
281294
| coroutine | __name__ | name |
282295
+-----------------+-------------------+---------------------------+
283296
| | __qualname__ | qualified name |
@@ -298,6 +311,12 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
298311
| | | created, or ``None``. See |
299312
| | | |coroutine-origin-link| |
300313
+-----------------+-------------------+---------------------------+
314+
| | cr_state | state of the coroutine, |
315+
| | | one of ``CORO_CREATED``, |
316+
| | | ``CORO_RUNNING``, |
317+
| | | ``CORO_SUSPENDED``, or |
318+
| | | ``CORO_CLOSED`` |
319+
+-----------------+-------------------+---------------------------+
301320
| builtin | __doc__ | documentation string |
302321
+-----------------+-------------------+---------------------------+
303322
| | __name__ | original name of this |
@@ -341,6 +360,11 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
341360

342361
Add ``f_generator`` attribute to frames.
343362

363+
.. versionchanged:: next
364+
365+
Add ``gi_state`` attribute to generators, ``cr_state`` attribute to
366+
coroutines, and ``ag_state`` attribute to async generators.
367+
344368
.. function:: getmembers(object[, predicate])
345369

346370
Return all the members of an object in a list of ``(name, value)``

0 commit comments

Comments
 (0)