Skip to content

Commit e8f1363

Browse files
Merge branch 'main' into base64-decode-ignore-pad-char
2 parents 2f6c71d + c3b61ef commit e8f1363

File tree

74 files changed

+5360
-3198
lines changed

Some content is hidden

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

74 files changed

+5360
-3198
lines changed

Doc/c-api/object.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -711,10 +711,10 @@ Object Protocol
711711
712712
:c:func:`PyUnstable_EnableTryIncRef` must have been called
713713
earlier on *obj* or this function may spuriously return ``0`` in the
714-
:term:`free threading` build.
714+
:term:`free-threaded build`.
715715
716716
This function is logically equivalent to the following C code, except that
717-
it behaves atomically in the :term:`free threading` build::
717+
it behaves atomically in the :term:`free-threaded build`::
718718
719719
if (Py_REFCNT(op) > 0) {
720720
Py_INCREF(op);
@@ -791,10 +791,10 @@ Object Protocol
791791
On GIL-enabled builds, this function is equivalent to
792792
:c:expr:`Py_REFCNT(op) == 1`.
793793
794-
On a :term:`free threaded <free threading>` build, this checks if *op*'s
794+
On a :term:`free-threaded build`, this checks if *op*'s
795795
:term:`reference count` is equal to one and additionally checks if *op*
796796
is only used by this thread. :c:expr:`Py_REFCNT(op) == 1` is **not**
797-
thread-safe on free threaded builds; prefer this function.
797+
thread-safe on free-threaded builds; prefer this function.
798798
799799
The caller must hold an :term:`attached thread state`, despite the fact
800800
that this function doesn't call into the Python interpreter. This function

Doc/c-api/refcounting.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ of Python objects.
2525
2626
.. note::
2727
28-
On :term:`free threaded <free threading>` builds of Python, returning 1
28+
On :term:`free-threaded builds <free-threaded build>` of Python, returning 1
2929
isn't sufficient to determine if it's safe to treat *o* as having no
3030
access by other threads. Use :c:func:`PyUnstable_Object_IsUniquelyReferenced`
3131
for that instead.

Doc/glossary.rst

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ Glossary
160160
On most builds of Python, having an attached thread state implies that the
161161
caller holds the :term:`GIL` for the current interpreter, so only
162162
one OS thread can have an attached thread state at a given moment. In
163-
:term:`free-threaded <free threading>` builds of Python, threads can concurrently
164-
hold an attached thread state, allowing for true parallelism of the bytecode
165-
interpreter.
163+
:term:`free-threaded builds <free-threaded build>` of Python, threads can
164+
concurrently hold an attached thread state, allowing for true parallelism of
165+
the bytecode interpreter.
166166

167167
attribute
168168
A value associated with an object which is usually referenced by name
@@ -580,6 +580,13 @@ Glossary
580580
the :term:`global interpreter lock` which allows only one thread to
581581
execute Python bytecode at a time. See :pep:`703`.
582582

583+
free-threaded build
584+
585+
A build of :term:`CPython` that supports :term:`free threading`,
586+
configured using the :option:`--disable-gil` option before compilation.
587+
588+
See :ref:`freethreading-python-howto`.
589+
583590
free variable
584591
Formally, as defined in the :ref:`language execution model <bind_names>`, a free
585592
variable is any variable used in a namespace which is not a local variable in that

Doc/library/base64.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ POST request.
9494
``False`` otherwise.
9595

9696
If *validate* is false, characters that are neither
97-
in the normal base-64 alphabet nor the alternative alphabet are
97+
in the normal base-64 alphabet nor (if *ignorechars* is not specified)
98+
the alternative alphabet are
9899
discarded prior to the padding check, but the ``+`` and ``/`` characters
99100
keep their meaning if they are not in *altchars* (they will be discarded
100101
in future Python versions).
@@ -104,15 +105,14 @@ POST request.
104105

105106
For more information about the strict base64 check, see :func:`binascii.a2b_base64`
106107

108+
.. versionchanged:: next
109+
Added the *ignorechars* parameter.
110+
107111
.. deprecated:: next
108112
Accepting the ``+`` and ``/`` characters with an alternative alphabet
109113
is now deprecated.
110114

111115

112-
.. versionchanged:: next
113-
Added the *ignorechars* parameter.
114-
115-
116116
.. function:: standard_b64encode(s)
117117

118118
Encode :term:`bytes-like object` *s* using the standard Base64 alphabet

Doc/library/ctypes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ invalid non-\ ``NULL`` pointers would crash Python)::
896896
Thread safety without the GIL
897897
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
898898

899-
From Python 3.13 onward, the :term:`GIL` can be disabled on :term:`free threaded <free threading>` builds.
899+
From Python 3.13 onward, the :term:`GIL` can be disabled on the :term:`free-threaded build`.
900900
In ctypes, reads and writes to a single object concurrently is safe, but not across multiple objects:
901901

902902
.. code-block:: pycon

Doc/library/dis.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ iterations of the loop.
16421642

16431643
Pushes a ``NULL`` to the stack.
16441644
Used in the call sequence to match the ``NULL`` pushed by
1645-
:opcode:`!LOAD_METHOD` for non-method calls.
1645+
:opcode:`LOAD_ATTR` for non-method calls.
16461646

16471647
.. versionadded:: 3.11
16481648

Doc/library/io.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ than raw I/O does.
720720
contains initial data.
721721

722722
Methods may be used from multiple threads without external locking in
723-
:term:`free threading` builds.
723+
:term:`free-threaded builds <free-threaded build>`.
724724

725725
:class:`BytesIO` provides or overrides these methods in addition to those
726726
from :class:`BufferedIOBase` and :class:`IOBase`:

Doc/library/site.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ For the head part, it uses ``sys.prefix`` and ``sys.exec_prefix``; empty heads
3434
are skipped. For the tail part, it uses the empty string and then
3535
:file:`lib/site-packages` (on Windows) or
3636
:file:`lib/python{X.Y[t]}/site-packages` (on Unix and macOS). (The
37-
optional suffix "t" indicates the :term:`free threading` build, and is
37+
optional suffix "t" indicates the :term:`free-threaded build`, and is
3838
appended if ``"t"`` is present in the :data:`sys.abiflags` constant.)
3939
For each
4040
of the distinct head-tail combinations, it sees if it refers to an existing

Doc/reference/expressions.rst

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,19 @@ called "displays", each of them in two flavors:
266266
Common syntax elements for comprehensions are:
267267

268268
.. productionlist:: python-grammar
269-
comprehension: `assignment_expression` `comp_for`
269+
comprehension: `flexible_expression` `comp_for`
270270
comp_for: ["async"] "for" `target_list` "in" `or_test` [`comp_iter`]
271271
comp_iter: `comp_for` | `comp_if`
272272
comp_if: "if" `or_test` [`comp_iter`]
273273

274274
The comprehension consists of a single expression followed by at least one
275-
:keyword:`!for` clause and zero or more :keyword:`!for` or :keyword:`!if` clauses.
276-
In this case, the elements of the new container are those that would be produced
277-
by considering each of the :keyword:`!for` or :keyword:`!if` clauses a block,
278-
nesting from left to right, and evaluating the expression to produce an element
279-
each time the innermost block is reached.
275+
:keyword:`!for` clause and zero or more :keyword:`!for` or :keyword:`!if`
276+
clauses. In this case, the elements of the new container are those that would
277+
be produced by considering each of the :keyword:`!for` or :keyword:`!if`
278+
clauses a block, nesting from left to right, and evaluating the expression to
279+
produce an element each time the innermost block is reached. If the expression
280+
is starred, the result will instead be unpacked to produce zero or more
281+
elements.
280282

281283
However, aside from the iterable expression in the leftmost :keyword:`!for` clause,
282284
the comprehension is executed in a separate implicitly nested scope. This ensures
@@ -321,6 +323,9 @@ See also :pep:`530`.
321323
asynchronous functions. Outer comprehensions implicitly become
322324
asynchronous.
323325

326+
.. versionchanged:: next
327+
Unpacking with the ``*`` operator is now allowed in the expression.
328+
324329

325330
.. _lists:
326331

@@ -396,8 +401,8 @@ enclosed in curly braces:
396401
.. productionlist:: python-grammar
397402
dict_display: "{" [`dict_item_list` | `dict_comprehension`] "}"
398403
dict_item_list: `dict_item` ("," `dict_item`)* [","]
404+
dict_comprehension: `dict_item` `comp_for`
399405
dict_item: `expression` ":" `expression` | "**" `or_expr`
400-
dict_comprehension: `expression` ":" `expression` `comp_for`
401406

402407
A dictionary display yields a new dictionary object.
403408

@@ -419,10 +424,21 @@ earlier dict items and earlier dictionary unpackings.
419424
.. versionadded:: 3.5
420425
Unpacking into dictionary displays, originally proposed by :pep:`448`.
421426

422-
A dict comprehension, in contrast to list and set comprehensions, needs two
423-
expressions separated with a colon followed by the usual "for" and "if" clauses.
424-
When the comprehension is run, the resulting key and value elements are inserted
425-
in the new dictionary in the order they are produced.
427+
A dict comprehension may take one of two forms:
428+
429+
- The first form uses two expressions separated with a colon followed by the
430+
usual "for" and "if" clauses. When the comprehension is run, the resulting
431+
key and value elements are inserted in the new dictionary in the order they
432+
are produced.
433+
434+
- The second form uses a single expression prefixed by the ``**`` dictionary
435+
unpacking operator followed by the usual "for" and "if" clauses. When the
436+
comprehension is evaluated, the expression is evaluated and then unpacked,
437+
inserting zero or more key/value pairs into the new dictionary.
438+
439+
Both forms of dictionary comprehension retain the property that if the same key
440+
is specified multiple times, the associated value in the resulting dictionary
441+
will be the last one specified.
426442

427443
.. index:: pair: immutable; object
428444
hashable
@@ -439,6 +455,8 @@ prevails.
439455
the key. Starting with 3.8, the key is evaluated before the value, as
440456
proposed by :pep:`572`.
441457

458+
.. versionchanged:: next
459+
Unpacking with the ``**`` operator is now allowed in dictionary comprehensions.
442460

443461
.. _genexpr:
444462

@@ -453,7 +471,7 @@ Generator expressions
453471
A generator expression is a compact generator notation in parentheses:
454472

455473
.. productionlist:: python-grammar
456-
generator_expression: "(" `expression` `comp_for` ")"
474+
generator_expression: "(" `flexible_expression` `comp_for` ")"
457475

458476
A generator expression yields a new generator object. Its syntax is the same as
459477
for comprehensions, except that it is enclosed in parentheses instead of

Doc/tutorial/classes.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,25 @@ Examples::
929929
>>> list(data[i] for i in range(len(data)-1, -1, -1))
930930
['f', 'l', 'o', 'g']
931931

932+
>>> x = [[1,2,3], [], [4, 5]]
933+
>>> g = (*i for i in x)
934+
>>> list(g)
935+
[1, 2, 3, 4, 5]
936+
937+
In most cases, generator expressions must be wrapped in parentheses. As a
938+
special case, however, when provided as the sole argument to a function (as in
939+
the examples involving ``sum``, ``set``, ``max``, and ``list`` above), the
940+
generator expression does not need to be wrapped in an additional set of
941+
parentheses. That is to say, the following two pieces of code are semantically
942+
equivalent::
943+
944+
>>> f(x for x in y)
945+
>>> f((x for x in y))
946+
947+
as are the following::
948+
949+
>>> f(*x for x in y)
950+
>>> f((*x for x in y))
932951

933952

934953
.. rubric:: Footnotes

0 commit comments

Comments
 (0)