Skip to content

Commit fe3b79c

Browse files
committed
Deploying to gh-pages from @ 6a2f51a 🚀
1 parent 9c0ad00 commit fe3b79c

File tree

603 files changed

+7306
-6308
lines changed

Some content is hidden

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

603 files changed

+7306
-6308
lines changed

.buildinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Sphinx build info version 1
22
# This file records the configuration used when building these files. When it is not found, a full rebuild will be done.
33
config: 027112e6b110a6ec310dc8c74832cccb
4-
tags: 645f666f9bcd5a90fca523b33c5a78b7
4+
tags: b5e2c454ba7771976391ed0cecdde553

_sources/bugs.rst.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ If you find a bug in this documentation or would like to propose an improvement,
1919
please submit a bug report on the :ref:`issue tracker <using-the-tracker>`. If you
2020
have a suggestion on how to fix it, include that as well.
2121

22+
.. only:: translation
23+
24+
If the bug or suggested improvement concerns the translation of this
25+
documentation, submit the report to the
26+
`translation’s repository <TRANSLATION_REPO_>`_ instead.
27+
2228
You can also open a discussion item on our
2329
`Documentation Discourse forum <https://discuss.python.org/c/documentation/26>`_.
2430

_sources/c-api/init.rst.txt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ code, or when embedding the Python interpreter:
12781278
This function is safe to call without an :term:`attached thread state`; it
12791279
will simply return ``NULL`` indicating that there was no prior thread state.
12801280
1281-
.. seealso:
1281+
.. seealso::
12821282
:c:func:`PyEval_ReleaseThread`
12831283
12841284
.. note::
@@ -1289,6 +1289,19 @@ code, or when embedding the Python interpreter:
12891289
The following functions use thread-local storage, and are not compatible
12901290
with sub-interpreters:
12911291
1292+
.. c:type:: PyGILState_STATE
1293+
1294+
The type of the value returned by :c:func:`PyGILState_Ensure` and passed to
1295+
:c:func:`PyGILState_Release`.
1296+
1297+
.. c:enumerator:: PyGILState_LOCKED
1298+
1299+
The GIL was already held when :c:func:`PyGILState_Ensure` was called.
1300+
1301+
.. c:enumerator:: PyGILState_UNLOCKED
1302+
1303+
The GIL was not held when :c:func:`PyGILState_Ensure` was called.
1304+
12921305
.. c:function:: PyGILState_STATE PyGILState_Ensure()
12931306
12941307
Ensure that the current thread is ready to call the Python C API regardless
@@ -1339,12 +1352,12 @@ with sub-interpreters:
13391352
made on the main thread. This is mainly a helper/diagnostic function.
13401353
13411354
.. note::
1342-
This function does not account for :term:`thread states <thread state>` created
1343-
by something other than :c:func:`PyGILState_Ensure` (such as :c:func:`PyThreadState_New`).
1355+
This function may return non-``NULL`` even when the :term:`thread state`
1356+
is detached.
13441357
Prefer :c:func:`PyThreadState_Get` or :c:func:`PyThreadState_GetUnchecked`
13451358
for most cases.
13461359
1347-
.. seealso: :c:func:`PyThreadState_Get``
1360+
.. seealso:: :c:func:`PyThreadState_Get`
13481361
13491362
.. c:function:: int PyGILState_Check()
13501363
@@ -1443,11 +1456,11 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
14431456
must be :term:`attached <attached thread state>`
14441457
14451458
.. versionchanged:: 3.9
1446-
This function now calls the :c:member:`PyThreadState.on_delete` callback.
1459+
This function now calls the :c:member:`!PyThreadState.on_delete` callback.
14471460
Previously, that happened in :c:func:`PyThreadState_Delete`.
14481461
14491462
.. versionchanged:: 3.13
1450-
The :c:member:`PyThreadState.on_delete` callback was removed.
1463+
The :c:member:`!PyThreadState.on_delete` callback was removed.
14511464
14521465
14531466
.. c:function:: void PyThreadState_Delete(PyThreadState *tstate)

_sources/c-api/object.rst.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ Object Protocol
585585
586586
Clear the managed dictionary of *obj*.
587587
588-
This function must only be called in a traverse function of the type which
588+
This function must only be called in a clear function of the type which
589589
has the :c:macro:`Py_TPFLAGS_MANAGED_DICT` flag set.
590590
591591
.. versionadded:: 3.13

_sources/c-api/typeobj.rst.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
16911691
:c:func:`Py_CLEAR` macro performs the operations in a safe order.
16921692

16931693
If the :c:macro:`Py_TPFLAGS_MANAGED_DICT` bit is set in the
1694-
:c:member:`~PyTypeObject.tp_flags` field, the traverse function must call
1694+
:c:member:`~PyTypeObject.tp_flags` field, the clear function must call
16951695
:c:func:`PyObject_ClearManagedDict` like this::
16961696

16971697
PyObject_ClearManagedDict((PyObject*)self);

_sources/faq/general.rst.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ How do I get documentation on Python?
186186
-------------------------------------
187187

188188
The standard documentation for the current stable version of Python is available
189-
at https://docs.python.org/3/. PDF, plain text, and downloadable HTML versions are
189+
at https://docs.python.org/3/. EPUB, plain text, and downloadable HTML versions are
190190
also available at https://docs.python.org/3/download.html.
191191

192192
The documentation is written in reStructuredText and processed by `the Sphinx

_sources/howto/a-conceptual-overview-of-asyncio.rst.txt

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ model of how :mod:`asyncio` fundamentally works, helping you understand the
99
how and why behind the recommended patterns.
1010

1111
You might be curious about some key :mod:`!asyncio` concepts.
12-
You'll be comfortably able to answer these questions by the end of this
13-
article:
12+
By the end of this article, you'll be able to comfortably answer these questions:
1413

1514
- What's happening behind the scenes when an object is awaited?
1615
- How does :mod:`!asyncio` differentiate between a task which doesn't need
17-
CPU-time (such as a network request or file read) as opposed to a task that
16+
CPU time (such as a network request or file read) as opposed to a task that
1817
does (such as computing n-factorial)?
1918
- How to write an asynchronous variant of an operation, such as
2019
an async sleep or database request.
@@ -35,7 +34,7 @@ A conceptual overview part 1: the high-level
3534
--------------------------------------------
3635

3736
In part 1, we'll cover the main, high-level building blocks of :mod:`!asyncio`:
38-
the event loop, coroutine functions, coroutine objects, tasks and ``await``.
37+
the event loop, coroutine functions, coroutine objects, tasks, and ``await``.
3938

4039
==========
4140
Event Loop
@@ -56,7 +55,7 @@ Once it pauses or completes, it returns control to the event loop.
5655
The event loop will then select another job from its pool and invoke it.
5756
You can *roughly* think of the collection of jobs as a queue: jobs are added and
5857
then processed one at a time, generally (but not always) in order.
59-
This process repeats indefinitely with the event loop cycling endlessly
58+
This process repeats indefinitely, with the event loop cycling endlessly
6059
onwards.
6160
If there are no more jobs pending execution, the event loop is smart enough to
6261
rest and avoid needlessly wasting CPU cycles, and will come back when there's
@@ -276,7 +275,7 @@ in this case, a call to resume ``plant_a_tree()``.
276275

277276
Generally speaking, when the awaited task finishes (``dig_the_hole_task``),
278277
the original task or coroutine (``plant_a_tree()``) is added back to the event
279-
loops to-do list to be resumed.
278+
loop's to-do list to be resumed.
280279

281280
This is a basic, yet reliable mental model.
282281
In practice, the control handoffs are slightly more complex, but not by much.
@@ -310,7 +309,7 @@ Consider this program::
310309
The first statement in the coroutine ``main()`` creates ``task_b`` and schedules
311310
it for execution via the event loop.
312311
Then, ``coro_a()`` is repeatedly awaited. Control never cedes to the
313-
event loop which is why we see the output of all three ``coro_a()``
312+
event loop, which is why we see the output of all three ``coro_a()``
314313
invocations before ``coro_b()``'s output:
315314

316315
.. code-block:: none
@@ -338,8 +337,8 @@ This behavior of ``await coroutine`` can trip a lot of people up!
338337
That example highlights how using only ``await coroutine`` could
339338
unintentionally hog control from other tasks and effectively stall the event
340339
loop.
341-
:func:`asyncio.run` can help you detect such occurences via the
342-
``debug=True`` flag which accordingly enables
340+
:func:`asyncio.run` can help you detect such occurrences via the
341+
``debug=True`` flag, which enables
343342
:ref:`debug mode <asyncio-debug-mode>`.
344343
Among other things, it will log any coroutines that monopolize execution for
345344
100ms or longer.
@@ -348,8 +347,8 @@ The design intentionally trades off some conceptual clarity around usage of
348347
``await`` for improved performance.
349348
Each time a task is awaited, control needs to be passed all the way up the
350349
call stack to the event loop.
351-
That might sound minor, but in a large program with many ``await``'s and a deep
352-
callstack that overhead can add up to a meaningful performance drag.
350+
That might sound minor, but in a large program with many ``await`` statements and a deep
351+
call stack, that overhead can add up to a meaningful performance drag.
353352

354353
------------------------------------------------
355354
A conceptual overview part 2: the nuts and bolts
@@ -372,7 +371,7 @@ resume a coroutine.
372371
If the coroutine was paused and is now being resumed, the argument ``arg``
373372
will be sent in as the return value of the ``yield`` statement which originally
374373
paused it.
375-
If the coroutine is being used for the first time (as opposed to being resumed)
374+
If the coroutine is being used for the first time (as opposed to being resumed),
376375
``arg`` must be ``None``.
377376

378377
.. code-block::
@@ -403,14 +402,14 @@ If the coroutine is being used for the first time (as opposed to being resumed)
403402
returned_value = e.value
404403
print(f"Coroutine main() finished and provided value: {returned_value}.")
405404
406-
:ref:`yield <yieldexpr>`, like usual, pauses execution and returns control
405+
:ref:`yield <yieldexpr>`, as usual, pauses execution and returns control
407406
to the caller.
408407
In the example above, the ``yield``, on line 3, is called by
409408
``... = await rock`` on line 11.
410409
More broadly speaking, ``await`` calls the :meth:`~object.__await__` method of
411410
the given object.
412411
``await`` also does one more very special thing: it propagates (or "passes
413-
along") any ``yield``\ s it receives up the call-chain.
412+
along") any ``yield``\ s it receives up the call chain.
414413
In this case, that's back to ``... = coroutine.send(None)`` on line 16.
415414

416415
The coroutine is resumed via the ``coroutine.send(42)`` call on line 21.
@@ -462,12 +461,12 @@ computation's status and result.
462461
The term is a nod to the idea of something still to come or not yet happened,
463462
and the object is a way to keep an eye on that something.
464463

465-
A future has a few important attributes. One is its state which can be either
466-
"pending", "cancelled" or "done".
464+
A future has a few important attributes. One is its state, which can be either
465+
"pending", "cancelled", or "done".
467466
Another is its result, which is set when the state transitions to done.
468467
Unlike a coroutine, a future does not represent the actual computation to be
469468
done; instead, it represents the status and result of that computation, kind of
470-
like a status light (red, yellow or green) or indicator.
469+
like a status light (red, yellow, or green) or indicator.
471470

472471
:class:`asyncio.Task` subclasses :class:`asyncio.Future` in order to gain
473472
these various capabilities.
@@ -490,8 +489,8 @@ We'll go through an example of how you could leverage a future to create your
490489
own variant of asynchronous sleep (``async_sleep``) which mimics
491490
:func:`asyncio.sleep`.
492491

493-
This snippet registers a few tasks with the event loop and then awaits a
494-
coroutine wrapped in a task: ``async_sleep(3)``.
492+
This snippet registers a few tasks with the event loop and then awaits the task
493+
created by ``asyncio.create_task``, which wraps the ``async_sleep(3)`` coroutine.
495494
We want that task to finish only after three seconds have elapsed, but without
496495
preventing other tasks from running.
497496

@@ -540,8 +539,8 @@ will monitor how much time has elapsed and, accordingly, call
540539
# Block until the future is marked as done.
541540
await future
542541

543-
Below, we'll use a rather bare object, ``YieldToEventLoop()``, to ``yield``
544-
from ``__await__`` in order to cede control to the event loop.
542+
Below, we use a rather bare ``YieldToEventLoop()`` object to ``yield``
543+
from its ``__await__`` method, ceding control to the event loop.
545544
This is effectively the same as calling ``asyncio.sleep(0)``, but this approach
546545
offers more clarity, not to mention it's somewhat cheating to use
547546
``asyncio.sleep`` when showcasing how to implement it!
@@ -552,13 +551,13 @@ The ``watcher_task``, which runs the coroutine ``_sleep_watcher(...)``, will
552551
be invoked once per full cycle of the event loop.
553552
On each resumption, it'll check the time and if not enough has elapsed, then
554553
it'll pause once again and hand control back to the event loop.
555-
Eventually, enough time will have elapsed, and ``_sleep_watcher(...)`` will
556-
mark the future as done, and then itself finish too by breaking out of the
554+
Once enough time has elapsed, ``_sleep_watcher(...)``
555+
marks the future as done and completes by exiting its
557556
infinite ``while`` loop.
558557
Given this helper task is only invoked once per cycle of the event loop,
559558
you'd be correct to note that this asynchronous sleep will sleep *at least*
560559
three seconds, rather than exactly three seconds.
561-
Note this is also of true of ``asyncio.sleep``.
560+
Note this is also true of ``asyncio.sleep``.
562561

563562
::
564563

@@ -601,6 +600,6 @@ For reference, you could implement it without futures, like so::
601600
else:
602601
await YieldToEventLoop()
603602

604-
But, that's all for now. Hopefully you're ready to more confidently dive into
603+
But that's all for now. Hopefully you're ready to more confidently dive into
605604
some async programming or check out advanced topics in the
606605
:mod:`rest of the documentation <asyncio>`.

_sources/library/annotationlib.rst.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,29 @@ Functions
340340

341341
* VALUE: :attr:`!object.__annotations__` is tried first; if that does not exist,
342342
the :attr:`!object.__annotate__` function is called if it exists.
343+
343344
* FORWARDREF: If :attr:`!object.__annotations__` exists and can be evaluated successfully,
344345
it is used; otherwise, the :attr:`!object.__annotate__` function is called. If it
345346
does not exist either, :attr:`!object.__annotations__` is tried again and any error
346347
from accessing it is re-raised.
348+
349+
* When calling :attr:`!object.__annotate__` it is first called with :attr:`~Format.FORWARDREF`.
350+
If this is not implemented, it will then check if :attr:`~Format.VALUE_WITH_FAKE_GLOBALS`
351+
is supported and use that in the fake globals environment.
352+
If neither of these formats are supported, it will fall back to using :attr:`~Format.VALUE`.
353+
If :attr:`~Format.VALUE` fails, the error from this call will be raised.
354+
347355
* STRING: If :attr:`!object.__annotate__` exists, it is called first;
348356
otherwise, :attr:`!object.__annotations__` is used and stringified
349357
using :func:`annotations_to_string`.
350358

359+
* When calling :attr:`!object.__annotate__` it is first called with :attr:`~Format.STRING`.
360+
If this is not implemented, it will then check if :attr:`~Format.VALUE_WITH_FAKE_GLOBALS`
361+
is supported and use that in the fake globals environment.
362+
If neither of these formats are supported, it will fall back to using :attr:`~Format.VALUE`
363+
with the result converted using :func:`annotations_to_string`.
364+
If :attr:`~Format.VALUE` fails, the error from this call will be raised.
365+
351366
Returns a dict. :func:`!get_annotations` returns a new dict every time
352367
it's called; calling it twice on the same object will return two
353368
different but equivalent dicts.

_sources/library/cmath.rst.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ Constants
338338
.. data:: nan
339339

340340
A floating-point "not a number" (NaN) value. Equivalent to
341-
``float('nan')``.
341+
``float('nan')``. See also :data:`math.nan`.
342342

343343
.. versionadded:: 3.6
344344

_sources/library/codecs.rst.txt

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -982,17 +982,22 @@ defined in Unicode. A simple and straightforward way that can store each Unicode
982982
code point, is to store each code point as four consecutive bytes. There are two
983983
possibilities: store the bytes in big endian or in little endian order. These
984984
two encodings are called ``UTF-32-BE`` and ``UTF-32-LE`` respectively. Their
985-
disadvantage is that if e.g. you use ``UTF-32-BE`` on a little endian machine you
986-
will always have to swap bytes on encoding and decoding. ``UTF-32`` avoids this
987-
problem: bytes will always be in natural endianness. When these bytes are read
988-
by a CPU with a different endianness, then bytes have to be swapped though. To
989-
be able to detect the endianness of a ``UTF-16`` or ``UTF-32`` byte sequence,
990-
there's the so called BOM ("Byte Order Mark"). This is the Unicode character
991-
``U+FEFF``. This character can be prepended to every ``UTF-16`` or ``UTF-32``
992-
byte sequence. The byte swapped version of this character (``0xFFFE``) is an
993-
illegal character that may not appear in a Unicode text. So when the
994-
first character in a ``UTF-16`` or ``UTF-32`` byte sequence
995-
appears to be a ``U+FFFE`` the bytes have to be swapped on decoding.
985+
disadvantage is that if, for example, you use ``UTF-32-BE`` on a little endian
986+
machine you will always have to swap bytes on encoding and decoding.
987+
Python's ``UTF-16`` and ``UTF-32`` codecs avoid this problem by using the
988+
platform's native byte order when no BOM is present.
989+
Python follows prevailing platform
990+
practice, so native-endian data round-trips without redundant byte swapping,
991+
even though the Unicode Standard defaults to big-endian when the byte order is
992+
unspecified. When these bytes are read by a CPU with a different endianness,
993+
the bytes have to be swapped. To be able to detect the endianness of a
994+
``UTF-16`` or ``UTF-32`` byte sequence, a BOM ("Byte Order Mark") is used.
995+
This is the Unicode character ``U+FEFF``. This character can be prepended to every
996+
``UTF-16`` or ``UTF-32`` byte sequence. The byte swapped version of this character
997+
(``0xFFFE``) is an illegal character that may not appear in a Unicode text.
998+
When the first character of a ``UTF-16`` or ``UTF-32`` byte sequence is
999+
``U+FFFE``, the bytes have to be swapped on decoding.
1000+
9961001
Unfortunately the character ``U+FEFF`` had a second purpose as
9971002
a ``ZERO WIDTH NO-BREAK SPACE``: a character that has no width and doesn't allow
9981003
a word to be split. It can e.g. be used to give hints to a ligature algorithm.

0 commit comments

Comments
 (0)