Skip to content

Commit 0a4c369

Browse files
Merge branch 'main' into gh-132042-optimize-class-creation
2 parents 9434773 + 3e256b9 commit 0a4c369

56 files changed

Lines changed: 891 additions & 452 deletions

Some content is hidden

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

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.11.6
3+
rev: v0.11.8
44
hooks:
55
- id: ruff
66
name: Run Ruff (lint) on Doc/
@@ -22,14 +22,14 @@ repos:
2222
name: Run Ruff (format) on Doc/
2323
args: [--check]
2424
files: ^Doc/
25+
- id: ruff-format
26+
name: Run Ruff (format) on Tools/build/check_warnings.py
27+
args: [--check, --config=Tools/build/.ruff.toml]
28+
files: ^Tools/build/check_warnings.py
2529

2630
- repo: https://github.com/psf/black-pre-commit-mirror
2731
rev: 25.1.0
2832
hooks:
29-
- id: black
30-
name: Run Black on Tools/build/check_warnings.py
31-
files: ^Tools/build/check_warnings.py
32-
args: [--line-length=79]
3333
- id: black
3434
name: Run Black on Tools/jit/
3535
files: ^Tools/jit/

Doc/howto/regex.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,9 +738,12 @@ given location, they can obviously be matched an infinite number of times.
738738
different: ``\A`` still matches only at the beginning of the string, but ``^``
739739
may match at any location inside the string that follows a newline character.
740740

741-
``\Z``
741+
``\z``
742742
Matches only at the end of the string.
743743

744+
``\Z``
745+
The same as ``\z``. For compatibility with old Python versions.
746+
744747
``\b``
745748
Word boundary. This is a zero-width assertion that matches only at the
746749
beginning or end of a word. A word is defined as a sequence of alphanumeric

Doc/library/cmdline.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The following modules have a command-line interface.
2727
* :mod:`pdb`
2828
* :ref:`pickle <pickle-cli>`
2929
* :ref:`pickletools <pickletools-cli>`
30-
* :mod:`platform`
30+
* :ref:`platform <platform-cli>`
3131
* :mod:`poplib`
3232
* :ref:`profile <profile-cli>`
3333
* :mod:`pstats`

Doc/library/fnmatch.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ functions: :func:`fnmatch`, :func:`fnmatchcase`, :func:`.filter`.
111111
>>>
112112
>>> regex = fnmatch.translate('*.txt')
113113
>>> regex
114-
'(?s:.*\\.txt)\\Z'
114+
'(?s:.*\\.txt)\\z'
115115
>>> reobj = re.compile(regex)
116116
>>> reobj.match('foobar.txt')
117117
<re.Match object; span=(0, 10), match='foobar.txt'>

Doc/library/glob.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ The :mod:`glob` module defines the following functions:
134134
>>>
135135
>>> regex = glob.translate('**/*.txt', recursive=True, include_hidden=True)
136136
>>> regex
137-
'(?s:(?:.+/)?[^/]*\\.txt)\\Z'
137+
'(?s:(?:.+/)?[^/]*\\.txt)\\z'
138138
>>> reobj = re.compile(regex)
139139
>>> reobj.match('foo/bar/baz.txt')
140140
<re.Match object; span=(0, 15), match='foo/bar/baz.txt'>

Doc/library/io.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,8 @@ Text I/O
965965
:class:`TextIOBase`.
966966

967967
*encoding* gives the name of the encoding that the stream will be decoded or
968-
encoded with. It defaults to :func:`locale.getencoding`.
968+
encoded with. In :ref:`UTF-8 Mode <utf8-mode>`, this defaults to UTF-8.
969+
Otherwise, it defaults to :func:`locale.getencoding`.
969970
``encoding="locale"`` can be used to specify the current locale's encoding
970971
explicitly. See :ref:`io-text-encoding` for more information.
971972

Doc/library/platform.rst

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
section.
1818

1919

20-
Cross Platform
20+
Cross platform
2121
--------------
2222

2323

@@ -188,7 +188,7 @@ Cross Platform
188188
:attr:`processor` is resolved late instead of immediately.
189189

190190

191-
Java Platform
191+
Java platform
192192
-------------
193193

194194

@@ -206,7 +206,7 @@ Java Platform
206206
and was only useful for Jython support.
207207

208208

209-
Windows Platform
209+
Windows platform
210210
----------------
211211

212212

@@ -240,7 +240,7 @@ Windows Platform
240240
.. versionadded:: 3.8
241241

242242

243-
macOS Platform
243+
macOS platform
244244
--------------
245245

246246
.. function:: mac_ver(release='', versioninfo=('','',''), machine='')
@@ -252,7 +252,7 @@ macOS Platform
252252
Entries which cannot be determined are set to ``''``. All tuple entries are
253253
strings.
254254

255-
iOS Platform
255+
iOS platform
256256
------------
257257

258258
.. function:: ios_ver(system='', release='', model='', is_simulator=False)
@@ -271,7 +271,7 @@ iOS Platform
271271
parameters.
272272

273273

274-
Unix Platforms
274+
Unix platforms
275275
--------------
276276

277277
.. function:: libc_ver(executable=sys.executable, lib='', version='', chunksize=16384)
@@ -287,7 +287,7 @@ Unix Platforms
287287
The file is read and scanned in chunks of *chunksize* bytes.
288288

289289

290-
Linux Platforms
290+
Linux platforms
291291
---------------
292292

293293
.. function:: freedesktop_os_release()
@@ -325,7 +325,7 @@ Linux Platforms
325325
.. versionadded:: 3.10
326326

327327

328-
Android Platform
328+
Android platform
329329
----------------
330330

331331
.. function:: android_ver(release="", api_level=0, manufacturer="", \
@@ -360,6 +360,34 @@ Android Platform
360360

361361
.. versionadded:: 3.13
362362

363+
.. _platform-cli:
364+
365+
Command-line usage
366+
------------------
367+
368+
:mod:`platform` can also be invoked directly using the :option:`-m`
369+
switch of the interpreter::
370+
371+
python -m platform [--terse] [--nonaliased] [{nonaliased,terse} ...]
372+
373+
The following options are accepted:
374+
375+
.. program:: platform
376+
377+
.. option:: --terse
378+
379+
Print terse information about the platform. This is equivalent to
380+
calling :func:`platform.platform` with the *terse* argument set to ``True``.
381+
382+
.. option:: --nonaliased
383+
384+
Print platform information without system/OS name aliasing. This is
385+
equivalent to calling :func:`platform.platform` with the *aliased* argument
386+
set to ``True``.
387+
388+
You can also pass one or more positional arguments (``terse``, ``nonaliased``)
389+
to explicitly control the output format. These behave similarly to their
390+
corresponding options.
363391

364392
Miscellaneous
365393
-------------

Doc/library/re.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ The special characters are:
266266
not a word boundary as outside a set, and numeric escapes
267267
such as ``\1`` are always octal escapes, not group references.
268268
Special sequences which do not match a single character such as ``\A``
269-
and ``\Z`` are not allowed.
269+
and ``\z`` are not allowed.
270270

271271
.. index:: single: ^ (caret); in regular expressions
272272

@@ -661,11 +661,17 @@ character ``'$'``.
661661
matches characters which are neither alphanumeric in the current locale
662662
nor the underscore.
663663

664-
.. index:: single: \Z; in regular expressions
664+
.. index:: single: \z; in regular expressions
665+
single: \Z; in regular expressions
665666

666-
``\Z``
667+
``\z``
667668
Matches only at the end of the string.
668669

670+
.. versionadded:: next
671+
672+
``\Z``
673+
The same as ``\z``. For compatibility with old Python versions.
674+
669675
.. index::
670676
single: \a; in regular expressions
671677
single: \b; in regular expressions

Doc/whatsnew/3.14.rst

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ Summary -- release highlights
7171
* :ref:`PEP 761: Discontinuation of PGP signatures <whatsnew314-pep761>`
7272
* :ref:`PEP 765: Disallow return/break/continue that exit a finally block <whatsnew314-pep765>`
7373
* :ref:`PEP 768: Safe external debugger interface for CPython <whatsnew314-pep768>`
74-
* :ref:`A new type of interpreter <whatsnew314-tail-call>`
74+
* :ref:`A new type of interpreter <whatsnew314-tail-call>`
75+
* :ref:`Syntax highlighting in PyREPL <whatsnew314-pyrepl-highlighting>`,
76+
and color output in :ref:`unittest <whatsnew314-color-unittest>`,
77+
:ref:`argparse <whatsnew314-color-argparse>`,
78+
:ref:`json <whatsnew314-color-json>` and
79+
:ref:`calendar <whatsnew314-color-calendar>` CLIs
7580

7681

7782
Incompatible changes
@@ -474,6 +479,36 @@ Improved error messages
474479
Traceback (most recent call last):
475480
SyntaxError: invalid syntax. Is this intended to be part of the string?
476481
482+
* When strings have incompatible prefixes, the error now shows
483+
which prefixes are incompatible. (Contributed by
484+
Nikita Sobolev in :gh:`133197`.)
485+
486+
.. code-block:: pycon
487+
488+
>>> ub'abc'
489+
File "<python-input-0>", line 1
490+
ub'abc'
491+
^^
492+
SyntaxError: 'u' and 'b' prefixes are incompatible
493+
494+
* Improved error messages when using ``as`` with incompatible targets in:
495+
496+
- Imports: ``import ... as ...``
497+
- From imports: ``from ... import ... as ...``
498+
- Except handlers: ``except ... as ...``
499+
- Pattern-match cases: ``case ... as ...``
500+
501+
(Contributed by Nikita Sobolev in :gh:`123539`,
502+
:gh:`123562`, and :gh:`123440`.)
503+
504+
.. code-block:: pycon
505+
506+
>>> import ast as arr[0]
507+
File "<python-input-1>", line 1
508+
import ast as arr[0]
509+
^^^^^^
510+
SyntaxError: cannot use subscript as import target
511+
477512
478513
.. _whatsnew314-pep741:
479514

@@ -560,6 +595,9 @@ For further information on how to build Python, see
560595
(Contributed by Ken Jin in :gh:`128563`, with ideas on how to implement this
561596
in CPython by Mark Shannon, Garrett Gu, Haoran Xu, and Josh Haberman.)
562597

598+
599+
.. _whatsnew314-pyrepl-highlighting:
600+
563601
Syntax highlighting in PyREPL
564602
-----------------------------
565603

@@ -624,6 +662,11 @@ Other language changes
624662
ASCII :class:`bytes` and :term:`bytes-like objects <bytes-like object>`.
625663
(Contributed by Daniel Pope in :gh:`129349`.)
626664

665+
* Support ``\z`` as a synonym for ``\Z`` in :mod:`regular expressions <re>`.
666+
It is interpreted unambiguously in many other regular expression engines,
667+
unlike ``\Z``, which has subtly different behavior.
668+
(Contributed by Serhiy Storchaka in :gh:`133306`.)
669+
627670
* ``\B`` in :mod:`regular expression <re>` now matches empty input string.
628671
Now it is always the opposite of ``\b``.
629672
(Contributed by Serhiy Storchaka in :gh:`124130`.)
@@ -698,6 +741,17 @@ argparse
698741
and subparser names if mistyped by the user.
699742
(Contributed by Savannah Ostrowski in :gh:`124456`.)
700743

744+
.. _whatsnew314-color-argparse:
745+
746+
* Introduced the optional *color* parameter to
747+
:class:`argparse.ArgumentParser`, enabling color for help text.
748+
This can be controlled via the :envvar:`PYTHON_COLORS` environment
749+
variable as well as the canonical |NO_COLOR|_
750+
and |FORCE_COLOR|_ environment variables.
751+
See also :ref:`using-on-controlling-color`.
752+
(Contributed by Hugo van Kemenade in :gh:`130645`.)
753+
754+
701755
ast
702756
---
703757

@@ -723,6 +777,9 @@ bdb
723777
* The :mod:`bdb` module now supports the :mod:`sys.monitoring` backend.
724778
(Contributed by Tian Gao in :gh:`124533`.)
725779

780+
781+
.. _whatsnew314-color-calendar:
782+
726783
calendar
727784
--------
728785

@@ -1021,6 +1078,8 @@ json
10211078
See the :ref:`JSON command-line interface <json-commandline>` documentation.
10221079
(Contributed by Trey Hunner in :gh:`122873`.)
10231080

1081+
.. _whatsnew314-color-json:
1082+
10241083
* By default, the output of the :ref:`JSON command-line interface <json-commandline>`
10251084
is highlighted in color. This can be controlled via the
10261085
:envvar:`PYTHON_COLORS` environment variable as well as the canonical
@@ -1467,6 +1526,8 @@ unicodedata
14671526
* The Unicode database has been updated to Unicode 16.0.0.
14681527

14691528

1529+
.. _whatsnew314-color-unittest:
1530+
14701531
unittest
14711532
--------
14721533

Grammar/python.gram

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -443,26 +443,30 @@ try_stmt[stmt_ty]:
443443

444444
except_block[excepthandler_ty]:
445445
| invalid_except_stmt_indent
446+
| 'except' e=expression ':' b=block {
447+
_PyAST_ExceptHandler(e, NULL, b, EXTRA) }
448+
| 'except' e=expression 'as' t=NAME ':' b=block {
449+
_PyAST_ExceptHandler(e, ((expr_ty) t)->v.Name.id, b, EXTRA) }
446450
| 'except' e=expressions ':' b=block {
447451
CHECK_VERSION(
448452
excepthandler_ty,
449453
14,
450-
"except expressions without parentheses",
451-
_PyAST_ExceptHandler(e, NULL, b, EXTRA)) }
452-
| 'except' e=expression 'as' t=NAME ':' b=block {
453-
_PyAST_ExceptHandler(e, ((expr_ty) t)->v.Name.id, b, EXTRA) }
454+
"except expressions without parentheses are",
455+
_PyAST_ExceptHandler(e, NULL, b, EXTRA)) }
454456
| 'except' ':' b=block { _PyAST_ExceptHandler(NULL, NULL, b, EXTRA) }
455457
| invalid_except_stmt
456458
except_star_block[excepthandler_ty]:
457459
| invalid_except_star_stmt_indent
460+
| 'except' '*' e=expression ':' b=block {
461+
_PyAST_ExceptHandler(e, NULL, b, EXTRA) }
462+
| 'except' '*' e=expression 'as' t=NAME ':' b=block {
463+
_PyAST_ExceptHandler(e, ((expr_ty) t)->v.Name.id, b, EXTRA) }
458464
| 'except' '*' e=expressions ':' b=block {
459465
CHECK_VERSION(
460466
excepthandler_ty,
461467
14,
462-
"except expressions without parentheses",
468+
"except expressions without parentheses are",
463469
_PyAST_ExceptHandler(e, NULL, b, EXTRA)) }
464-
| 'except' '*' e=expression 'as' t=NAME ':' b=block {
465-
_PyAST_ExceptHandler(e, ((expr_ty) t)->v.Name.id, b, EXTRA) }
466470
| invalid_except_star_stmt
467471
finally_block[asdl_stmt_seq*]:
468472
| invalid_finally_stmt

0 commit comments

Comments
 (0)