Skip to content

Commit afc8f57

Browse files
authored
Merge branch 'main' into fix-issue-116111-on-datetime-docs
2 parents 522be82 + d5e75c0 commit afc8f57

Some content is hidden

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

64 files changed

+1725
-780
lines changed

Doc/c-api/init.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,7 +2287,7 @@ The C-API provides a basic mutual exclusion lock.
22872287
should not be used to make concurrency control decisions, as the lock
22882288
state may change immediately after the check.
22892289
2290-
.. versionadded:: next
2290+
.. versionadded:: 3.14
22912291
22922292
.. _python-critical-section-api:
22932293
@@ -2372,7 +2372,7 @@ code triggered by the finalizer blocks and calls :c:func:`PyEval_SaveThread`.
23722372
23732373
On the default build, this macro expands to ``{``.
23742374
2375-
.. versionadded:: next
2375+
.. versionadded:: 3.14
23762376
23772377
.. c:macro:: Py_END_CRITICAL_SECTION()
23782378
@@ -2418,7 +2418,7 @@ code triggered by the finalizer blocks and calls :c:func:`PyEval_SaveThread`.
24182418
24192419
On the default build, this macro expands to ``{``.
24202420
2421-
.. versionadded:: next
2421+
.. versionadded:: 3.14
24222422
24232423
.. c:macro:: Py_END_CRITICAL_SECTION2()
24242424

Doc/extending/extending.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ and initialize it by calling :c:func:`PyErr_NewException` in the module's
214214

215215
SpamError = PyErr_NewException("spam.error", NULL, NULL);
216216

217-
Since :c:data:`!SpamError` is a global variable, it will be overwitten every time
217+
Since :c:data:`!SpamError` is a global variable, it will be overwritten every time
218218
the module is reinitialized, when the :c:data:`Py_mod_exec` function is called.
219219

220220
For now, let's avoid the issue: we will block repeated initialization by raising an

Doc/howto/free-threading-extensions.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ that return :term:`strong references <strong reference>`.
161161
+===================================+===================================+
162162
| :c:func:`PyList_GetItem` | :c:func:`PyList_GetItemRef` |
163163
+-----------------------------------+-----------------------------------+
164+
| :c:func:`PyList_GET_ITEM` | :c:func:`PyList_GetItemRef` |
165+
+-----------------------------------+-----------------------------------+
164166
| :c:func:`PyDict_GetItem` | :c:func:`PyDict_GetItemRef` |
165167
+-----------------------------------+-----------------------------------+
166168
| :c:func:`PyDict_GetItemWithError` | :c:func:`PyDict_GetItemRef` |

Doc/library/asyncio-queue.rst

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,33 @@ Queue
102102

103103
.. method:: shutdown(immediate=False)
104104

105-
Shut down the queue, making :meth:`~Queue.get` and :meth:`~Queue.put`
105+
Put a :class:`Queue` instance into a shutdown mode.
106+
107+
The queue can no longer grow.
108+
Future calls to :meth:`~Queue.put` raise :exc:`QueueShutDown`.
109+
Currently blocked callers of :meth:`~Queue.put` will be unblocked
110+
and will raise :exc:`QueueShutDown` in the formerly blocked thread.
111+
112+
If *immediate* is false (the default), the queue can be wound
113+
down normally with :meth:`~Queue.get` calls to extract tasks
114+
that have already been loaded.
115+
116+
And if :meth:`~Queue.task_done` is called for each remaining task, a
117+
pending :meth:`~Queue.join` will be unblocked normally.
118+
119+
Once the queue is empty, future calls to :meth:`~Queue.get` will
106120
raise :exc:`QueueShutDown`.
107121

108-
By default, :meth:`~Queue.get` on a shut down queue will only
109-
raise once the queue is empty. Set *immediate* to true to make
110-
:meth:`~Queue.get` raise immediately instead.
122+
If *immediate* is true, the queue is terminated immediately.
123+
The queue is drained to be completely empty. All callers of
124+
:meth:`~Queue.join` are unblocked regardless of the number
125+
of unfinished tasks. Blocked callers of :meth:`~Queue.get`
126+
are unblocked and will raise :exc:`QueueShutDown` because the
127+
queue is empty.
111128

112-
All blocked callers of :meth:`~Queue.put` and :meth:`~Queue.get`
113-
will be unblocked. If *immediate* is true, a task will be marked
114-
as done for each remaining item in the queue, which may unblock
115-
callers of :meth:`~Queue.join`.
129+
Use caution when using :meth:`~Queue.join` with *immediate* set
130+
to true. This unblocks the join even when no work has been done
131+
on the tasks, violating the usual invariant for joining a queue.
116132

117133
.. versionadded:: 3.13
118134

@@ -129,9 +145,6 @@ Queue
129145
call was received for every item that had been :meth:`~Queue.put`
130146
into the queue).
131147

132-
``shutdown(immediate=True)`` calls :meth:`task_done` for each
133-
remaining item in the queue.
134-
135148
Raises :exc:`ValueError` if called more times than there were
136149
items placed in the queue.
137150

Doc/library/bdb.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,8 @@ The :mod:`bdb` module also defines two classes:
192192
entered.
193193
* ``"return"``: A function or other code block is about to return.
194194
* ``"exception"``: An exception has occurred.
195-
* ``"c_call"``: A C function is about to be called.
196-
* ``"c_return"``: A C function has returned.
197-
* ``"c_exception"``: A C function has raised an exception.
198195

199-
For the Python events, specialized functions (see below) are called. For
200-
the C events, no action is taken.
196+
For all the events, specialized functions (see below) are called.
201197

202198
The *arg* parameter depends on the previous event.
203199

Doc/library/importlib.resources.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ within *packages*.
1616
"Resources" are file-like resources associated with a module or package in
1717
Python. The resources may be contained directly in a package, within a
1818
subdirectory contained in that package, or adjacent to modules outside a
19-
package. Resources may be text or binary. As a result, Python module sources
20-
(.py) of a package and compilation artifacts (pycache) are technically
21-
de-facto resources of that package. In practice, however, resources are
22-
primarily those non-Python artifacts exposed specifically by the package
23-
author.
19+
package. Resources may be text or binary. As a result, a package's Python
20+
module sources (.py), compilation artifacts (pycache), and installation
21+
artifacts (like :func:`reserved filenames <os.path.isreserved>`
22+
in directories) are technically de-facto resources of that package.
23+
In practice, however, resources are primarily those non-Python artifacts
24+
exposed specifically by the package author.
2425

2526
Resources can be opened or read in either binary or text mode.
2627

Doc/library/queue.rst

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,6 @@ fully processed by daemon consumer threads.
187187
processed (meaning that a :meth:`task_done` call was received for every item
188188
that had been :meth:`put` into the queue).
189189

190-
``shutdown(immediate=True)`` calls :meth:`task_done` for each remaining item
191-
in the queue.
192-
193190
Raises a :exc:`ValueError` if called more times than there were items placed in
194191
the queue.
195192

@@ -204,6 +201,9 @@ fully processed by daemon consumer threads.
204201
count of unfinished tasks drops to zero, :meth:`join` unblocks.
205202

206203

204+
Waiting for task completion
205+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
206+
207207
Example of how to wait for enqueued tasks to be completed::
208208

209209
import threading
@@ -233,22 +233,38 @@ Example of how to wait for enqueued tasks to be completed::
233233
Terminating queues
234234
^^^^^^^^^^^^^^^^^^
235235

236-
:class:`Queue` objects can be made to prevent further interaction by shutting
237-
them down.
236+
When no longer needed, :class:`Queue` objects can be wound down
237+
until empty or terminated immediately with a hard shutdown.
238238

239239
.. method:: Queue.shutdown(immediate=False)
240240

241-
Shut down the queue, making :meth:`~Queue.get` and :meth:`~Queue.put` raise
242-
:exc:`ShutDown`.
241+
Put a :class:`Queue` instance into a shutdown mode.
242+
243+
The queue can no longer grow.
244+
Future calls to :meth:`~Queue.put` raise :exc:`ShutDown`.
245+
Currently blocked callers of :meth:`~Queue.put` will be unblocked
246+
and will raise :exc:`ShutDown` in the formerly blocked thread.
247+
248+
If *immediate* is false (the default), the queue can be wound
249+
down normally with :meth:`~Queue.get` calls to extract tasks
250+
that have already been loaded.
251+
252+
And if :meth:`~Queue.task_done` is called for each remaining task, a
253+
pending :meth:`~Queue.join` will be unblocked normally.
254+
255+
Once the queue is empty, future calls to :meth:`~Queue.get` will
256+
raise :exc:`ShutDown`.
243257

244-
By default, :meth:`~Queue.get` on a shut down queue will only raise once the
245-
queue is empty. Set *immediate* to true to make :meth:`~Queue.get` raise
246-
immediately instead.
258+
If *immediate* is true, the queue is terminated immediately.
259+
The queue is drained to be completely empty. All callers of
260+
:meth:`~Queue.join` are unblocked regardless of the number
261+
of unfinished tasks. Blocked callers of :meth:`~Queue.get`
262+
are unblocked and will raise :exc:`ShutDown` because the
263+
queue is empty.
247264

248-
All blocked callers of :meth:`~Queue.put` and :meth:`~Queue.get` will be
249-
unblocked. If *immediate* is true, a task will be marked as done for each
250-
remaining item in the queue, which may unblock callers of
251-
:meth:`~Queue.join`.
265+
Use caution when using :meth:`~Queue.join` with *immediate* set
266+
to true. This unblocks the join even when no work has been done
267+
on the tasks, violating the usual invariant for joining a queue.
252268

253269
.. versionadded:: 3.13
254270

Doc/library/shelve.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Restrictions
144144
which can cause hard crashes when trying to read from the database.
145145

146146
* :meth:`Shelf.reorganize` may not be available for all database packages and
147-
may temporarely increase resource usage (especially disk space) when called.
147+
may temporarily increase resource usage (especially disk space) when called.
148148
Additionally, it will never run automatically and instead needs to be called
149149
explicitly.
150150

Doc/reference/expressions.rst

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,18 @@ Literals
133133

134134
Python supports string and bytes literals and various numeric literals:
135135

136-
.. productionlist:: python-grammar
137-
literal: `stringliteral` | `bytesliteral` | `NUMBER`
136+
.. grammar-snippet::
137+
:group: python-grammar
138+
139+
literal: `strings` | `NUMBER`
138140

139141
Evaluation of a literal yields an object of the given type (string, bytes,
140142
integer, floating-point number, complex number) with the given value. The value
141143
may be approximated in the case of floating-point and imaginary (complex)
142-
literals. See section :ref:`literals` for details.
144+
literals.
145+
See section :ref:`literals` for details.
146+
See section :ref:`string-concatenation` for details on ``strings``.
147+
143148

144149
.. index::
145150
triple: immutable; data; type
@@ -152,6 +157,58 @@ occurrence) may obtain the same object or a different object with the same
152157
value.
153158

154159

160+
.. _string-concatenation:
161+
162+
String literal concatenation
163+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
164+
165+
Multiple adjacent string or bytes literals (delimited by whitespace), possibly
166+
using different quoting conventions, are allowed, and their meaning is the same
167+
as their concatenation::
168+
169+
>>> "hello" 'world'
170+
"helloworld"
171+
172+
Formally:
173+
174+
.. grammar-snippet::
175+
:group: python-grammar
176+
177+
strings: ( `STRING` | fstring)+ | tstring+
178+
179+
This feature is defined at the syntactical level, so it only works with literals.
180+
To concatenate string expressions at run time, the '+' operator may be used::
181+
182+
>>> greeting = "Hello"
183+
>>> space = " "
184+
>>> name = "Blaise"
185+
>>> print(greeting + space + name) # not: print(greeting space name)
186+
Hello Blaise
187+
188+
Literal concatenation can freely mix raw strings, triple-quoted strings,
189+
and formatted string literals.
190+
For example::
191+
192+
>>> "Hello" r', ' f"{name}!"
193+
"Hello, Blaise!"
194+
195+
This feature can be used to reduce the number of backslashes
196+
needed, to split long strings conveniently across long lines, or even to add
197+
comments to parts of strings. For example::
198+
199+
re.compile("[A-Za-z_]" # letter or underscore
200+
"[A-Za-z0-9_]*" # letter, digit or underscore
201+
)
202+
203+
However, bytes literals may only be combined with other byte literals;
204+
not with string literals of any kind.
205+
Also, template string literals may only be combined with other template
206+
string literals::
207+
208+
>>> t"Hello" t"{name}!"
209+
Template(strings=('Hello', '!'), interpolations=(...))
210+
211+
155212
.. _parenthesized:
156213

157214
Parenthesized forms

Doc/reference/grammar.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ error recovery.
1010

1111
The notation used here is the same as in the preceding docs,
1212
and is described in the :ref:`notation <notation>` section,
13-
except for a few extra complications:
13+
except for an extra complication:
1414

15-
* ``&e``: a positive lookahead (that is, ``e`` is required to match but
16-
not consumed)
17-
* ``!e``: a negative lookahead (that is, ``e`` is required *not* to match)
1815
* ``~`` ("cut"): commit to the current alternative and fail the rule
1916
even if this fails to parse
2017

0 commit comments

Comments
 (0)