Skip to content

Commit 99af855

Browse files
authored
Merge branch 'main' into pyrepl/completions-below
2 parents eae92aa + 034cf0c commit 99af855

File tree

145 files changed

+1961
-664
lines changed

Some content is hidden

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

145 files changed

+1961
-664
lines changed

.github/workflows/jit.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ on:
55
- '**jit**'
66
- 'Python/bytecodes.c'
77
- 'Python/optimizer*.c'
8+
- '!Python/perf_jit_trampoline.c'
9+
- '!**/*.md'
10+
- '!**/*.ini'
811
push:
912
paths:
1013
- '**jit**'
1114
- 'Python/bytecodes.c'
1215
- 'Python/optimizer*.c'
16+
- '!Python/perf_jit_trampoline.c'
17+
- '!**/*.md'
18+
- '!**/*.ini'
1319
workflow_dispatch:
1420

1521
permissions:

.github/workflows/reusable-docs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ jobs:
6262
python Doc/tools/check-warnings.py \
6363
--annotate-diff '${{ env.branch_base }}' '${{ env.branch_pr }}' \
6464
--fail-if-regression \
65-
--fail-if-improved
65+
--fail-if-improved \
66+
--fail-if-new-news-nit
6667
6768
# This build doesn't use problem matchers or check annotations
6869
build_doc_oldest_supported_sphinx:

Doc/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ help:
3232
@echo " clean to remove build files"
3333
@echo " venv to create a venv with necessary tools"
3434
@echo " html to make standalone HTML files"
35+
@echo " gettext to generate POT files"
3536
@echo " htmlview to open the index page built by the html target in your browser"
3637
@echo " htmllive to rebuild and reload HTML files in your browser"
3738
@echo " htmlhelp to make HTML files and a HTML help project"
@@ -140,6 +141,11 @@ pydoc-topics: build
140141
@echo "Building finished; now run this:" \
141142
"cp build/pydoc-topics/topics.py ../Lib/pydoc_data/topics.py"
142143

144+
.PHONY: gettext
145+
gettext: BUILDER = gettext
146+
gettext: SPHINXOPTS += '-d build/doctrees-gettext'
147+
gettext: build
148+
143149
.PHONY: htmlview
144150
htmlview: html
145151
$(PYTHON) -c "import os, webbrowser; webbrowser.open('file://' + os.path.realpath('build/html/index.html'))"

Doc/c-api/dict.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ Dictionary Objects
191191
to both *default_value* and *\*result* (if it's not ``NULL``).
192192
These may refer to the same object: in that case you hold two separate
193193
references to it.
194+
194195
.. versionadded:: 3.13
195196
196197

Doc/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@
374374
# Split the index
375375
html_split_index = True
376376

377+
# Split pot files one per reST file
378+
gettext_compact = False
377379

378380
# Options for LaTeX output
379381
# ------------------------

Doc/library/dataclasses.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,8 @@ methods will raise a :exc:`FrozenInstanceError` when invoked.
615615

616616
There is a tiny performance penalty when using ``frozen=True``:
617617
:meth:`~object.__init__` cannot use simple assignment to initialize fields, and
618-
must use :meth:`!__setattr__`.
618+
must use :meth:`!object.__setattr__`.
619+
.. Make sure to not remove "object" from "object.__setattr__" in the above markup
619620
620621
.. _dataclasses-inheritance:
621622

Doc/library/functions.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,13 @@ are always available. They are listed here in alphabetical order.
608608
will be used for both the global and the local variables. If *globals* and
609609
*locals* are given, they are used for the global and local variables,
610610
respectively. If provided, *locals* can be any mapping object. Remember
611-
that at the module level, globals and locals are the same dictionary. If exec
612-
gets two separate objects as *globals* and *locals*, the code will be
613-
executed as if it were embedded in a class definition.
611+
that at the module level, globals and locals are the same dictionary.
612+
613+
.. note::
614+
615+
Most users should just pass a *globals* argument and never *locals*.
616+
If exec gets two separate objects as *globals* and *locals*, the code
617+
will be executed as if it were embedded in a class definition.
614618

615619
If the *globals* dictionary does not contain a value for the key
616620
``__builtins__``, a reference to the dictionary of the built-in module

Doc/library/functools.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,9 @@ The :mod:`functools` module defines the following functions:
646646
attributes of the wrapper function are updated with the corresponding attributes
647647
from the original function. The default values for these arguments are the
648648
module level constants ``WRAPPER_ASSIGNMENTS`` (which assigns to the wrapper
649-
function's ``__module__``, ``__name__``, ``__qualname__``, ``__annotations__``
650-
and ``__doc__``, the documentation string) and ``WRAPPER_UPDATES`` (which
649+
function's ``__module__``, ``__name__``, ``__qualname__``, ``__annotations__``,
650+
``__type_params__``, and ``__doc__``, the documentation string)
651+
and ``WRAPPER_UPDATES`` (which
651652
updates the wrapper function's ``__dict__``, i.e. the instance dictionary).
652653

653654
To allow access to the original function for introspection and other purposes
@@ -677,6 +678,9 @@ The :mod:`functools` module defines the following functions:
677678
function, even if that function defined a ``__wrapped__`` attribute.
678679
(see :issue:`17482`)
679680

681+
.. versionchanged:: 3.12
682+
The ``__type_params__`` attribute is now copied by default.
683+
680684

681685
.. decorator:: wraps(wrapped, assigned=WRAPPER_ASSIGNMENTS, updated=WRAPPER_UPDATES)
682686

Doc/library/importlib.metadata.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ instance::
343343
>>> dist.metadata['License'] # doctest: +SKIP
344344
'MIT'
345345

346-
For editable packages, an origin property may present :pep:`610`
346+
For editable packages, an ``origin`` property may present :pep:`610`
347347
metadata::
348348

349349
>>> dist.origin.url

Doc/library/itertools.rst

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ loops that truncate the stream.
122122
# accumulate([1,2,3,4,5]) → 1 3 6 10 15
123123
# accumulate([1,2,3,4,5], initial=100) → 100 101 103 106 110 115
124124
# accumulate([1,2,3,4,5], operator.mul) → 1 2 6 24 120
125-
it = iter(iterable)
125+
iterator = iter(iterable)
126126
total = initial
127127
if initial is None:
128128
try:
129-
total = next(it)
129+
total = next(iterator)
130130
except StopIteration:
131131
return
132132
yield total
133-
for element in it:
133+
for element in iterator:
134134
total = func(total, element)
135135
yield total
136136

@@ -218,9 +218,8 @@ loops that truncate the stream.
218218

219219
def chain(*iterables):
220220
# chain('ABC', 'DEF') → A B C D E F
221-
for it in iterables:
222-
for element in it:
223-
yield element
221+
for iterable in iterables:
222+
yield from iterable
224223

225224

226225
.. classmethod:: chain.from_iterable(iterable)
@@ -230,9 +229,8 @@ loops that truncate the stream.
230229

231230
def from_iterable(iterables):
232231
# chain.from_iterable(['ABC', 'DEF']) → A B C D E F
233-
for it in iterables:
234-
for element in it:
235-
yield element
232+
for iterable in iterables:
233+
yield from iterable
236234

237235

238236
.. function:: combinations(iterable, r)
@@ -380,7 +378,7 @@ loops that truncate the stream.
380378
saved.append(element)
381379
while saved:
382380
for element in saved:
383-
yield element
381+
yield element
384382

385383
Note, this member of the toolkit may require significant auxiliary storage
386384
(depending on the length of the iterable).
@@ -615,10 +613,10 @@ loops that truncate the stream.
615613
This function is roughly equivalent to the following code, except that the
616614
actual implementation does not build up intermediate results in memory::
617615

618-
def product(*args, repeat=1):
616+
def product(*iterables, repeat=1):
619617
# product('ABCD', 'xy') → Ax Ay Bx By Cx Cy Dx Dy
620618
# product(range(2), repeat=3) → 000 001 010 011 100 101 110 111
621-
pools = [tuple(pool) for pool in args] * repeat
619+
pools = [tuple(pool) for pool in iterables] * repeat
622620
result = [[]]
623621
for pool in pools:
624622
result = [x+[y] for x in result for y in pool]
@@ -696,24 +694,23 @@ loops that truncate the stream.
696694

697695
Return *n* independent iterators from a single iterable.
698696

699-
The following Python code helps explain what *tee* does (although the actual
700-
implementation is more complex and uses only a single underlying
701-
:abbr:`FIFO (first-in, first-out)` queue)::
697+
Roughly equivalent to::
702698

703699
def tee(iterable, n=2):
704-
it = iter(iterable)
705-
deques = [collections.deque() for i in range(n)]
706-
def gen(mydeque):
700+
iterator = iter(iterable)
701+
shared_link = [None, None]
702+
return tuple(_tee(iterator, shared_link) for _ in range(n))
703+
704+
def _tee(iterator, link):
705+
try:
707706
while True:
708-
if not mydeque: # when the local deque is empty
709-
try:
710-
newval = next(it) # fetch a new value and
711-
except StopIteration:
712-
return
713-
for d in deques: # load it to all the deques
714-
d.append(newval)
715-
yield mydeque.popleft()
716-
return tuple(gen(d) for d in deques)
707+
if link[1] is None:
708+
link[0] = next(iterator)
709+
link[1] = [None, None]
710+
value, link = link
711+
yield value
712+
except StopIteration:
713+
return
717714

718715
Once a :func:`tee` has been created, the original *iterable* should not be
719716
used anywhere else; otherwise, the *iterable* could get advanced without
@@ -735,17 +732,17 @@ loops that truncate the stream.
735732
iterables are of uneven length, missing values are filled-in with *fillvalue*.
736733
Iteration continues until the longest iterable is exhausted. Roughly equivalent to::
737734

738-
def zip_longest(*args, fillvalue=None):
735+
def zip_longest(*iterables, fillvalue=None):
739736
# zip_longest('ABCD', 'xy', fillvalue='-') → Ax By C- D-
740-
iterators = [iter(it) for it in args]
737+
iterators = [iter(it) for it in iterables]
741738
num_active = len(iterators)
742739
if not num_active:
743740
return
744741
while True:
745742
values = []
746-
for i, it in enumerate(iterators):
743+
for i, iterator in enumerate(iterators):
747744
try:
748-
value = next(it)
745+
value = next(iterator)
749746
except StopIteration:
750747
num_active -= 1
751748
if not num_active:
@@ -800,6 +797,7 @@ and :term:`generators <generator>` which incur interpreter overhead.
800797
.. testcode::
801798

802799
import collections
800+
import contextlib
803801
import functools
804802
import math
805803
import operator
@@ -942,32 +940,26 @@ and :term:`generators <generator>` which incur interpreter overhead.
942940
# iter_index('AABCADEAF', 'A') → 0 1 4 7
943941
seq_index = getattr(iterable, 'index', None)
944942
if seq_index is None:
945-
# Path for general iterables
946943
iterator = islice(iterable, start, stop)
947944
for i, element in enumerate(iterator, start):
948945
if element is value or element == value:
949946
yield i
950947
else:
951-
# Path for sequences with an index() method
952948
stop = len(iterable) if stop is None else stop
953949
i = start
954-
try:
950+
with contextlib.suppress(ValueError):
955951
while True:
956952
yield (i := seq_index(value, i, stop))
957953
i += 1
958-
except ValueError:
959-
pass
960954

961955
def iter_except(func, exception, first=None):
962956
"Convert a call-until-exception interface to an iterator interface."
963957
# iter_except(d.popitem, KeyError) → non-blocking dictionary iterator
964-
try:
958+
with contextlib.suppress(exception):
965959
if first is not None:
966960
yield first()
967961
while True:
968962
yield func()
969-
except exception:
970-
pass
971963

972964

973965
The following recipes have a more mathematical flavor:

Doc/library/marshal.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
This module contains functions that can read and write Python values in a binary
1111
format. The format is specific to Python, but independent of machine
1212
architecture issues (e.g., you can write a Python value to a file on a PC,
13-
transport the file to a Sun, and read it back there). Details of the format are
13+
transport the file to a Mac, and read it back there). Details of the format are
1414
undocumented on purpose; it may change between Python versions (although it
1515
rarely does). [#]_
1616

0 commit comments

Comments
 (0)