Skip to content

Commit bc889bc

Browse files
committed
Merge remote-tracking branch 'upstream/main' into bpo-45711-remove-exc_type_field
2 parents fbff4f6 + 2dc7d3d commit bc889bc

File tree

96 files changed

+8547
-4126
lines changed

Some content is hidden

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

96 files changed

+8547
-4126
lines changed

Doc/c-api/iter.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ There are two functions specifically for working with iterators.
99

1010
.. c:function:: int PyIter_Check(PyObject *o)
1111
12-
Return non-zero if the object *o* supports the iterator protocol, and ``0``
13-
otherwise. This function always succeeds.
12+
Return non-zero if the object *o* can be safely passed to
13+
:c:func:`PyIter_Next`, and ``0`` otherwise. This function always succeeds.
1414
1515
.. c:function:: int PyAIter_Check(PyObject *o)
1616
@@ -21,10 +21,11 @@ There are two functions specifically for working with iterators.
2121
2222
.. c:function:: PyObject* PyIter_Next(PyObject *o)
2323
24-
Return the next value from the iteration *o*. The object must be an iterator
25-
(it is up to the caller to check this). If there are no remaining values,
26-
returns ``NULL`` with no exception set. If an error occurs while retrieving
27-
the item, returns ``NULL`` and passes along the exception.
24+
Return the next value from the iterator *o*. The object must be an iterator
25+
according to :c:func:`PyIter_Check` (it is up to the caller to check this).
26+
If there are no remaining values, returns ``NULL`` with no exception set.
27+
If an error occurs while retrieving the item, returns ``NULL`` and passes
28+
along the exception.
2829
2930
To write a loop which iterates over an iterator, the C code should look
3031
something like this::

Doc/c-api/typeobj.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,9 +1521,9 @@ and :c:type:`PyType_Type` effectively act as defaults.)
15211521

15221522
.. c:member:: getiterfunc PyTypeObject.tp_iter
15231523
1524-
An optional pointer to a function that returns an iterator for the object. Its
1525-
presence normally signals that the instances of this type are iterable (although
1526-
sequences may be iterable without this function).
1524+
An optional pointer to a function that returns an :term:`iterator` for the
1525+
object. Its presence normally signals that the instances of this type are
1526+
:term:`iterable` (although sequences may be iterable without this function).
15271527

15281528
This function has the same signature as :c:func:`PyObject_GetIter`::
15291529

@@ -1536,8 +1536,8 @@ and :c:type:`PyType_Type` effectively act as defaults.)
15361536

15371537
.. c:member:: iternextfunc PyTypeObject.tp_iternext
15381538
1539-
An optional pointer to a function that returns the next item in an iterator.
1540-
The signature is::
1539+
An optional pointer to a function that returns the next item in an
1540+
:term:`iterator`. The signature is::
15411541

15421542
PyObject *tp_iternext(PyObject *self);
15431543

@@ -2429,8 +2429,8 @@ Async Object Structures
24292429

24302430
PyObject *am_await(PyObject *self);
24312431

2432-
The returned object must be an iterator, i.e. :c:func:`PyIter_Check` must
2433-
return ``1`` for it.
2432+
The returned object must be an :term:`iterator`, i.e. :c:func:`PyIter_Check`
2433+
must return ``1`` for it.
24342434

24352435
This slot may be set to ``NULL`` if an object is not an :term:`awaitable`.
24362436

Doc/faq/library.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,6 @@ Be sure to use the :mod:`threading` module and not the :mod:`_thread` module.
240240
The :mod:`threading` module builds convenient abstractions on top of the
241241
low-level primitives provided by the :mod:`_thread` module.
242242
243-
Aahz has a set of slides from his threading tutorial that are helpful; see
244-
http://www.pythoncraft.com/OSCON2001/.
245-
246243
247244
None of my threads seem to run: why?
248245
------------------------------------
@@ -614,9 +611,9 @@ use ``p.read(n)``.
614611
How do I access the serial (RS232) port?
615612
----------------------------------------
616613
617-
For Win32, POSIX (Linux, BSD, etc.), Jython:
614+
For Win32, OSX, Linux, BSD, Jython, IronPython:
618615
619-
http://pyserial.sourceforge.net
616+
https://pypi.org/project/pyserial/
620617
621618
For Unix, see a Usenet post by Mitch Chapman:
622619

Doc/faq/programming.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2092,7 +2092,7 @@ Jim Roskind suggests performing steps in the following order in each module:
20922092
* ``import`` statements
20932093
* active code (including globals that are initialized from imported values).
20942094

2095-
van Rossum doesn't like this approach much because the imports appear in a
2095+
Van Rossum doesn't like this approach much because the imports appear in a
20962096
strange place, but it does work.
20972097

20982098
Matthias Urlichs recommends restructuring your code so that the recursive import

Doc/glossary.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,11 @@ Glossary
659659

660660
More information can be found in :ref:`typeiter`.
661661

662+
.. impl-detail::
663+
664+
CPython does not consistently apply the requirement that an iterator
665+
define :meth:`__iter__`.
666+
662667
key function
663668
A key function or collation function is a callable that returns a value
664669
used for sorting or ordering. For example, :func:`locale.strxfrm` is

Doc/howto/descriptor.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,9 @@ Using the non-data descriptor protocol, a pure Python version of
12641264
def __get__(self, obj, objtype=None):
12651265
return self.f
12661266

1267+
def __call__(self, *args, **kwds):
1268+
return self.f(*args, **kwds)
1269+
12671270
.. testcode::
12681271
:hide:
12691272

@@ -1272,13 +1275,17 @@ Using the non-data descriptor protocol, a pure Python version of
12721275
def f(x):
12731276
return x * 10
12741277

1278+
wrapped_ord = StaticMethod(ord)
1279+
12751280
.. doctest::
12761281
:hide:
12771282

12781283
>>> E_sim.f(3)
12791284
30
12801285
>>> E_sim().f(3)
12811286
30
1287+
>>> wrapped_ord('A')
1288+
65
12821289

12831290

12841291
Class methods
@@ -1344,7 +1351,7 @@ Using the non-data descriptor protocol, a pure Python version of
13441351
if cls is None:
13451352
cls = type(obj)
13461353
if hasattr(type(self.f), '__get__'):
1347-
return self.f.__get__(cls)
1354+
return self.f.__get__(cls, cls)
13481355
return MethodType(self.f, cls)
13491356

13501357
.. testcode::

Doc/library/concurrent.futures.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ that :class:`ProcessPoolExecutor` will not work in the interactive interpreter.
231231
Calling :class:`Executor` or :class:`Future` methods from a callable submitted
232232
to a :class:`ProcessPoolExecutor` will result in deadlock.
233233

234-
.. class:: ProcessPoolExecutor(max_workers=None, mp_context=None, initializer=None, initargs=())
234+
.. class:: ProcessPoolExecutor(max_workers=None, mp_context=None, initializer=None, initargs=(), max_tasks_per_child=None)
235235

236236
An :class:`Executor` subclass that executes calls asynchronously using a pool
237237
of at most *max_workers* processes. If *max_workers* is ``None`` or not
@@ -252,6 +252,11 @@ to a :class:`ProcessPoolExecutor` will result in deadlock.
252252
pending jobs will raise a :exc:`~concurrent.futures.process.BrokenProcessPool`,
253253
as well as any attempt to submit more jobs to the pool.
254254

255+
*max_tasks_per_child* is an optional argument that specifies the maximum
256+
number of tasks a single process can execute before it will exit and be
257+
replaced with a fresh worker process. The default *max_tasks_per_child* is
258+
``None`` which means worker processes will live as long as the pool.
259+
255260
.. versionchanged:: 3.3
256261
When one of the worker processes terminates abruptly, a
257262
:exc:`BrokenProcessPool` error is now raised. Previously, behaviour
@@ -264,6 +269,10 @@ to a :class:`ProcessPoolExecutor` will result in deadlock.
264269

265270
Added the *initializer* and *initargs* arguments.
266271

272+
.. versionchanged:: 3.11
273+
The *max_tasks_per_child* argument was added to allow users to
274+
control the lifetime of workers in the pool.
275+
267276

268277
.. _processpoolexecutor-example:
269278

Doc/library/functions.rst

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ are always available. They are listed here in alphabetical order.
6666
Return an :term:`asynchronous iterator` for an :term:`asynchronous iterable`.
6767
Equivalent to calling ``x.__aiter__()``.
6868

69-
``aiter(x)`` itself has an ``__aiter__()`` method that returns ``x``,
70-
so ``aiter(aiter(x))`` is the same as ``aiter(x)``.
71-
7269
Note: Unlike :func:`iter`, :func:`aiter` has no 2-argument variant.
7370

7471
.. versionadded:: 3.10
@@ -929,8 +926,8 @@ are always available. They are listed here in alphabetical order.
929926
Return an :term:`iterator` object. The first argument is interpreted very
930927
differently depending on the presence of the second argument. Without a
931928
second argument, *object* must be a collection object which supports the
932-
iteration protocol (the :meth:`__iter__` method), or it must support the
933-
sequence protocol (the :meth:`__getitem__` method with integer arguments
929+
:term:`iterable` protocol (the :meth:`__iter__` method), or it must support
930+
the sequence protocol (the :meth:`__getitem__` method with integer arguments
934931
starting at ``0``). If it does not support either of those protocols,
935932
:exc:`TypeError` is raised. If the second argument, *sentinel*, is given,
936933
then *object* must be a callable object. The iterator created in this case
@@ -1060,7 +1057,7 @@ are always available. They are listed here in alphabetical order.
10601057

10611058
.. function:: next(iterator[, default])
10621059

1063-
Retrieve the next item from the *iterator* by calling its
1060+
Retrieve the next item from the :term:`iterator` by calling its
10641061
:meth:`~iterator.__next__` method. If *default* is given, it is returned
10651062
if the iterator is exhausted, otherwise :exc:`StopIteration` is raised.
10661063

Doc/library/statistics.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ However, for reading convenience, most of the examples show sorted sequences.
643643

644644
.. versionadded:: 3.10
645645

646-
.. function:: linear_regression(x, y, /)
646+
.. function:: linear_regression(x, y, /, *, proportional=False)
647647

648648
Return the slope and intercept of `simple linear regression
649649
<https://en.wikipedia.org/wiki/Simple_linear_regression>`_
@@ -677,8 +677,18 @@ However, for reading convenience, most of the examples show sorted sequences.
677677
>>> round(slope * 2019 + intercept)
678678
16
679679

680+
If *proportional* is true, the independent variable *x* and the
681+
dependent variable *y* are assumed to be directly proportional.
682+
The data is fit to a line passing through the origin.
683+
Since the *intercept* will always be 0.0, the underlying linear
684+
function simplifies to:
685+
686+
*y = slope \* x + noise*
687+
680688
.. versionadded:: 3.10
681689

690+
.. versionchanged:: 3.11
691+
Added support for *proportional*.
682692

683693
Exceptions
684694
----------

Doc/library/stdtypes.rst

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -810,40 +810,41 @@ using two distinct methods; these are used to allow user-defined classes to
810810
support iteration. Sequences, described below in more detail, always support
811811
the iteration methods.
812812

813-
One method needs to be defined for container objects to provide iteration
813+
One method needs to be defined for container objects to provide :term:`iterable`
814814
support:
815815

816816
.. XXX duplicated in reference/datamodel!
817817
818818
.. method:: container.__iter__()
819819

820-
Return an iterator object. The object is required to support the iterator
821-
protocol described below. If a container supports different types of
822-
iteration, additional methods can be provided to specifically request
820+
Return an :term:`iterator` object. The object is required to support the
821+
iterator protocol described below. If a container supports different types
822+
of iteration, additional methods can be provided to specifically request
823823
iterators for those iteration types. (An example of an object supporting
824824
multiple forms of iteration would be a tree structure which supports both
825825
breadth-first and depth-first traversal.) This method corresponds to the
826-
:c:member:`~PyTypeObject.tp_iter` slot of the type structure for Python objects in the Python/C
827-
API.
826+
:c:member:`~PyTypeObject.tp_iter` slot of the type structure for Python
827+
objects in the Python/C API.
828828

829829
The iterator objects themselves are required to support the following two
830830
methods, which together form the :dfn:`iterator protocol`:
831831

832832

833833
.. method:: iterator.__iter__()
834834

835-
Return the iterator object itself. This is required to allow both containers
836-
and iterators to be used with the :keyword:`for` and :keyword:`in` statements.
837-
This method corresponds to the :c:member:`~PyTypeObject.tp_iter` slot of the type structure for
838-
Python objects in the Python/C API.
835+
Return the :term:`iterator` object itself. This is required to allow both
836+
containers and iterators to be used with the :keyword:`for` and
837+
:keyword:`in` statements. This method corresponds to the
838+
:c:member:`~PyTypeObject.tp_iter` slot of the type structure for Python
839+
objects in the Python/C API.
839840

840841

841842
.. method:: iterator.__next__()
842843

843-
Return the next item from the container. If there are no further items, raise
844-
the :exc:`StopIteration` exception. This method corresponds to the
845-
:c:member:`~PyTypeObject.tp_iternext` slot of the type structure for Python objects in the
846-
Python/C API.
844+
Return the next item from the :term:`iterator`. If there are no further
845+
items, raise the :exc:`StopIteration` exception. This method corresponds to
846+
the :c:member:`~PyTypeObject.tp_iternext` slot of the type structure for
847+
Python objects in the Python/C API.
847848

848849
Python defines several iterator objects to support iteration over general and
849850
specific sequence types, dictionaries, and other more specialized forms. The

Doc/library/sys.rst

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,13 +1216,10 @@ always available.
12161216
.. data:: prefix
12171217

12181218
A string giving the site-specific directory prefix where the platform
1219-
independent Python files are installed; by default, this is the string
1219+
independent Python files are installed; on Unix, the default is
12201220
``'/usr/local'``. This can be set at build time with the ``--prefix``
1221-
argument to the :program:`configure` script. The main collection of Python
1222-
library modules is installed in the directory :file:`{prefix}/lib/python{X.Y}`
1223-
while the platform independent header files (all except :file:`pyconfig.h`) are
1224-
stored in :file:`{prefix}/include/python{X.Y}`, where *X.Y* is the version
1225-
number of Python, for example ``3.2``.
1221+
argument to the :program:`configure` script. See
1222+
:ref:`installation_paths` for derived paths.
12261223

12271224
.. note:: If a :ref:`virtual environment <venv-def>` is in effect, this
12281225
value will be changed in ``site.py`` to point to the virtual

Doc/library/sysconfig.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Example of usage::
6060
>>> sysconfig.get_config_vars('AR', 'CXX')
6161
['ar', 'g++']
6262

63+
.. _installation_paths:
6364

6465
Installation paths
6566
------------------
@@ -72,7 +73,7 @@ Every new component that is installed using :mod:`distutils` or a
7273
Distutils-based system will follow the same scheme to copy its file in the right
7374
places.
7475

75-
Python currently supports seven schemes:
76+
Python currently supports six schemes:
7677

7778
- *posix_prefix*: scheme for POSIX platforms like Linux or macOS. This is
7879
the default scheme used when Python or a component is installed.
@@ -84,6 +85,7 @@ Python currently supports seven schemes:
8485
located under the user home directory.
8586
- *nt*: scheme for NT platforms like Windows.
8687
- *nt_user*: scheme for NT platforms, when the *user* option is used.
88+
- *osx_framework_user*: scheme for macOS, when the *user* option is used.
8789

8890
Each scheme is itself composed of a series of paths and each path has a unique
8991
identifier. Python currently uses eight paths:

Doc/library/typing.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ called :class:`TypeVar`.
256256
def first(l: Sequence[T]) -> T: # Generic function
257257
return l[0]
258258

259+
.. _user-defined-generics:
259260

260261
User-defined generic types
261262
==========================

Doc/reference/compound_stmts.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ usage patterns to be encapsulated for convenient reuse.
418418

419419
The execution of the :keyword:`with` statement with one "item" proceeds as follows:
420420

421-
#. The context expression (the expression given in the :token:`with_item`) is
422-
evaluated to obtain a context manager.
421+
#. The context expression (the expression given in the
422+
:token:`~python-grammar:with_item`) is evaluated to obtain a context manager.
423423

424424
#. The context manager's :meth:`__enter__` is loaded for later use.
425425

@@ -797,7 +797,8 @@ Syntax:
797797
capture_pattern: !'_' NAME
798798

799799
A single underscore ``_`` is not a capture pattern (this is what ``!'_'``
800-
expresses). It is instead treated as a :token:`wildcard_pattern`.
800+
expresses). It is instead treated as a
801+
:token:`~python-grammar:wildcard_pattern`.
801802

802803
In a given pattern, a given name can only be bound once. E.g.
803804
``case x, x: ...`` is invalid while ``case [x] | x: ...`` is allowed.
@@ -1182,9 +1183,9 @@ is roughly equivalent to ::
11821183
except that the original function is not temporarily bound to the name ``func``.
11831184

11841185
.. versionchanged:: 3.9
1185-
Functions may be decorated with any valid :token:`assignment_expression`.
1186-
Previously, the grammar was much more restrictive; see :pep:`614` for
1187-
details.
1186+
Functions may be decorated with any valid
1187+
:token:`~python-grammar:assignment_expression`. Previously, the grammar was
1188+
much more restrictive; see :pep:`614` for details.
11881189

11891190
.. index::
11901191
triple: default; parameter; value
@@ -1360,9 +1361,9 @@ The evaluation rules for the decorator expressions are the same as for function
13601361
decorators. The result is then bound to the class name.
13611362

13621363
.. versionchanged:: 3.9
1363-
Classes may be decorated with any valid :token:`assignment_expression`.
1364-
Previously, the grammar was much more restrictive; see :pep:`614` for
1365-
details.
1364+
Classes may be decorated with any valid
1365+
:token:`~python-grammar:assignment_expression`. Previously, the grammar was
1366+
much more restrictive; see :pep:`614` for details.
13661367

13671368
**Programmer's note:** Variables defined in the class definition are class
13681369
attributes; they are shared by instances. Instance attributes can be set in a

0 commit comments

Comments
 (0)