Skip to content

Commit 2922cff

Browse files
authored
Merge branch 'main' into gh-71199-build-as-os
2 parents a0266b8 + b968417 commit 2922cff

55 files changed

Lines changed: 668 additions & 157 deletions

Some content is hidden

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

‎Doc/c-api/dict.rst‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,14 @@ Dictionary objects
472472
473473
.. c:function:: int PyDict_Update(PyObject *a, PyObject *b)
474474
475-
This is the same as ``PyDict_Merge(a, b, 1)`` in C, and is similar to
476-
``a.update(b)`` in Python except that :c:func:`PyDict_Update` doesn't fall
477-
back to the iterating over a sequence of key value pairs if the second
478-
argument has no "keys" attribute. Return ``0`` on success or ``-1`` if an
479-
exception was raised.
475+
This is the same as ``PyDict_Merge(a, b, 1)`` in C.
476+
477+
Similar to ``a.update(b)`` in Python, except that this function
478+
does not fall back to the iterating over a sequence of key-value pairs
479+
if *b* is not a mapping.
480+
Use :c:func:`PyDict_MergeFromSeq2` for this case.
481+
482+
Return ``0`` on success or ``-1`` if an exception was raised.
480483
481484
.. note::
482485

‎Doc/library/dis.rst‎

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -621,10 +621,14 @@ operations on it as if it was a Python list. The top of the stack corresponds to
621621

622622
.. opcode:: POP_ITER
623623

624-
Removes the iterator from the top of the stack.
624+
Removes the iterator and the value pushed with it by :opcode:`GET_ITER`
625+
from the top of the stack.
625626

626627
.. versionadded:: 3.14
627628

629+
.. versionchanged:: 3.15
630+
Two values are now removed.
631+
628632

629633
.. opcode:: POP_TOP
630634

@@ -644,11 +648,15 @@ operations on it as if it was a Python list. The top of the stack corresponds to
644648

645649
.. opcode:: END_SEND
646650

647-
Implements ``del STACK[-2]``.
651+
Implements ``del STACK[-3:-1]``.
648652
Used to clean up when a generator exits.
649653

650654
.. versionadded:: 3.12
651655

656+
.. versionchanged:: 3.15
657+
The receiver and the value pushed with it by :opcode:`GET_ITER` are
658+
removed, instead of only the receiver.
659+
652660

653661
.. opcode:: COPY (i)
654662

@@ -712,17 +720,23 @@ result back on the stack.
712720
Implements ``STACK[-1] = ~STACK[-1]``.
713721

714722

715-
.. opcode:: GET_ITER
716-
717-
Implements ``STACK[-1] = iter(STACK[-1])``.
723+
.. opcode:: GET_ITER (yield_from)
718724

725+
Replaces ``STACK[-1]`` with an iterator for it and pushes a second value,
726+
which is used by :opcode:`FOR_ITER`, :opcode:`SEND` and :opcode:`POP_ITER`.
719727

720-
.. opcode:: GET_YIELD_FROM_ITER
728+
For some built-in sequence types, such as :class:`list` and :class:`tuple`,
729+
the object itself is left on the stack as a "virtual iterator" and the
730+
index to start iterating from is pushed. Otherwise, implements
731+
``STACK[-1] = iter(STACK[-1])`` and pushes ``NULL``.
721732

722-
If ``STACK[-1]`` is a :term:`generator iterator` or :term:`coroutine` object
723-
it is left as is. Otherwise, implements ``STACK[-1] = iter(STACK[-1])``.
733+
If *yield_from* is non-zero, the instruction is used for ``yield from``:
734+
a :term:`coroutine` object is left as is, unless the current code is
735+
a regular generator, in which case :exc:`TypeError` is raised.
724736

725-
.. versionadded:: 3.5
737+
.. versionchanged:: 3.15
738+
A second value is now pushed after the iterator. The *yield_from*
739+
argument was added, replacing the ``GET_YIELD_FROM_ITER`` instruction.
726740

727741

728742
.. opcode:: TO_BOOL
@@ -1425,14 +1439,21 @@ iterations of the loop.
14251439

14261440
.. opcode:: FOR_ITER (delta)
14271441

1428-
``STACK[-1]`` is an :term:`iterator`. Call its :meth:`~iterator.__next__` method.
1442+
``STACK[-2]`` is an :term:`iterator` (or a virtual iterator, see
1443+
:opcode:`GET_ITER`) and ``STACK[-1]`` is the value pushed with it by
1444+
:opcode:`GET_ITER`. Get the next item, calling the iterator's
1445+
:meth:`~iterator.__next__` method if needed.
14291446
If this yields a new value, push it on the stack (leaving the iterator below
14301447
it). If the iterator indicates it is :term:`exhausted` then the byte code counter is
14311448
incremented by *delta*.
14321449

14331450
.. versionchanged:: 3.12
14341451
Up until 3.11 the iterator was popped when it was exhausted.
14351452

1453+
.. versionchanged:: 3.15
1454+
The iterator is now followed on the stack by the value pushed with it
1455+
by :opcode:`GET_ITER`.
1456+
14361457
.. opcode:: LOAD_GLOBAL (namei)
14371458

14381459
Loads the global named ``co_names[namei>>1]`` onto the stack.
@@ -1810,15 +1831,21 @@ iterations of the loop.
18101831

18111832
.. opcode:: SEND (delta)
18121833

1813-
Equivalent to ``STACK[-1] = STACK[-2].send(STACK[-1])``. Used in ``yield from``
1814-
and ``await`` statements.
1834+
Equivalent to ``STACK[-1] = STACK[-3].send(STACK[-1])``. Used in ``yield from``
1835+
and ``await`` statements. ``STACK[-2]`` is the value pushed with the
1836+
receiver by :opcode:`GET_ITER`; if the receiver is a virtual iterator,
1837+
it is advanced as by :opcode:`FOR_ITER`.
18151838

18161839
If the call raises :exc:`StopIteration`, pop the top value from the stack,
18171840
push the exception's ``value`` attribute, and increment the bytecode counter
18181841
by *delta*.
18191842

18201843
.. versionadded:: 3.11
18211844

1845+
.. versionchanged:: 3.15
1846+
The receiver is now at ``STACK[-3]``, followed by the value pushed with
1847+
it by :opcode:`GET_ITER`.
1848+
18221849

18231850
.. opcode:: HAVE_ARGUMENT
18241851

‎Doc/library/http.client.rst‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ HTTPConnection Objects
312312
but there is a request body, one of those
313313
header fields will be added automatically. If
314314
*body* is ``None``, the Content-Length header is set to ``0`` for
315-
methods that expect a body (``PUT``, ``POST``, and ``PATCH``). If
315+
methods that expect a body (``PUT``, ``POST``, ``PATCH``, and ``QUERY``). If
316316
*body* is a string or a bytes-like object that is not also a
317317
:term:`file <file object>`, the Content-Length header is
318318
set to its length. Any other type of *body* (files
@@ -369,6 +369,9 @@ HTTPConnection Objects
369369
*continue_timeout* value must be greater than zero, otherwise
370370
:exc:`ValueError` is raised.
371371

372+
.. versionchanged:: next
373+
``QUERY`` was added to the methods that expect a body.
374+
372375
.. method:: HTTPConnection.getresponse(support_continue=False)
373376

374377
Should be called after a request is sent to get the response from the server.

‎Doc/library/http.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ Property Indicates that Details
194194
<HTTPMethod.PATCH>,
195195
<HTTPMethod.POST>,
196196
<HTTPMethod.PUT>,
197+
<HTTPMethod.QUERY>,
197198
<HTTPMethod.TRACE>]
198199

199200
.. _http-methods:
@@ -217,4 +218,5 @@ Method Enum Name Details
217218
``OPTIONS`` ``OPTIONS`` HTTP Semantics :rfc:`9110`, Section 9.3.7
218219
``TRACE`` ``TRACE`` HTTP Semantics :rfc:`9110`, Section 9.3.8
219220
``PATCH`` ``PATCH`` HTTP/1.1 :rfc:`5789`
221+
``QUERY`` ``QUERY`` The HTTP QUERY Method :rfc:`10008`
220222
=========== =================================== ==================================================================

‎Doc/library/io.rst‎

Lines changed: 75 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,81 @@ I/O base classes
526526
write calls until all unwritten bytes are written. High-level I/O
527527
objects like :ref:`binary-io` and :ref:`text-io` implement retry behavior.
528528

529+
530+
Raw file I/O
531+
^^^^^^^^^^^^
532+
533+
.. class:: FileIO(name, mode='r', closefd=True, opener=None)
534+
535+
A raw binary stream representing an OS-level file containing bytes data. It
536+
inherits from :class:`RawIOBase` and implements its low-level access design.
537+
This means :meth:`~RawIOBase.write` does not guarantee all bytes are written
538+
and :meth:`~RawIOBase.read` may read less bytes than requested even when more
539+
bytes may be present in the underlying file. To get "write all" and
540+
"read at least" behavior, use :ref:`binary-io`.
541+
542+
The *name* can be one of two things:
543+
544+
* a character string or :class:`bytes` object representing the path to the
545+
file which will be opened. In this case closefd must be ``True`` (the default)
546+
otherwise an error will be raised.
547+
* an integer representing the number of an existing OS-level file descriptor
548+
to which the resulting :class:`FileIO` object will give access. When the
549+
FileIO object is closed this fd will be closed as well, unless *closefd*
550+
is set to ``False``.
551+
552+
The *mode* can be ``'r'``, ``'w'``, ``'x'`` or ``'a'`` for reading
553+
(default), writing, exclusive creation or appending. The file will be
554+
created if it doesn't exist when opened for writing or appending; it will be
555+
truncated when opened for writing. :exc:`FileExistsError` will be raised if
556+
it already exists when opened for creating. Opening a file for creating
557+
implies writing, so this mode behaves in a similar way to ``'w'``. Add a
558+
``'+'`` to the mode to allow simultaneous reading and writing.
559+
560+
A custom opener can be used by passing a callable as *opener*. The underlying
561+
file descriptor for the file object is then obtained by calling *opener* with
562+
(*name*, *flags*). *opener* must return an open file descriptor (passing
563+
:mod:`os.open` as *opener* results in functionality similar to passing
564+
``None``).
565+
566+
The newly created file is :ref:`non-inheritable <fd_inheritance>`.
567+
568+
See the :func:`open` built-in function for examples on using the *opener*
569+
parameter.
570+
571+
.. warning::
572+
:class:`FileIO` is a low-level I/O object and members, such as
573+
:meth:`~RawIOBase.read` and :meth:`~RawIOBase.write`, need to have their
574+
return values checked explicitly in a retry loop to implement "write all"
575+
and "read at least" behavior. High-level I/O objects :ref:`binary-io` and
576+
:ref:`text-io` implement retry behavior.
577+
578+
.. versionchanged:: 3.3
579+
The *opener* parameter was added.
580+
The ``'x'`` mode was added.
581+
582+
.. versionchanged:: 3.4
583+
The file is now non-inheritable.
584+
585+
:class:`FileIO` provides these data attributes in addition to those from
586+
:class:`RawIOBase` and :class:`IOBase`:
587+
588+
.. attribute:: mode
589+
590+
The mode as given in the constructor.
591+
592+
.. attribute:: name
593+
594+
The file name. This is the file descriptor of the file when no name is
595+
given in the constructor.
596+
597+
598+
Buffered streams
599+
^^^^^^^^^^^^^^^^
600+
601+
Buffered I/O streams provide a higher-level interface to an I/O device
602+
than raw I/O does.
603+
529604
.. class:: BufferedIOBase
530605

531606
Base class for binary streams that support some kind of buffering.
@@ -647,80 +722,6 @@ I/O base classes
647722
so the implementation should only access *b* during the method call.
648723

649724

650-
Raw file I/O
651-
^^^^^^^^^^^^
652-
653-
.. class:: FileIO(name, mode='r', closefd=True, opener=None)
654-
655-
A raw binary stream representing an OS-level file containing bytes data. It
656-
inherits from :class:`RawIOBase` and implements its low-level access design.
657-
This means :meth:`~RawIOBase.write` does not guarantee all bytes are written
658-
and :meth:`~RawIOBase.read` may read less bytes than requested even when more
659-
bytes may be present in the underlying file. To get "write all" and
660-
"read at least" behavior, use :ref:`binary-io`.
661-
662-
The *name* can be one of two things:
663-
664-
* a character string or :class:`bytes` object representing the path to the
665-
file which will be opened. In this case closefd must be ``True`` (the default)
666-
otherwise an error will be raised.
667-
* an integer representing the number of an existing OS-level file descriptor
668-
to which the resulting :class:`FileIO` object will give access. When the
669-
FileIO object is closed this fd will be closed as well, unless *closefd*
670-
is set to ``False``.
671-
672-
The *mode* can be ``'r'``, ``'w'``, ``'x'`` or ``'a'`` for reading
673-
(default), writing, exclusive creation or appending. The file will be
674-
created if it doesn't exist when opened for writing or appending; it will be
675-
truncated when opened for writing. :exc:`FileExistsError` will be raised if
676-
it already exists when opened for creating. Opening a file for creating
677-
implies writing, so this mode behaves in a similar way to ``'w'``. Add a
678-
``'+'`` to the mode to allow simultaneous reading and writing.
679-
680-
A custom opener can be used by passing a callable as *opener*. The underlying
681-
file descriptor for the file object is then obtained by calling *opener* with
682-
(*name*, *flags*). *opener* must return an open file descriptor (passing
683-
:mod:`os.open` as *opener* results in functionality similar to passing
684-
``None``).
685-
686-
The newly created file is :ref:`non-inheritable <fd_inheritance>`.
687-
688-
See the :func:`open` built-in function for examples on using the *opener*
689-
parameter.
690-
691-
.. warning::
692-
:class:`FileIO` is a low-level I/O object and members, such as
693-
:meth:`~RawIOBase.read` and :meth:`~RawIOBase.write`, need to have their
694-
return values checked explicitly in a retry loop to implement "write all"
695-
and "read at least" behavior. High-level I/O objects :ref:`binary-io` and
696-
:ref:`text-io` implement retry behavior.
697-
698-
.. versionchanged:: 3.3
699-
The *opener* parameter was added.
700-
The ``'x'`` mode was added.
701-
702-
.. versionchanged:: 3.4
703-
The file is now non-inheritable.
704-
705-
:class:`FileIO` provides these data attributes in addition to those from
706-
:class:`RawIOBase` and :class:`IOBase`:
707-
708-
.. attribute:: mode
709-
710-
The mode as given in the constructor.
711-
712-
.. attribute:: name
713-
714-
The file name. This is the file descriptor of the file when no name is
715-
given in the constructor.
716-
717-
718-
Buffered streams
719-
^^^^^^^^^^^^^^^^
720-
721-
Buffered I/O streams provide a higher-level interface to an I/O device
722-
than raw I/O does.
723-
724725
.. class:: BytesIO(initial_bytes=b'')
725726

726727
A binary stream using an in-memory bytes buffer. It inherits from

‎Doc/tools/removed-ids.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ library/asyncio-task.html: terminating-a-task-group
3434
library/dis.html: opcode-DELETE_ATTR
3535
library/dis.html: opcode-DELETE_GLOBAL
3636
library/dis.html: opcode-DELETE_NAME
37+
library/dis.html: opcode-GET_YIELD_FROM_ITER
3738
library/asyncio-llapi-index.html: event-loop-policies
3839

3940
deprecations/index.html: pending-removal-in-python-3-15

‎Doc/whatsnew/3.16.rst‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,13 @@ gzip
508508
(Contributed by Marin Misur in :gh:`91372`.)
509509

510510

511+
http
512+
----
513+
514+
* Add the ``QUERY`` HTTP method (:rfc:`10008`) to :class:`~http.HTTPMethod`.
515+
(Contributed by Michiel W. Beijen in :gh:`153309`.)
516+
517+
511518
http.client
512519
-----------
513520

@@ -1408,6 +1415,28 @@ that may require changes to your code.
14081415
:exc:`TypeError`.
14091416
(Contributed by Serhiy Storchaka in :gh:`152587`.)
14101417

1418+
* :func:`urllib.parse.urlsplit` and :func:`urllib.parse.urlparse` now raise
1419+
:exc:`ValueError` when the URL is parsed if the port is not a decimal
1420+
number or is outside the range 0--65535. Previously, the error was only
1421+
raised when the :attr:`!port` attribute was read. This also affects
1422+
:func:`~urllib.parse.urljoin`, and :func:`~urllib.parse.urldefrag` for
1423+
URLs with a fragment. Code which never read :attr:`!port` may now fail
1424+
on URLs such as:
1425+
1426+
* SCP-style addresses given a scheme, such as
1427+
``git+ssh://git@github.com:org/repo.git``;
1428+
* multi-host URLs with ports, such as
1429+
``mongodb://h1:27017,h2:27017/db`` or
1430+
``postgresql://h1:5432,h2:5433/db``;
1431+
* URL templates with a placeholder port, such as
1432+
``http://localhost:{port}/``.
1433+
1434+
These are not valid URLs under :rfc:`3986`. To process them, split off
1435+
the netloc yourself before calling :func:`~urllib.parse.urlsplit`, for
1436+
example by replacing it with a placeholder host, or fill in templates
1437+
before parsing them.
1438+
(Contributed by Miguel Brito and Senthil Kumaran in :gh:`88037`.)
1439+
14111440
* :class:`uuid.UUID` now consistently raises :exc:`TypeError` when the
14121441
*bytes* or *bytes_le* argument is not a :class:`bytes` object.
14131442
Previously, some invalid inputs raised :exc:`AssertionError` or

‎Include/cpython/initconfig.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ typedef struct {
1515
} _type;
1616
const char *func;
1717
const char *err_msg;
18+
#if defined(__cplusplus) && defined(__clang__) && __clang_major__ < 22
19+
// gh-160436: clang < 22 warns in the implicit copy/move members
20+
int exitcode;
21+
#else
1822
Py_DEPRECATED(3.16) int exitcode;
23+
#endif
1924
} PyStatus;
2025

2126
PyAPI_FUNC(PyStatus) PyStatus_Ok(void);

0 commit comments

Comments
 (0)