8000 Merge branch 'main' into lo · python/cpython@991085f · GitHub
[go: up one dir, main page]

Skip to content

Commit 991085f

Browse files
authored
Merge branch 'main' into lo
2 parents 5a83c3d + 9bb202a commit 991085f

File tree

383 files changed

+5782
-4046
lines changed

Some content is hidden

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

383 files changed

+5782
-4046
lines changed

.github/ISSUE_TEMPLATE/bug.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ body:
3939
- "3.10"
4040
- "3.11"
4141
- "3.12"
42+
- "3.13"
4243
- "CPython main branch"
4344
validations:
4445
required: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ gmon.out
4242
.coverage
4343
.mypy_cache/
4444
.pytest_cache/
45+
.ruff_cache/
4546
.DS_Store
4647

4748
*.exe

.pre-commit-config.yaml

Lines changed: 2 additions & 2 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.0.292
3+
rev: v0.1.0
44
hooks:
55
- id: ruff
66
name: Run Ruff on Lib/test/
@@ -12,7 +12,7 @@ repos:
1212
files: ^Tools/clinic/|Lib/test/test_clinic.py
1313

1414
- repo: https://github.com/pre-commit/pre-commit-hooks
15-
rev: v4.4.0
15+
rev: v4.5.0
1616
hooks:
1717
- id: check-toml
1818
exclude: ^Lib/test/test_tomllib/

Doc/c-api/call.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ This is a pointer to a function with the following signature:
108108
Doing so will allow callables such as bound methods to make their onward
109109
calls (which include a prepended *self* argument) very efficiently.
110110

111+
.. versionadded:: 3.8
112+
111113
To call an object that implements vectorcall, use a :ref:`call API <capi-call>`
112114
function as with any other callable.
113115
:c:func:`PyObject_Vectorcall` will usually be most efficient.

Doc/c-api/unicode.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,8 +971,8 @@ These are the UTF-8 codec APIs:
971971
returned buffer always has an extra null byte appended (not included in
972972
*size*), regardless of whether there are any other null code points.
973973
974-
In the case of an error, ``NULL`` is returned with an exception set and no
975-
*size* is stored.
974+
On error, set an exception, set *size* to ``-1`` (if it's not NULL) and
975+
return ``NULL``.
976976
977977
This caches the UTF-8 representation of the string in the Unicode object, and
978978
subsequent calls will return a pointer to the same buffer. The caller is not
@@ -992,11 +992,19 @@ These are the UTF-8 codec APIs:
992992
993993
As :c:func:`PyUnicode_AsUTF8AndSize`, but does not store the size.
994994
995+
Raise an exception if the *unicode* string contains embedded null
996+
characters. To accept embedded null characters and truncate on purpose
997+
at the first null byte, ``PyUnicode_AsUTF8AndSize(unicode, NULL)`` can be
998+
used instead.
999+
9951000
.. versionadded:: 3.3
9961001
9971002
.. versionchanged:: 3.7
9981003
The return type is now ``const char *`` rather of ``char *``.
9991004
1005+
.. versionchanged:: 3.13
1006+
Raise an exception if the string contains embedded null characters.
1007+
10001008
10011009
UTF-32 Codecs
10021010
"""""""""""""

Doc/data/stable_abi.dat

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Doc/glossary.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ Glossary
239239

240240
context manager
241241
An object which controls the environment seen in a :keyword:`with`
242-
statement by defining :meth:`__enter__` and :meth:`__exit__` methods.
242+
statement by defining :meth:`~object.__enter__` and :meth:`~object.__exit__` methods.
243243
See :pep:`343`.
244244

245245
context variable
@@ -636,7 +636,7 @@ Glossary
636636
iterables include all sequence types (such as :class:`list`, :class:`str`,
637637
and :class:`tuple`) and some non-sequence types like :class:`dict`,
638638
:term:`file objects <file object>`, and objects of any classes you define
639-
with an :meth:`__iter__` method or with a :meth:`__getitem__` method
639+
with an :meth:`__iter__` method or with a :meth:`~object.__getitem__` method
640640
that implements :term:`sequence` semantics.
641641

642642
Iterables can be
@@ -1078,17 +1078,17 @@ Glossary
10781078

10791079
sequence
10801080
An :term:`iterable` which supports efficient element access using integer
1081-
indices via the :meth:`__getitem__` special method and defines a
1081+
indices via the :meth:`~object.__getitem__` special method and defines a
10821082
:meth:`__len__` method that returns the length of the sequence.
10831083
Some built-in sequence types are :class:`list`, :class:`str`,
10841084
:class:`tuple`, and :class:`bytes`. Note that :class:`dict` also
1085-
supports :meth:`__getitem__` and :meth:`__len__`, but is considered a
1085+
supports :meth:`~object.__getitem__` and :meth:`__len__`, but is considered a
10861086
mapping rather than a sequence because the lookups use arbitrary
10871087
:term:`immutable` keys rather than integers.
10881088

10891089
The :class:`collections.abc.Sequence` abstract base class
10901090
defines a much richer interface that goes beyond just
1091-
:meth:`__getitem__` and :meth:`__len__`, adding :meth:`count`,
1091+
:meth:`~object.__getitem__` and :meth:`__len__`, adding :meth:`count`,
10921092
:meth:`index`, :meth:`__contains__`, and
10931093
:meth:`__reversed__`. Types that implement this expanded
10941094
interface can be registered explicitly using

Doc/howto/regex.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ You can omit either *m* or *n*; in that case, a reasonable value is assumed for
245245
the missing value. Omitting *m* is interpreted as a lower limit of 0, while
246246
omitting *n* results in an upper bound of infinity.
247247

248+
The simplest case ``{m}`` matches the preceding item exactly *m* times.
249+
For example, ``a/{2}b`` will only match ``'a//b'``.
250+
248251
Readers of a reductionist bent may notice that the three other quantifiers can
249252
all be expressed using this notation. ``{0,}`` is the same as ``*``, ``{1,}``
250253
is equivalent to ``+``, and ``{0,1}`` is the same as ``?``. It's better to use

Doc/library/abc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ a helper class :class:`ABC` to alternatively define ABCs through inheritance:
154154
Finally, the last line makes ``Foo`` a virtual subclass of ``MyIterable``,
155155
even though it does not define an :meth:`~iterator.__iter__` method (it uses
156156
the old-style iterable protocol, defined in terms of :meth:`__len__` and
157-
:meth:`__getitem__`). Note that this will not make ``get_iterator``
157+
:meth:`~object.__getitem__`). Note that this will not make ``get_iterator``
158158
available as a method of ``Foo``, so it is provided separately.
159159

160160

Doc/library/asyncio-eventloop.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ Scheduling callbacks
243243
See the :ref:`concurrency and multithreading <asyncio-multithreading>`
244244
section of the documentation.
245245

246-
.. versionchanged:: 3.7
247-
The *context* keyword-only parameter was added. See :pep:`567`
248-
for more details.
246+
.. versionchanged:: 3.7
247+
The *context* keyword-only parameter was added. See :pep:`567`
248+
for more details.
249249

250250
.. _asyncio-pass-keywords:
251251

@@ -1391,6 +1391,14 @@ Enabling debug mode
13911391
The new :ref:`Python Development Mode <devmode>` can now also be used
13921392
to enable the debug mode.
13931393

1394+
.. attribute:: loop.slow_callback_duration
1395+
1396+
This attribute can be used to set the
1397+
minimum execution duration in seconds that is considered "slow".
1398+
When debug mode is enabled, "slow" callbacks are logged.
1399+
1400+
Default value is 100 milliseconds.
1401+
13941402
.. seealso::
13951403

13961404
The :ref:`debug mode of asyncio <asyncio-debug-mode>`.

Doc/library/bz2.rst

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ The :mod:`bz2` module contains:
9191
and :meth:`~io.IOBase.truncate`.
9292
Iteration and the :keyword:`with` statement are supported.
9393

94-
:class:`BZ2File` also provides the following method:
94+
:class:`BZ2File` also provides the following methods:
9595

9696
.. method:: peek([n])
9797

@@ -106,14 +106,52 @@ The :mod:`bz2` module contains:
106106

107107
.. versionadded:: 3.3
108108

109+
.. method:: fileno()
110+
111+
Return the file descriptor for the underlying file.
112+
113+
.. versionadded:: 3.3
114+
115+
.. method:: readable()
116+
117+
Return whether the file was opened for reading.
118+
119+
.. versionadded:: 3.3
120+
121+
.. method:: seekable()
122+
123+
Return whether the file supports seeking.
124+
125+
.. versionadded:: 3.3
126+
127+
.. method:: writable()
128+
129+
Return whether the file was opened for writing.
130+
131+
.. versionadded:: 3.3
132+
133+
.. method:: read1(size=-1)
134+
135+
Read up to *size* uncompressed bytes, while trying to avoid
136+
making multiple reads from the underlying stream. Reads up to a
137+
buffer's worth of data if size is negative.
138+
139+
Returns ``b''`` if the file is at EOF.
140+
141+
.. versionadded:: 3.3
142+
143+
.. method:: readinto(b)
144+
145+
Read bytes into *b*.
146+
147+
Returns the number of bytes read (0 for EOF).
148+
149+
.. versionadded:: 3.3
150+
109151

110152
.. versionchanged:: 3.1
111153
Support for the :keyword:`with` statement was added.
112154

113-
.. versionchanged:: 3.3
114-
The :meth:`fileno`, :meth:`readable`, :meth:`seekable`, :meth:`writable`,
115-
:meth:`read1` and :meth:`readinto` methods were added.
116-
117155
.. versionchanged:: 3.3
118156
Support was added for *filename* being a :term:`file object` instead of an
119157
actual filename.

Doc/library/code.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,34 @@ build applications which provide an interactive interpreter prompt.
2323
``'__doc__'`` set to ``None``.
2424

2525

26-
.. class:: InteractiveConsole(locals=None, filename="<console>")
26+
.. class:: InteractiveConsole(locals=None, filename="<console>", local_exit=False)
2727

2828
Closely emulate the behavior of the interactive Python interpreter. This class
2929
builds on :class:`InteractiveInterpreter` and adds prompting using the familiar
30-
``sys.ps1`` and ``sys.ps2``, and input buffering.
30+
``sys.ps1`` and ``sys.ps2``, and input buffering. If *local_exit* is True,
31+
``exit()`` and ``quit()`` in the console will not raise :exc:`SystemExit`, but
32+
instead return to the calling code.
3133

34+
.. versionchanged:: 3.13
35+
Added *local_exit* parameter.
3236

33-
.. function:: interact(banner=None, readfunc=None, local=None, exitmsg=None)
37+
.. function:: interact(banner=None, readfunc=None, local=None, exitmsg=None, local_exit=False)
3438

3539
Convenience function to run a read-eval-print loop. This creates a new
3640
instance of :class:`InteractiveConsole` and sets *readfunc* to be used as
3741
the :meth:`InteractiveConsole.raw_input` method, if provided. If *local* is
3842
provided, it is passed to the :class:`InteractiveConsole` constructor for
39-
use as the default namespace for the interpreter loop. The :meth:`interact`
43+
use as the default namespace for the interpreter loop. If *local_exit* is provided,
44+
it is passed to the :class:`InteractiveConsole` constructor. The :meth:`interact`
4045
method of the instance is then run with *banner* and *exitmsg* passed as the
4146
banner and exit message to use, if provided. The console object is discarded
4247
after use.
4348

4449
.. versionchanged:: 3.6
4550
Added *exitmsg* parameter.
4651

52+
.. versionchanged:: 3.13
53+
Added *local_exit* parameter.
4754

4855
.. function:: compile_command(source, filename="<input>", symbol="single")
4956

Doc/library/codecs.rst

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -520,44 +520,46 @@ The base :class:`Codec` class defines these methods which also define the
520520
function interfaces of the stateless encoder and decoder:
521521

522522

523-
.. method:: Codec.encode(input, errors='strict')
523+
.. class:: Codec
524524

525-
Encodes the object *input* and returns a tuple (output object, length consumed).
526-
For instance, :term:`text encoding` converts
527-
a string object to a bytes object using a particular
528-
character set encoding (e.g., ``cp1252`` or ``iso-8859-1``).
525+
.. method:: encode(input, errors='strict')
529526

530-
The *errors* argument defines the error handling to apply.
531-
It defaults to ``'strict'`` handling.
527+
Encodes the object *input* and returns a tuple (output object, length consumed).
528+
For instance, :term:`text encoding` converts
529+
a string object to a bytes object using a particular
530+
character set encoding (e.g., ``cp1252`` or ``iso-8859-1``).
532531

533-
The method may not store state in the :class:`Codec` instance. Use
534-
:class:`StreamWriter` for codecs which have to keep state in order to make
535-
encoding efficient.
532+
The *errors* argument defines the error handling to apply.
533+
It defaults to ``'strict'`` handling.
536534

537-
The encoder must be able to handle zero length input and return an empty object
538-
of the output object type in this situation.
535+
The method may not store state in the :class:`Codec` instance. Use
536+
:class:`StreamWriter` for codecs which have to keep state in order to make
537+
encoding efficient.
539538

539+
The encoder must be able to handle zero length input and return an empty object
540+
of the output object type in this situation.
540541

541-
.. method:: Codec.decode(input, errors='strict')
542542

543-
Decodes the object *input* and returns a tuple (output object, length
544-
consumed). For instance, for a :term:`text encoding`, decoding converts
545-
a bytes object encoded using a particular
546-
character set encoding to a string object.
543+
.. method:: decode(input, errors='strict')
547544

548-
For text encodings and bytes-to-bytes codecs,
549-
*input* must be a bytes object or one which provides the read-only
550-
buffer interface -- for example, buffer objects and memory mapped files.
545+
Decodes the object *input* and returns a tuple (output object, length
546+
consumed). For instance, for a :term:`text encoding`, decoding converts
547+
a bytes object encoded using a particular
548+
character set encoding to a string object.
551549

552-
The *errors* argument defines the error handling to apply.
553-
It defaults to ``'strict'`` handling.
550+
For text encodings and bytes-to-bytes codecs,
551+
*input* must be a bytes object or one which provides the read-only
552+
buffer interface -- for example, buffer objects and memory mapped files.
554553

555-
The method may not store state in the :class:`Codec` instance. Use
556-
:class:`StreamReader` for codecs which have to keep state in order to make
557-
decoding efficient.
554+
The *errors* argument defines the error handling to apply.
555+
It defaults to ``'strict'`` handling.
558556

559-
The decoder must be able to handle zero length input and return an empty object
560-
of the output object type in this situation.
557+
The method may not store state in the :class:`Codec` instance. Use
558+
:class:`StreamReader` for codecs which have to keep state in order to make
559+
decoding efficient.
560+
561+
The decoder must be able to handle zero length input and return an empty object
562+
of the output object type in this situation.
561563

562564

563565
Incremental Encoding and Decoding
@@ -705,7 +707,7 @@ Stream Encoding and Decoding
705707

706708
The :class:`StreamWriter` and :class:`StreamReader` classes provide generic
707709
working interfaces which can be used to implement new encoding submodules very
708-
easily. See :mod:`encodings.utf_8` for an example of how this is done.
710+
easily. See :mod:`!encodings.utf_8` for an example of how this is done.
709711

710712

711713
.. _stream-writer-objects:
@@ -895,9 +897,10 @@ The design is such that one can use the factory functions returned by the
895897
.. class:: StreamRecoder(stream, encode, decode, Reader, Writer, errors='strict')
896898

897899
Creates a :class:`StreamRecoder` instance which implements a two-way conversion:
898-
*encode* and *decode* work on the frontend — the data visible to
899-
code calling :meth:`read` and :meth:`write`, while *Reader* and *Writer*
900-
work on the backend — the data in *stream*.
900+
*encode* and *decode* work on the frontend — the data visible to
901+
code calling :meth:`~StreamReader.read` and :meth:`~StreamWriter.write`,
902+
while *Reader* and *Writer*
903+
work on the backend — the data in *stream*.
901904

902905
You can use these objects to do transparent transcodings, e.g., from Latin-1
903906
to UTF-8 and back.
@@ -1417,8 +1420,8 @@ to :class:`bytes` mappings. They are not supported by :meth:`bytes.decode`
14171420
| | quotedprintable, | quoted printable. | ``quotetabs=True`` / |
14181421
| | quoted_printable | | :meth:`quopri.decode` |
14191422
+----------------------+------------------+------------------------------+------------------------------+
1420-
| uu_codec | uu | Convert the operand using | :meth:`uu.encode` / |
1421-
| | | uuencode. | :meth:`uu.decode` |
1423+
| uu_codec | uu | Convert the operand using | |
1424+
| | | uuencode. | |
14221425
+----------------------+------------------+------------------------------+------------------------------+
14231426
| zlib_codec | zip, zlib | Compress the operand using | :meth:`zlib.compress` / |
14241427
| | | gzip. | :meth:`zlib.decompress` |

0 commit comments

Comments
 (0)
0