Skip to content

Commit a3ecd16

Browse files
committed
Merge remote-tracking branch 'upstream/main' into cpython-nogil-interpreter
2 parents 20b081c + 86e5e06 commit a3ecd16

File tree

87 files changed

+7873
-990
lines changed

Some content is hidden

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

87 files changed

+7873
-990
lines changed

.github/workflows/jit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ jobs:
7070
runner: ubuntu-latest
7171
compiler: gcc
7272
# These fail because of emulation, not because of the JIT:
73-
exclude: test_unix_events test_init test_process_pool test_shutdown test_multiprocessing_fork test_cmd_line test_faulthandler test_os test_perf_profiler test_posix test_signal test_socket test_subprocess test_threading test_venv
73+
exclude: test_unix_events test_init test_process_pool test_shutdown test_multiprocessing_fork test_cmd_line test_faulthandler test_os test_perf_profiler test_posix test_signal test_socket test_subprocess test_threading test_venv test_external_inspection
7474
- target: aarch64-unknown-linux-gnu/clang
7575
architecture: aarch64
7676
runner: ubuntu-latest
7777
compiler: clang
7878
# These fail because of emulation, not because of the JIT:
79-
exclude: test_unix_events test_init test_process_pool test_shutdown test_multiprocessing_fork test_cmd_line test_faulthandler test_os test_perf_profiler test_posix test_signal test_socket test_subprocess test_threading test_venv
79+
exclude: test_unix_events test_init test_process_pool test_shutdown test_multiprocessing_fork test_cmd_line test_faulthandler test_os test_perf_profiler test_posix test_signal test_socket test_subprocess test_threading test_venv test_external_inspection
8080
env:
8181
CC: ${{ matrix.compiler }}
8282
steps:

.github/workflows/reusable-macos.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
HOMEBREW_NO_ANALYTICS: 1
1818
HOMEBREW_NO_AUTO_UPDATE: 1
1919
HOMEBREW_NO_INSTALL_CLEANUP: 1
20+
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
2021
PYTHONSTRICTEXTENSIONBUILD: 1
2122
strategy:
2223
fail-fast: false

Doc/library/ast.rst

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,15 @@ Node classes
103103
For example, to create and populate an :class:`ast.UnaryOp` node, you could
104104
use ::
105105

106-
node = ast.UnaryOp()
107-
node.op = ast.USub()
108-
node.operand = ast.Constant()
109-
node.operand.value = 5
110-
node.operand.lineno = 0
111-
node.operand.col_offset = 0
112-
node.lineno = 0
113-
node.col_offset = 0
114-
115-
or the more compact ::
116-
117106
node = ast.UnaryOp(ast.USub(), ast.Constant(5, lineno=0, col_offset=0),
118107
lineno=0, col_offset=0)
119108

109+
If a field that is optional in the grammar is omitted from the constructor,
110+
it defaults to ``None``. If a list field is omitted, it defaults to the empty
111+
list. If any other field is omitted, a :exc:`DeprecationWarning` is raised
112+
and the AST node will not have this field. In Python 3.15, this condition will
113+
raise an error.
114+
120115
.. versionchanged:: 3.8
121116

122117
Class :class:`ast.Constant` is now used for all constants.
@@ -140,6 +135,14 @@ Node classes
140135
In the meantime, instantiating them will return an instance of
141136
a different class.
142137

138+
.. deprecated-removed:: 3.13 3.15
139+
140+
Previous versions of Python allowed the creation of AST nodes that were missing
141+
required fields. Similarly, AST node constructors allowed arbitrary keyword
142+
arguments that were set as attributes of the AST node, even if they did not
143+
match any of the fields of the AST node. This behavior is deprecated and will
144+
be removed in Python 3.15.
145+
143146
.. note::
144147
The descriptions of the specific node classes displayed here
145148
were initially adapted from the fantastic `Green Tree

Doc/library/enum.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,9 @@ Data Types
400400

401401
results in the call ``int('1a', 16)`` and a value of ``17`` for the member.
402402

403+
..note:: When writing a custom ``__new__``, do not use ``super().__new__`` --
404+
call the appropriate ``__new__`` instead.
405+
403406
.. method:: Enum.__repr__(self)
404407

405408
Returns the string used for *repr()* calls. By default, returns the

Doc/library/functions.rst

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,20 @@ are always available. They are listed here in alphabetical order.
526526

527527
.. function:: eval(expression, globals=None, locals=None)
528528

529-
The arguments are a string and optional globals and locals. If provided,
530-
*globals* must be a dictionary. If provided, *locals* can be any mapping
531-
object.
529+
:param expression:
530+
A Python expression.
531+
:type expression: :class:`str` | :ref:`code object <code-objects>`
532+
533+
:param globals:
534+
The global namespace (default: ``None``).
535+
:type globals: :class:`dict` | ``None``
536+
537+
:param locals:
538+
The local namespace (default: ``None``).
539+
:type locals: :term:`mapping` | ``None``
540+
541+
:returns: The result of the evaluated expression.
542+
:raises: Syntax errors are reported as exceptions.
532543

533544
The *expression* argument is parsed and evaluated as a Python expression
534545
(technically speaking, a condition list) using the *globals* and *locals*
@@ -545,8 +556,7 @@ are always available. They are listed here in alphabetical order.
545556
:term:`nested scopes <nested scope>` (non-locals) in the enclosing
546557
environment.
547558

548-
The return value is the result of
549-
the evaluated expression. Syntax errors are reported as exceptions. Example:
559+
Example:
550560

551561
>>> x = 1
552562
>>> eval('x+1')

Doc/library/itertools.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ The primary purpose of the itertools recipes is educational. The recipes show
778778
various ways of thinking about individual tools — for example, that
779779
``chain.from_iterable`` is related to the concept of flattening. The recipes
780780
also give ideas about ways that the tools can be combined — for example, how
781-
``compress()`` and ``range()`` can work together. The recipes also show patterns
781+
``starmap()`` and ``repeat()`` can work together. The recipes also show patterns
782782
for using itertools with the :mod:`operator` and :mod:`collections` modules as
783783
well as with the built-in itertools such as ``map()``, ``filter()``,
784784
``reversed()``, and ``enumerate()``.
@@ -863,10 +863,9 @@ which incur interpreter overhead.
863863
"Given a predicate that returns True or False, count the True results."
864864
return sum(map(pred, iterable))
865865

866-
def all_equal(iterable):
866+
def all_equal(iterable, key=None):
867867
"Returns True if all the elements are equal to each other."
868-
g = groupby(iterable)
869-
return next(g, True) and not next(g, False)
868+
return len(take(2, groupby(iterable, key))) <= 1
870869

871870
def first_true(iterable, default=False, pred=None):
872871
"""Returns the first true value in the iterable.
@@ -1225,6 +1224,8 @@ The following recipes have a more mathematical flavor:
12251224

12261225
>>> [all_equal(s) for s in ('', 'A', 'AAAA', 'AAAB', 'AAABA')]
12271226
[True, True, True, False, False]
1227+
>>> [all_equal(s, key=str.casefold) for s in ('', 'A', 'AaAa', 'AAAB', 'AAABA')]
1228+
[True, True, True, False, False]
12281229

12291230
>>> quantify(range(99), lambda x: x%2==0)
12301231
50

Doc/library/json.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Extending :class:`JSONEncoder`::
106106
... if isinstance(obj, complex):
107107
... return [obj.real, obj.imag]
108108
... # Let the base class default method raise the TypeError
109-
... return json.JSONEncoder.default(self, obj)
109+
... return super().default(obj)
110110
...
111111
>>> json.dumps(2 + 1j, cls=ComplexEncoder)
112112
'[2.0, 1.0]'
@@ -504,7 +504,7 @@ Encoders and Decoders
504504
else:
505505
return list(iterable)
506506
# Let the base class default method raise the TypeError
507-
return json.JSONEncoder.default(self, o)
507+
return super().default(o)
508508

509509

510510
.. method:: encode(o)

Doc/library/pprint.rst

Lines changed: 92 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,93 @@ Dictionaries are sorted by key before the display is computed.
3131
.. versionchanged:: 3.10
3232
Added support for pretty-printing :class:`dataclasses.dataclass`.
3333

34-
The :mod:`pprint` module defines one class:
34+
.. _pprint-functions:
35+
36+
Functions
37+
---------
38+
39+
.. function:: pp(object, *args, sort_dicts=False, **kwargs)
40+
41+
Prints the formatted representation of *object* followed by a newline.
42+
If *sort_dicts* is false (the default), dictionaries will be displayed with
43+
their keys in insertion order, otherwise the dict keys will be sorted.
44+
*args* and *kwargs* will be passed to :func:`~pprint.pprint` as formatting
45+
parameters.
46+
47+
.. versionadded:: 3.8
48+
49+
50+
.. function:: pprint(object, stream=None, indent=1, width=80, depth=None, *, \
51+
compact=False, sort_dicts=True, underscore_numbers=False)
52+
53+
Prints the formatted representation of *object* on *stream*, followed by a
54+
newline. If *stream* is ``None``, :data:`sys.stdout` is used. This may be used
55+
in the interactive interpreter instead of the :func:`print` function for
56+
inspecting values (you can even reassign ``print = pprint.pprint`` for use
57+
within a scope).
58+
59+
The configuration parameters *stream*, *indent*, *width*, *depth*,
60+
*compact*, *sort_dicts* and *underscore_numbers* are passed to the
61+
:class:`PrettyPrinter` constructor and their meanings are as
62+
described in its documentation above.
63+
64+
>>> import pprint
65+
>>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
66+
>>> stuff.insert(0, stuff)
67+
>>> pprint.pprint(stuff)
68+
[<Recursion on list with id=...>,
69+
'spam',
70+
'eggs',
71+
'lumberjack',
72+
'knights',
73+
'ni']
74+
75+
.. function:: pformat(object, indent=1, width=80, depth=None, *, \
76+
compact=False, sort_dicts=True, underscore_numbers=False)
77+
78+
Return the formatted representation of *object* as a string. *indent*,
79+
*width*, *depth*, *compact*, *sort_dicts* and *underscore_numbers* are
80+
passed to the :class:`PrettyPrinter` constructor as formatting parameters
81+
and their meanings are as described in its documentation above.
82+
83+
84+
.. function:: isreadable(object)
85+
86+
.. index:: pair: built-in function; eval
87+
88+
Determine if the formatted representation of *object* is "readable", or can be
89+
used to reconstruct the value using :func:`eval`. This always returns ``False``
90+
for recursive objects.
91+
92+
>>> pprint.isreadable(stuff)
93+
False
94+
95+
96+
.. function:: isrecursive(object)
97+
98+
Determine if *object* requires a recursive representation. This function is
99+
subject to the same limitations as noted in :func:`saferepr` below and may raise an
100+
:exc:`RecursionError` if it fails to detect a recursive object.
101+
102+
103+
.. function:: saferepr(object)
104+
105+
Return a string representation of *object*, protected against recursion in
106+
some common data structures, namely instances of :class:`dict`, :class:`list`
107+
and :class:`tuple` or subclasses whose ``__repr__`` has not been overridden. If the
108+
representation of object exposes a recursive entry, the recursive reference
109+
will be represented as ``<Recursion on typename with id=number>``. The
110+
representation is not otherwise formatted.
111+
112+
>>> pprint.saferepr(stuff)
113+
"[<Recursion on list with id=...>, 'spam', 'eggs', 'lumberjack', 'knights', 'ni']"
114+
115+
.. _prettyprinter-objects:
116+
117+
PrettyPrinter Objects
118+
---------------------
119+
120+
This module defines one class:
35121

36122
.. First the implementation class:
37123
@@ -44,9 +130,9 @@ The :mod:`pprint` module defines one class:
44130
Construct a :class:`PrettyPrinter` instance. This constructor understands
45131
several keyword parameters.
46132

47-
*stream* (default ``sys.stdout``) is a :term:`file-like object` to
133+
*stream* (default :data:`!sys.stdout`) is a :term:`file-like object` to
48134
which the output will be written by calling its :meth:`!write` method.
49-
If both *stream* and ``sys.stdout`` are ``None``, then
135+
If both *stream* and :data:`!sys.stdout` are ``None``, then
50136
:meth:`~PrettyPrinter.pprint` silently returns.
51137

52138
Other values configure the manner in which nesting of complex data
@@ -87,7 +173,7 @@ The :mod:`pprint` module defines one class:
87173
Added the *underscore_numbers* parameter.
88174

89175
.. versionchanged:: 3.11
90-
No longer attempts to write to ``sys.stdout`` if it is ``None``.
176+
No longer attempts to write to :data:`!sys.stdout` if it is ``None``.
91177

92178
>>> import pprint
93179
>>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
@@ -112,89 +198,6 @@ The :mod:`pprint` module defines one class:
112198
>>> pp.pprint(tup)
113199
('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', (...)))))))
114200

115-
.. function:: pformat(object, indent=1, width=80, depth=None, *, \
116-
compact=False, sort_dicts=True, underscore_numbers=False)
117-
118-
Return the formatted representation of *object* as a string. *indent*,
119-
*width*, *depth*, *compact*, *sort_dicts* and *underscore_numbers* are
120-
passed to the :class:`PrettyPrinter` constructor as formatting parameters
121-
and their meanings are as described in its documentation above.
122-
123-
124-
.. function:: pp(object, *args, sort_dicts=False, **kwargs)
125-
126-
Prints the formatted representation of *object* followed by a newline.
127-
If *sort_dicts* is false (the default), dictionaries will be displayed with
128-
their keys in insertion order, otherwise the dict keys will be sorted.
129-
*args* and *kwargs* will be passed to :func:`pprint` as formatting
130-
parameters.
131-
132-
.. versionadded:: 3.8
133-
134-
135-
.. function:: pprint(object, stream=None, indent=1, width=80, depth=None, *, \
136-
compact=False, sort_dicts=True, underscore_numbers=False)
137-
138-
Prints the formatted representation of *object* on *stream*, followed by a
139-
newline. If *stream* is ``None``, ``sys.stdout`` is used. This may be used
140-
in the interactive interpreter instead of the :func:`print` function for
141-
inspecting values (you can even reassign ``print = pprint.pprint`` for use
142-
within a scope).
143-
144-
The configuration parameters *stream*, *indent*, *width*, *depth*,
145-
*compact*, *sort_dicts* and *underscore_numbers* are passed to the
146-
:class:`PrettyPrinter` constructor and their meanings are as
147-
described in its documentation above.
148-
149-
>>> import pprint
150-
>>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
151-
>>> stuff.insert(0, stuff)
152-
>>> pprint.pprint(stuff)
153-
[<Recursion on list with id=...>,
154-
'spam',
155-
'eggs',
156-
'lumberjack',
157-
'knights',
158-
'ni']
159-
160-
.. function:: isreadable(object)
161-
162-
.. index:: pair: built-in function; eval
163-
164-
Determine if the formatted representation of *object* is "readable", or can be
165-
used to reconstruct the value using :func:`eval`. This always returns ``False``
166-
for recursive objects.
167-
168-
>>> pprint.isreadable(stuff)
169-
False
170-
171-
172-
.. function:: isrecursive(object)
173-
174-
Determine if *object* requires a recursive representation. This function is
175-
subject to the same limitations as noted in :func:`saferepr` below and may raise an
176-
:exc:`RecursionError` if it fails to detect a recursive object.
177-
178-
179-
One more support function is also defined:
180-
181-
.. function:: saferepr(object)
182-
183-
Return a string representation of *object*, protected against recursion in
184-
some common data structures, namely instances of :class:`dict`, :class:`list`
185-
and :class:`tuple` or subclasses whose ``__repr__`` has not been overridden. If the
186-
representation of object exposes a recursive entry, the recursive reference
187-
will be represented as ``<Recursion on typename with id=number>``. The
188-
representation is not otherwise formatted.
189-
190-
>>> pprint.saferepr(stuff)
191-
"[<Recursion on list with id=...>, 'spam', 'eggs', 'lumberjack', 'knights', 'ni']"
192-
193-
194-
.. _prettyprinter-objects:
195-
196-
PrettyPrinter Objects
197-
---------------------
198201

199202
:class:`PrettyPrinter` instances have the following methods:
200203

@@ -258,7 +261,7 @@ are converted to strings. The default implementation uses the internals of the
258261
Example
259262
-------
260263

261-
To demonstrate several uses of the :func:`pprint` function and its parameters,
264+
To demonstrate several uses of the :func:`~pprint.pprint` function and its parameters,
262265
let's fetch information about a project from `PyPI <https://pypi.org>`_::
263266

264267
>>> import json
@@ -267,7 +270,7 @@ let's fetch information about a project from `PyPI <https://pypi.org>`_::
267270
>>> with urlopen('https://pypi.org/pypi/sampleproject/json') as resp:
268271
... project_info = json.load(resp)['info']
269272

270-
In its basic form, :func:`pprint` shows the whole object::
273+
In its basic form, :func:`~pprint.pprint` shows the whole object::
271274

272275
>>> pprint.pprint(project_info)
273276
{'author': 'The Python Packaging Authority',

0 commit comments

Comments
 (0)