Skip to content

Commit d569c5f

Browse files
committed
Merge remote-tracking branch 'upstream/main' into known
2 parents 202e1e7 + 8136606 commit d569c5f

Some content is hidden

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

44 files changed

+325
-355
lines changed

Doc/library/re.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,14 @@ Match objects support the following methods and attributes:
13271327
>>> m[2] # The second parenthesized subgroup.
13281328
'Newton'
13291329

1330+
Named groups are supported as well::
1331+
1332+
>>> m = re.match(r"(?P<first_name>\w+) (?P<last_name>\w+)", "Isaac Newton")
1333+
>>> m['first_name']
1334+
'Isaac'
1335+
>>> m['last_name']
1336+
'Newton'
1337+
13301338
.. versionadded:: 3.6
13311339

13321340

Doc/library/typing.rst

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ annotations. These include:
7878
*Introducing* :data:`TypeVarTuple`
7979
* :pep:`647`: User-Defined Type Guards
8080
*Introducing* :data:`TypeGuard`
81+
* :pep:`655`: Marking individual TypedDict items as required or potentially-missing
82+
*Introducing* :data:`Required` and :data:`NotRequired`
8183
* :pep:`673`: Self type
8284
*Introducing* :data:`Self`
8385
* :pep:`675`: Arbitrary Literal String Type
@@ -1022,6 +1024,18 @@ These can be used as types in annotations using ``[]``, each having a unique syn
10221024

10231025
.. versionadded:: 3.8
10241026

1027+
.. data:: Required
1028+
1029+
.. data:: NotRequired
1030+
1031+
Special typing constructs that mark individual keys of a :class:`TypedDict`
1032+
as either required or non-required respectively.
1033+
1034+
For more information, see :class:`TypedDict` and
1035+
:pep:`655` ("Marking individual TypedDict items as required or potentially-missing").
1036+
1037+
.. versionadded:: 3.11
1038+
10251039
.. data:: Annotated
10261040

10271041
A type, introduced in :pep:`593` (``Flexible function and variable
@@ -1706,8 +1720,21 @@ These are not used in annotations. They are building blocks for declaring types.
17061720
Point2D = TypedDict('Point2D', {'in': int, 'x-y': int})
17071721

17081722
By default, all keys must be present in a ``TypedDict``. It is possible to
1709-
override this by specifying totality.
1710-
Usage::
1723+
mark individual keys as non-required using :data:`NotRequired`::
1724+
1725+
class Point2D(TypedDict):
1726+
x: int
1727+
y: int
1728+
label: NotRequired[str]
1729+
1730+
# Alternative syntax
1731+
Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': NotRequired[str]})
1732+
1733+
This means that a ``Point2D`` ``TypedDict`` can have the ``label``
1734+
key omitted.
1735+
1736+
It is also possible to mark all keys as non-required by default
1737+
by specifying a totality of ``False``::
17111738

17121739
class Point2D(TypedDict, total=False):
17131740
x: int
@@ -1721,6 +1748,21 @@ These are not used in annotations. They are building blocks for declaring types.
17211748
``True`` as the value of the ``total`` argument. ``True`` is the default,
17221749
and makes all items defined in the class body required.
17231750

1751+
Individual keys of a ``total=False`` ``TypedDict`` can be marked as
1752+
required using :data:`Required`::
1753+
1754+
class Point2D(TypedDict, total=False):
1755+
x: Required[int]
1756+
y: Required[int]
1757+
label: str
1758+
1759+
# Alternative syntax
1760+
Point2D = TypedDict('Point2D', {
1761+
'x': Required[int],
1762+
'y': Required[int],
1763+
'label': str
1764+
}, total=False)
1765+
17241766
It is possible for a ``TypedDict`` type to inherit from one or more other ``TypedDict`` types
17251767
using the class-based syntax.
17261768
Usage::
@@ -1785,11 +1827,16 @@ These are not used in annotations. They are building blocks for declaring types.
17851827

17861828
``Point2D.__required_keys__`` and ``Point2D.__optional_keys__`` return
17871829
:class:`frozenset` objects containing required and non-required keys, respectively.
1788-
Currently the only way to declare both required and non-required keys in the
1789-
same ``TypedDict`` is mixed inheritance, declaring a ``TypedDict`` with one value
1790-
for the ``total`` argument and then inheriting it from another ``TypedDict`` with
1791-
a different value for ``total``.
1792-
Usage::
1830+
1831+
Keys marked with :data:`Required` will always appear in ``__required_keys__``
1832+
and keys marked with :data:`NotRequired` will always appear in ``__optional_keys__``.
1833+
1834+
For backwards compatibility with Python 3.10 and below,
1835+
it is also possible to use inheritance to declare both required and
1836+
non-required keys in the same ``TypedDict`` . This is done by declaring a
1837+
``TypedDict`` with one value for the ``total`` argument and then
1838+
inheriting from it in another ``TypedDict`` with a different value for
1839+
``total``::
17931840

17941841
>>> class Point2D(TypedDict, total=False):
17951842
... x: int
@@ -1807,6 +1854,10 @@ These are not used in annotations. They are building blocks for declaring types.
18071854

18081855
.. versionadded:: 3.8
18091856

1857+
.. versionchanged:: 3.11
1858+
Added support for marking individual keys as :data:`Required` or :data:`NotRequired`.
1859+
See :pep:`655`.
1860+
18101861
.. versionchanged:: 3.11
18111862
Added support for generic ``TypedDict``\ s.
18121863

Doc/library/warnings.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,19 @@ the disposition of the match. Each entry is a tuple of the form (*action*,
154154
+---------------+----------------------------------------------+
155155

156156
* *message* is a string containing a regular expression that the start of
157-
the warning message must match. The expression is compiled to always be
158-
case-insensitive.
157+
the warning message must match, case-insensitively. In :option:`-W` and
158+
:envvar:`PYTHONWARNINGS`, *message* is a literal string that the start of the
159+
warning message must contain (case-insensitively), ignoring any whitespace at
160+
the start or end of *message*.
159161

160162
* *category* is a class (a subclass of :exc:`Warning`) of which the warning
161163
category must be a subclass in order to match.
162164

163-
* *module* is a string containing a regular expression that the module name must
164-
match. The expression is compiled to be case-sensitive.
165+
* *module* is a string containing a regular expression that the start of the
166+
fully-qualified module name must match, case-sensitively. In :option:`-W` and
167+
:envvar:`PYTHONWARNINGS`, *module* is a literal string that the
168+
fully-qualified module name must be equal to (case-sensitively), ignoring any
169+
whitespace at the start or end of *module*.
165170

166171
* *lineno* is an integer that the line number where the warning occurred must
167172
match, or ``0`` to match all line numbers.
@@ -207,8 +212,7 @@ Some examples::
207212
error::ResourceWarning # Treat ResourceWarning messages as errors
208213
default::DeprecationWarning # Show DeprecationWarning messages
209214
ignore,default:::mymodule # Only report warnings triggered by "mymodule"
210-
error:::mymodule[.*] # Convert warnings to errors in "mymodule"
211-
# and any subpackages of "mymodule"
215+
error:::mymodule # Convert warnings to errors in "mymodule"
212216

213217

214218
.. _default-warning-filter:

Doc/whatsnew/2.5.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
1212
This article explains the new features in Python 2.5. The final release of
1313
Python 2.5 is scheduled for August 2006; :pep:`356` describes the planned
14-
release schedule.
14+
release schedule. Python 2.5 was released on September 19, 2006.
1515

1616
The changes in Python 2.5 are an interesting mix of language and library
1717
improvements. The library enhancements will be more important to Python's user

Doc/whatsnew/2.6.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
This saves the maintainer some effort going through the SVN logs
5050
when researching a change.
5151
52-
This article explains the new features in Python 2.6, released on October 1
52+
This article explains the new features in Python 2.6, released on October 1,
5353
2008. The release schedule is described in :pep:`361`.
5454

5555
The major theme of Python 2.6 is preparing the migration path to

Doc/whatsnew/3.0.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
5454
This article explains the new features in Python 3.0, compared to 2.6.
5555
Python 3.0, also known as "Python 3000" or "Py3K", is the first ever
56-
*intentionally backwards incompatible* Python release. There are more
57-
changes than in a typical release, and more that are important for all
58-
Python users. Nevertheless, after digesting the changes, you'll find
56+
*intentionally backwards incompatible* Python release. Python 3.0 was released on December 3, 2008.
57+
There are more changes than in a typical release, and more that are important for all
58+
Python users. Nevertheless, after digesting the changes, you'll find
5959
that Python really hasn't changed all that much -- by and large, we're
6060
mostly fixing well-known annoyances and warts, and removing a lot of
6161
old cruft.

Doc/whatsnew/3.1.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
when researching a change.
4848
4949
This article explains the new features in Python 3.1, compared to 3.0.
50+
Python 3.1 was released on June 27, 2009.
5051

5152

5253
PEP 372: Ordered Dictionaries

Doc/whatsnew/3.10.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
when researching a change.
4848
4949
This article explains the new features in Python 3.10, compared to 3.9.
50-
50+
Python 3.10 was released on October 4, 2021.
5151
For full details, see the :ref:`changelog <changelog>`.
5252

5353
Summary -- Release highlights

Doc/whatsnew/3.12.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ Removed
115115

116116
(Contributed by Erlend E. Aasland in :gh:`92548`)
117117

118+
* The ``--experimental-isolated-subinterpreters`` configure flag
119+
(and corresponding ``EXPERIMENTAL_ISOLATED_SUBINTERPRETERS``)
120+
have been removed.
121+
118122

119123
Porting to Python 3.12
120124
======================

Doc/whatsnew/3.2.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
This saves the maintainer the effort of going through the SVN log
4949
when researching a change.
5050
51-
This article explains the new features in Python 3.2 as compared to 3.1. It
51+
This article explains the new features in Python 3.2 as compared to 3.1.
52+
Python 3.2 was released on February 20, 2011. It
5253
focuses on a few highlights and gives a few examples. For full details, see the
5354
`Misc/NEWS
5455
<https://github.com/python/cpython/blob/076ca6c3c8df3030307e548d9be792ce3c1c6eea/Misc/NEWS>`_

0 commit comments

Comments
 (0)