Skip to content

Commit

Permalink
Merge branch '3.13' into backport-99b23c6-3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
Yhg1s authored Sep 26, 2024
2 parents 33df56c + a079922 commit 7472c88
Show file tree
Hide file tree
Showing 24 changed files with 266 additions and 195 deletions.
13 changes: 10 additions & 3 deletions Doc/faq/programming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1613,9 +1613,16 @@ method too, and it must do so carefully. The basic implementation of
self.__dict__[name] = value
...

Most :meth:`!__setattr__` implementations must modify
:attr:`self.__dict__ <object.__dict__>` to store
local state for self without causing an infinite recursion.
Many :meth:`~object.__setattr__` implementations call :meth:`!object.__setattr__` to set
an attribute on self without causing infinite recursion::

class X:
def __setattr__(self, name, value):
# Custom logic here...
object.__setattr__(self, name, value)

Alternatively, it is possible to set attributes by inserting
entries into :attr:`self.__dict__ <object.__dict__>` directly.


How do I call a method defined in a base class from a derived class that extends it?
Expand Down
26 changes: 13 additions & 13 deletions Doc/library/ast.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ Root nodes
A Python module, as with :ref:`file input <file-input>`.
Node type generated by :func:`ast.parse` in the default ``"exec"`` *mode*.

*body* is a :class:`list` of the module's :ref:`ast-statements`.
``body`` is a :class:`list` of the module's :ref:`ast-statements`.

*type_ignores* is a :class:`list` of the module's type ignore comments;
``type_ignores`` is a :class:`list` of the module's type ignore comments;
see :func:`ast.parse` for more details.

.. doctest::
Expand All @@ -194,7 +194,7 @@ Root nodes
A single Python :ref:`expression input <expression-input>`.
Node type generated by :func:`ast.parse` when *mode* is ``"eval"``.

*body* is a single node,
``body`` is a single node,
one of the :ref:`expression types <ast-expressions>`.

.. doctest::
Expand All @@ -209,7 +209,7 @@ Root nodes
A single :ref:`interactive input <interactive>`, like in :ref:`tut-interac`.
Node type generated by :func:`ast.parse` when *mode* is ``"single"``.

*body* is a :class:`list` of :ref:`statement nodes <ast-statements>`.
``body`` is a :class:`list` of :ref:`statement nodes <ast-statements>`.

.. doctest::

Expand Down Expand Up @@ -238,9 +238,9 @@ Root nodes
# type: (int, int) -> int
return a + b

*argtypes* is a :class:`list` of :ref:`expression nodes <ast-expressions>`.
``argtypes`` is a :class:`list` of :ref:`expression nodes <ast-expressions>`.

*returns* is a single :ref:`expression node <ast-expressions>`.
``returns`` is a single :ref:`expression node <ast-expressions>`.

.. doctest::

Expand Down Expand Up @@ -1766,9 +1766,9 @@ aliases.

.. class:: TypeVar(name, bound, default_value)

A :class:`typing.TypeVar`. *name* is the name of the type variable.
*bound* is the bound or constraints, if any. If *bound* is a :class:`Tuple`,
it represents constraints; otherwise it represents the bound. *default_value*
A :class:`typing.TypeVar`. ``name`` is the name of the type variable.
``bound`` is the bound or constraints, if any. If ``bound`` is a :class:`Tuple`,
it represents constraints; otherwise it represents the bound. ``default_value``
is the default value; if the :class:`!TypeVar` has no default, this
attribute will be set to ``None``.

Expand Down Expand Up @@ -1796,8 +1796,8 @@ aliases.

.. class:: ParamSpec(name, default_value)

A :class:`typing.ParamSpec`. *name* is the name of the parameter specification.
*default_value* is the default value; if the :class:`!ParamSpec` has no default,
A :class:`typing.ParamSpec`. ``name`` is the name of the parameter specification.
``default_value`` is the default value; if the :class:`!ParamSpec` has no default,
this attribute will be set to ``None``.

.. doctest::
Expand Down Expand Up @@ -1831,8 +1831,8 @@ aliases.

.. class:: TypeVarTuple(name, default_value)

A :class:`typing.TypeVarTuple`. *name* is the name of the type variable tuple.
*default_value* is the default value; if the :class:`!TypeVarTuple` has no
A :class:`typing.TypeVarTuple`. ``name`` is the name of the type variable tuple.
``default_value`` is the default value; if the :class:`!TypeVarTuple` has no
default, this attribute will be set to ``None``.

.. doctest::
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4572,7 +4572,7 @@ written in Python, such as a mail server's external command delivery program.

See the :manpage:`pidfd_open(2)` man page for more details.

.. availability:: Linux >= 5.3
.. availability:: Linux >= 5.3, Android >= :func:`build-time <sys.getandroidapilevel>` API level 31
.. versionadded:: 3.9

.. data:: PIDFD_NONBLOCK
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/signal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ The :mod:`signal` module defines the following functions:

See the :manpage:`pidfd_send_signal(2)` man page for more information.

.. availability:: Linux >= 5.1
.. availability:: Linux >= 5.1, Android >= :func:`build-time <sys.getandroidapilevel>` API level 31
.. versionadded:: 3.9


Expand Down
8 changes: 5 additions & 3 deletions Doc/library/string.rst
Original file line number Diff line number Diff line change
Expand Up @@ -574,11 +574,13 @@ The available presentation types for :class:`float` and
| ``'%'`` | Percentage. Multiplies the number by 100 and displays |
| | in fixed (``'f'``) format, followed by a percent sign. |
+---------+----------------------------------------------------------+
| None | For :class:`float` this is the same as ``'g'``, except |
| None | For :class:`float` this is like the ``'g'`` type, except |
| | that when fixed-point notation is used to format the |
| | result, it always includes at least one digit past the |
| | decimal point. The precision used is as large as needed |
| | to represent the given value faithfully. |
| | decimal point, and switches to the scientific notation |
| | when ``exp >= p - 1``. When the precision is not |
| | specified, the latter will be as large as needed to |
| | represent the given value faithfully. |
| | |
| | For :class:`~decimal.Decimal`, this is the same as |
| | either ``'g'`` or ``'G'`` depending on the value of |
Expand Down
10 changes: 8 additions & 2 deletions Doc/reference/compound_stmts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1217,9 +1217,10 @@ A function definition defines a user-defined function object (see section
: | `parameter_list_no_posonly`
parameter_list_no_posonly: `defparameter` ("," `defparameter`)* ["," [`parameter_list_starargs`]]
: | `parameter_list_starargs`
parameter_list_starargs: "*" [`parameter`] ("," `defparameter`)* ["," ["**" `parameter` [","]]]
parameter_list_starargs: "*" [`star_parameter`] ("," `defparameter`)* ["," ["**" `parameter` [","]]]
: | "**" `parameter` [","]
parameter: `identifier` [":" `expression`]
star_parameter: `identifier` [":" ["*"] `expression`]
defparameter: `parameter` ["=" `expression`]
funcname: `identifier`

Expand Down Expand Up @@ -1326,7 +1327,8 @@ and may only be passed by positional arguments.

Parameters may have an :term:`annotation <function annotation>` of the form "``: expression``"
following the parameter name. Any parameter may have an annotation, even those of the form
``*identifier`` or ``**identifier``. Functions may have "return" annotation of
``*identifier`` or ``**identifier``. (As a special case, parameters of the form
``*identifier`` may have an annotation "``: *expression``".) Functions may have "return" annotation of
the form "``-> expression``" after the parameter list. These annotations can be
any valid Python expression. The presence of annotations does not change the
semantics of a function. The annotation values are available as values of
Expand All @@ -1337,6 +1339,10 @@ enables postponed evaluation. Otherwise, they are evaluated when the function
definition is executed. In this case annotations may be evaluated in
a different order than they appear in the source code.

.. versionchanged:: 3.11
Parameters of the form "``*identifier``" may have an annotation
"``: *expression``". See :pep:`646`.

.. index:: pair: lambda; expression

It is also possible to create anonymous functions (functions not bound to a
Expand Down
6 changes: 4 additions & 2 deletions Doc/reference/datamodel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1061,8 +1061,10 @@ have the following two methods available:

.. doctest::

>>> int.__subclasses__()
[<class 'bool'>, <enum 'IntEnum'>, <flag 'IntFlag'>, <class 're._constants._NamedIntConstant'>, <class 're._ZeroSentinel'>]
>>> class A: pass
>>> class B(A): pass
>>> A.__subclasses__()
[<class 'B'>]

Class instances
---------------
Expand Down
39 changes: 24 additions & 15 deletions Doc/reference/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ A list display is a possibly empty series of expressions enclosed in square
brackets:

.. productionlist:: python-grammar
list_display: "[" [`starred_list` | `comprehension`] "]"
list_display: "[" [`flexible_expression_list` | `comprehension`] "]"

A list display yields a new list object, the contents being specified by either
a list of expressions or a comprehension. When a comma-separated list of
Expand All @@ -309,7 +309,7 @@ A set display is denoted by curly braces and distinguishable from dictionary
displays by the lack of colons separating keys and values:

.. productionlist:: python-grammar
set_display: "{" (`starred_list` | `comprehension`) "}"
set_display: "{" (`flexible_expression_list` | `comprehension`) "}"

A set display yields a new mutable set object, the contents being specified by
either a sequence of expressions or a comprehension. When a comma-separated
Expand Down Expand Up @@ -454,7 +454,7 @@ Yield expressions
.. productionlist:: python-grammar
yield_atom: "(" `yield_expression` ")"
yield_from: "yield" "from" `expression`
yield_expression: "yield" `expression_list` | `yield_from`
yield_expression: "yield" `yield_list` | `yield_from`

The yield expression is used when defining a :term:`generator` function
or an :term:`asynchronous generator` function and
Expand Down Expand Up @@ -485,9 +485,9 @@ When a generator function is called, it returns an iterator known as a
generator. That generator then controls the execution of the generator
function. The execution starts when one of the generator's methods is called.
At that time, the execution proceeds to the first yield expression, where it is
suspended again, returning the value of :token:`~python-grammar:expression_list`
suspended again, returning the value of :token:`~python-grammar:yield_list`
to the generator's caller,
or ``None`` if :token:`~python-grammar:expression_list` is omitted.
or ``None`` if :token:`~python-grammar:yield_list` is omitted.
By suspended, we mean that all local state is
retained, including the current bindings of local variables, the instruction
pointer, the internal evaluation stack, and the state of any exception handling.
Expand Down Expand Up @@ -576,7 +576,7 @@ is already executing raises a :exc:`ValueError` exception.
:meth:`~generator.__next__` method, the current yield expression always
evaluates to :const:`None`. The execution then continues to the next yield
expression, where the generator is suspended again, and the value of the
:token:`~python-grammar:expression_list` is returned to :meth:`__next__`'s
:token:`~python-grammar:yield_list` is returned to :meth:`__next__`'s
caller. If the generator exits without yielding another value, a
:exc:`StopIteration` exception is raised.

Expand Down Expand Up @@ -695,7 +695,7 @@ how a generator object would be used in a :keyword:`for` statement.
Calling one of the asynchronous generator's methods returns an :term:`awaitable`
object, and the execution starts when this object is awaited on. At that time,
the execution proceeds to the first yield expression, where it is suspended
again, returning the value of :token:`~python-grammar:expression_list` to the
again, returning the value of :token:`~python-grammar:yield_list` to the
awaiting coroutine. As with a generator, suspension means that all local state
is retained, including the current bindings of local variables, the instruction
pointer, the internal evaluation stack, and the state of any exception handling.
Expand Down Expand Up @@ -759,7 +759,7 @@ which are used to control the execution of a generator function.
asynchronous generator function is resumed with an :meth:`~agen.__anext__`
method, the current yield expression always evaluates to :const:`None` in the
returned awaitable, which when run will continue to the next yield
expression. The value of the :token:`~python-grammar:expression_list` of the
expression. The value of the :token:`~python-grammar:yield_list` of the
yield expression is the value of the :exc:`StopIteration` exception raised by
the completing coroutine. If the asynchronous generator exits without
yielding another value, the awaitable instead raises a
Expand Down Expand Up @@ -892,7 +892,7 @@ will generally select an element from the container. The subscription of a
:ref:`GenericAlias <types-genericalias>` object.

.. productionlist:: python-grammar
subscription: `primary` "[" `expression_list` "]"
subscription: `primary` "[" `flexible_expression_list` "]"

When an object is subscripted, the interpreter will evaluate the primary and
the expression list.
Expand All @@ -904,9 +904,13 @@ primary is subscripted, the evaluated result of the expression list will be
passed to one of these methods. For more details on when ``__class_getitem__``
is called instead of ``__getitem__``, see :ref:`classgetitem-versus-getitem`.

If the expression list contains at least one comma, it will evaluate to a
:class:`tuple` containing the items of the expression list. Otherwise, the
expression list will evaluate to the value of the list's sole member.
If the expression list contains at least one comma, or if any of the expressions
are starred, the expression list will evaluate to a :class:`tuple` containing
the items of the expression list. Otherwise, the expression list will evaluate
to the value of the list's sole member.

.. versionchanged:: 3.11
Expressions in an expression list may be starred. See :pep:`646`.

For built-in objects, there are two types of objects that support subscription
via :meth:`~object.__getitem__`:
Expand Down Expand Up @@ -1905,10 +1909,12 @@ Expression lists
single: , (comma); expression list

.. productionlist:: python-grammar
starred_expression: ["*"] `or_expr`
flexible_expression: `assignment_expression` | `starred_expression`
flexible_expression_list: `flexible_expression` ("," `flexible_expression`)* [","]
starred_expression_list: `starred_expression` ("," `starred_expression`)* [","]
expression_list: `expression` ("," `expression`)* [","]
starred_list: `starred_item` ("," `starred_item`)* [","]
starred_expression: `expression` | (`starred_item` ",")* [`starred_item`]
starred_item: `assignment_expression` | "*" `or_expr`
yield_list: `expression_list` | `starred_expression` "," [`starred_expression_list`]

.. index:: pair: object; tuple

Expand All @@ -1929,6 +1935,9 @@ the unpacking.
.. versionadded:: 3.5
Iterable unpacking in expression lists, originally proposed by :pep:`448`.

.. versionadded:: 3.11
Any item in an expression list may be starred. See :pep:`646`.

.. index:: pair: trailing; comma

A trailing comma is required only to create a one-item tuple,
Expand Down
2 changes: 1 addition & 1 deletion Doc/tools/templates/download.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{% endif %}

{% block body %}
<h1>{% trans %}Download Python {{ release }} Documentation{% endtrans %}</h1>
<h1>{% trans %}Download Python {{ dl_version }} Documentation{% endtrans %}</h1>

{% if last_updated %}<p><b>{% trans %}Last updated on: {{ last_updated }}.{% endtrans %}</b></p>{% endif %}

Expand Down
11 changes: 6 additions & 5 deletions Lib/_pyrepl/simple_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import _sitebuiltins
import linecache
import functools
import os
import sys
import code

Expand All @@ -50,7 +51,9 @@ def check() -> str:
try:
_get_reader()
except _error as e:
return str(e) or repr(e) or "unknown error"
if term := os.environ.get("TERM", ""):
term = f"; TERM={term}"
return str(str(e) or repr(e) or "unknown error") + term
return ""


Expand Down Expand Up @@ -159,10 +162,8 @@ def maybe_run_command(statement: str) -> bool:
input_n += 1
except KeyboardInterrupt:
r = _get_reader()
if r.last_command and 'isearch' in r.last_command.__name__:
r.isearch_direction = ''
r.console.forgetinput()
r.pop_input_trans()
if r.input_trans is r.isearch_trans:
r.do_cmd(("isearch-end", [""]))
r.pos = len(r.get_unicode())
r.dirty = True
r.refresh()
Expand Down
Loading

0 comments on commit 7472c88

Please sign in to comment.