Skip to content

Commit 0be970e

Browse files
authored
Merge branch 'main' into fix-issue-46375
2 parents 9c6e8ad + 29a920e commit 0be970e

109 files changed

Lines changed: 3398 additions & 573 deletions

File tree

Some content is hidden

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

.github/SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Security Policy
22

33
Python [provides a security policy and threat model](https://devguide.python.org/security/policy/)
4-
in the Python Development Guide documenting what bugs are vulnerabilities,
4+
in the Python Developer's Guide documenting what bugs are vulnerabilities,
55
how to structure reports, and what versions of Python accept reports.
66

77
Python Security Response Team (PSRT) members

Doc/c-api/long.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
7171
on failure.
7272
7373
74+
.. c:function:: PyObject* PyLong_FromUnsignedLongLong(unsigned long long v)
75+
76+
Return a new :c:type:`PyLongObject` object from a C :c:expr:`unsigned long long`,
77+
or ``NULL`` on failure.
78+
79+
7480
.. c:function:: PyObject* PyLong_FromInt32(int32_t value)
7581
PyObject* PyLong_FromInt64(int64_t value)
7682
@@ -81,12 +87,6 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
8187
.. versionadded:: 3.14
8288
8389
84-
.. c:function:: PyObject* PyLong_FromUnsignedLongLong(unsigned long long v)
85-
86-
Return a new :c:type:`PyLongObject` object from a C :c:expr:`unsigned long long`,
87-
or ``NULL`` on failure.
88-
89-
9090
.. c:function:: PyObject* PyLong_FromUInt32(uint32_t value)
9191
PyObject* PyLong_FromUInt64(uint64_t value)
9292

Doc/c-api/typeobj.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2975,13 +2975,13 @@ Buffer Object Structures
29752975
steps:
29762976

29772977
(1) Check if the request can be met. If not, raise :exc:`BufferError`,
2978-
set :c:expr:`view->obj` to ``NULL`` and return ``-1``.
2978+
set ``view->obj`` to ``NULL`` and return ``-1``.
29792979

29802980
(2) Fill in the requested fields.
29812981

29822982
(3) Increment an internal counter for the number of exports.
29832983

2984-
(4) Set :c:expr:`view->obj` to *exporter* and increment :c:expr:`view->obj`.
2984+
(4) Set ``view->obj`` to *exporter* and increment ``view->obj``.
29852985

29862986
(5) Return ``0``.
29872987

@@ -3007,10 +3007,10 @@ Buffer Object Structures
30073007
schemes can be used:
30083008

30093009
* Re-export: Each member of the tree acts as the exporting object and
3010-
sets :c:expr:`view->obj` to a new reference to itself.
3010+
sets ``view->obj`` to a new reference to itself.
30113011

30123012
* Redirect: The buffer request is redirected to the root object of the
3013-
tree. Here, :c:expr:`view->obj` will be a new reference to the root
3013+
tree. Here, ``view->obj`` will be a new reference to the root
30143014
object.
30153015

30163016
The individual fields of *view* are described in section
@@ -3064,7 +3064,7 @@ Buffer Object Structures
30643064
*view* argument.
30653065

30663066

3067-
This function MUST NOT decrement :c:expr:`view->obj`, since that is
3067+
This function MUST NOT decrement ``view->obj``, since that is
30683068
done automatically in :c:func:`PyBuffer_Release` (this scheme is
30693069
useful for breaking reference cycles).
30703070

Doc/howto/functional.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ first calculation. ::
10421042
>>> functools.reduce(operator.concat, [])
10431043
Traceback (most recent call last):
10441044
...
1045-
TypeError: reduce() of empty sequence with no initial value
1045+
TypeError: reduce() of empty iterable with no initial value
10461046
>>> functools.reduce(operator.mul, [1, 2, 3], 1)
10471047
6
10481048
>>> functools.reduce(operator.mul, [], 1)

Doc/library/bisect.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ example uses :py:func:`~bisect.bisect` to look up a letter grade for an exam sco
200200
based on a set of ordered numeric breakpoints: 90 and up is an 'A', 80 to 89 is
201201
a 'B', and so on::
202202

203-
>>> def grade(score)
203+
>>> def grade(score):
204204
... i = bisect([60, 70, 80, 90], score)
205205
... return "FDCBA"[i]
206206
...

Doc/library/collections.abc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ Notes on using :class:`Set` and :class:`MutableSet` as a mixin:
456456
The :class:`Set` mixin provides a :meth:`!_hash` method to compute a hash value
457457
for the set; however, :meth:`~object.__hash__` is not defined because not all sets
458458
are :term:`hashable` or immutable. To add set hashability using mixins,
459-
inherit from both :meth:`Set` and :meth:`Hashable`, then define
459+
inherit from both :class:`Set` and :class:`Hashable`, then define
460460
``__hash__ = Set._hash``.
461461

462462
.. seealso::

Doc/library/collections.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ variants of :deco:`functools.lru_cache`:
12331233
.. testcode::
12341234

12351235
from collections import OrderedDict
1236-
from time import time
1236+
from time import monotonic
12371237

12381238
class TimeBoundedLRU:
12391239
"LRU Cache that invalidates and refreshes old entries."
@@ -1248,10 +1248,10 @@ variants of :deco:`functools.lru_cache`:
12481248
if args in self.cache:
12491249
self.cache.move_to_end(args)
12501250
timestamp, result = self.cache[args]
1251-
if time() - timestamp <= self.maxage:
1251+
if monotonic() - timestamp <= self.maxage:
12521252
return result
12531253
result = self.func(*args)
1254-
self.cache[args] = time(), result
1254+
self.cache[args] = monotonic(), result
12551255
if len(self.cache) > self.maxsize:
12561256
self.cache.popitem(last=False)
12571257
return result

Doc/library/difflib.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ Finally, we compare the two:
724724

725725
>>> result = list(d.compare(text1, text2))
726726

727-
``result`` is a list of strings, so let's pretty-print it:
727+
``result`` is a list of strings, so let's pretty-print it::
728728

729729
>>> from pprint import pprint
730730
>>> pprint(result)
@@ -739,7 +739,7 @@ Finally, we compare the two:
739739
'? ++++ ^ ^\n',
740740
'+ 5. Flat is better than nested.\n']
741741

742-
As a single multi-line string it looks like this:
742+
As a single multi-line string it looks like this::
743743

744744
>>> import sys
745745
>>> sys.stdout.writelines(result)

Doc/library/importlib.resources.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ For all the following functions:
240240

241241
.. versionchanged:: 3.13
242242
Multiple *path_names* are accepted.
243-
*encoding* and *errors* must be given as keyword arguments.
244243

245244

246245
.. function:: is_resource(anchor, *path_names)

Doc/library/io.rst

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ will raise a :exc:`TypeError`. So will giving a :class:`bytes` object to the
3838
Operations that used to raise :exc:`IOError` now raise :exc:`OSError`, since
3939
:exc:`IOError` is now an alias of :exc:`OSError`.
4040

41+
.. _text-io:
4142

4243
Text I/O
4344
^^^^^^^^
@@ -65,6 +66,7 @@ In-memory text streams are also available as :class:`StringIO` objects::
6566
The text stream API is described in detail in the documentation of
6667
:class:`TextIOBase`.
6768

69+
.. _binary-io:
6870

6971
Binary I/O
7072
^^^^^^^^^^
@@ -103,6 +105,13 @@ stream by opening a file in binary mode with buffering disabled::
103105

104106
The raw stream API is described in detail in the docs of :class:`RawIOBase`.
105107

108+
.. warning::
109+
Raw I/O is a low-level interface and methods generally must have their return
110+
values checked and be explicitly retried to ensure an operation completes.
111+
For instance :meth:`~RawIOBase.write` returns the number of bytes written
112+
which may be less than the number of bytes provided (a partial write).
113+
High-level I/O objects like :ref:`binary-io` and :ref:`text-io` implement
114+
retry behavior.
106115

107116
.. _io-text-encoding:
108117

@@ -478,8 +487,11 @@ I/O Base Classes
478487

479488
Read up to *size* bytes from the object and return them. As a convenience,
480489
if *size* is unspecified or -1, all bytes until EOF are returned.
481-
Otherwise, only one system call is ever made. Fewer than *size* bytes may
482-
be returned if the operating system call returns fewer than *size* bytes.
490+
491+
Attempts to make only one system call but will retry if interrupted and
492+
the signal handler does not raise an exception (see :pep:`475` for the
493+
rationale). This means fewer than *size* bytes may be returned if the
494+
operating system call returns fewer than *size* bytes.
483495

484496
If 0 bytes are returned, and *size* was not 0, this indicates end of file.
485497
If the object is in non-blocking mode and no bytes are available,
@@ -493,13 +505,19 @@ I/O Base Classes
493505
Read and return all the bytes from the stream until EOF, using multiple
494506
calls to the stream if necessary.
495507

508+
If ``0`` bytes are returned this indicates end of file. If the object is in
509+
non-blocking mode and the underlying :meth:`read` returns ``None``
510+
indicating no bytes are available, ``None`` is returned.
511+
496512
.. method:: readinto(b, /)
497513

498514
Read bytes into a pre-allocated, writable
499515
:term:`bytes-like object` *b*, and return the
500516
number of bytes read. For example, *b* might be a :class:`bytearray`.
501-
If the object is in non-blocking mode and no bytes
502-
are available, ``None`` is returned.
517+
518+
If ``0`` is returned and ``len(b)`` is not ``0``, this indicates end of file. If
519+
the object is in non-blocking mode and no bytes are available, ``None`` is
520+
returned.
503521

504522
.. method:: write(b, /)
505523

@@ -513,6 +531,13 @@ I/O Base Classes
513531
this method returns, so the implementation should only access *b*
514532
during the method call.
515533

534+
.. warning::
535+
536+
This function does not ensure all bytes are written or an exception is
537+
thrown. Callers may implement that behavior by checking the return
538+
value and, if it is less than the length of *b*, looping with additional
539+
write calls until all unwritten bytes are written. High-level I/O
540+
objects like :ref:`binary-io` and :ref:`text-io` implement retry behavior.
516541

517542
.. class:: BufferedIOBase
518543

@@ -641,7 +666,11 @@ Raw File I/O
641666
.. class:: FileIO(name, mode='r', closefd=True, opener=None)
642667

643668
A raw binary stream representing an OS-level file containing bytes data. It
644-
inherits from :class:`RawIOBase`.
669+
inherits from :class:`RawIOBase` and implements its low-level access design.
670+
This means :meth:`~RawIOBase.write` does not guarantee all bytes are written
671+
and :meth:`~RawIOBase.read` may read less bytes than requested even when more
672+
bytes may be present in the underlying file. To get "write all" and
673+
"read at least" behavior, use :ref:`binary-io`.
645674

646675
The *name* can be one of two things:
647676

@@ -661,10 +690,6 @@ Raw File I/O
661690
implies writing, so this mode behaves in a similar way to ``'w'``. Add a
662691
``'+'`` to the mode to allow simultaneous reading and writing.
663692

664-
The :meth:`~RawIOBase.read` (when called with a positive argument),
665-
:meth:`~RawIOBase.readinto` and :meth:`~RawIOBase.write` methods on this
666-
class will only make one system call.
667-
668693
A custom opener can be used by passing a callable as *opener*. The underlying
669694
file descriptor for the file object is then obtained by calling *opener* with
670695
(*name*, *flags*). *opener* must return an open file descriptor (passing
@@ -676,6 +701,13 @@ Raw File I/O
676701
See the :func:`open` built-in function for examples on using the *opener*
677702
parameter.
678703

704+
.. warning::
705+
:class:`FileIO` is a low-level I/O object and members, such as
706+
:meth:`~RawIOBase.read` and :meth:`~RawIOBase.write`, need to have their
707+
return values checked explicitly in a retry loop to implement "write all"
708+
and "read at least" behavior. High-level I/O objects :ref:`binary-io` and
709+
:ref:`text-io` implement retry behavior.
710+
679711
.. versionchanged:: 3.3
680712
The *opener* parameter was added.
681713
The ``'x'`` mode was added.

0 commit comments

Comments
 (0)