Skip to content

Commit ff4814b

Browse files
authored
Merge branch 'main' into ssl-keylogfile-always-supported
2 parents bd004e9 + 9f225e2 commit ff4814b

54 files changed

Lines changed: 1198 additions & 652 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/complex.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ rather than dereferencing them through pointers.
130130
131131
Please note, that these functions are :term:`soft deprecated` since Python
132132
3.15. Avoid using this API in a new code to do complex arithmetic: either use
133-
the `Number Protocol <number>`_ API or use native complex types, like
133+
the :ref:`Number Protocol <number>` API or use native complex types, like
134134
:c:expr:`double complex`.
135135
136136

Doc/extending/first-extension-module.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ Then, create ``meson.build`` containing the following:
164164
165165
.. note::
166166

167-
See `meson-python documentation <meson-python>`_ for details on
167+
See the `meson-python documentation <meson-python_>`_ for details on
168168
configuration.
169169

170170
Now, build install the *project in the current directory* (``.``) via ``pip``:

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.

Doc/library/shlex.rst

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ The :mod:`!shlex` module defines the following functions:
4444
.. versionadded:: 3.8
4545

4646

47-
.. function:: quote(s)
47+
.. function:: quote(s, *, force=False)
4848

4949
Return a shell-escaped version of the string *s*. The returned value is a
5050
string that can safely be used as one token in a shell command line, for
5151
cases where you cannot use a list.
5252

53+
If *force* is :const:`True`, then *s* is unconditionally quoted,
54+
even if it is already safe for a shell without being quoted.
55+
5356
.. _shlex-quote-warning:
5457

5558
.. warning::
@@ -91,8 +94,23 @@ The :mod:`!shlex` module defines the following functions:
9194
>>> command
9295
['ls', '-l', 'somefile; rm -rf ~']
9396

97+
The *force* keyword can be used to produce consistent behavior when
98+
escaping multiple strings:
99+
100+
>>> from shlex import quote
101+
>>> filenames = ['my first file', 'file2', 'file 3']
102+
>>> filenames_some_escaped = [quote(f) for f in filenames]
103+
>>> filenames_some_escaped
104+
["'my first file'", 'file2', "'file 3'"]
105+
>>> filenames_all_escaped = [quote(f, force=True) for f in filenames]
106+
>>> filenames_all_escaped
107+
["'my first file'", "'file2'", "'file 3'"]
108+
94109
.. versionadded:: 3.3
95110

111+
.. versionchanged:: next
112+
The *force* keyword was added.
113+
96114
The :mod:`!shlex` module defines the following class:
97115

98116

Doc/library/stdtypes.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,7 +2616,9 @@ expression support in the :mod:`re` module).
26162616
:func:`re.split`). Splitting an empty string with a specified separator
26172617
returns ``['']``.
26182618

2619-
For example::
2619+
For example:
2620+
2621+
.. doctest::
26202622

26212623
>>> '1,2,3'.split(',')
26222624
['1', '2', '3']
@@ -2634,7 +2636,9 @@ expression support in the :mod:`re` module).
26342636
string or a string consisting of just whitespace with a ``None`` separator
26352637
returns ``[]``.
26362638

2637-
For example::
2639+
For example:
2640+
2641+
.. doctest::
26382642

26392643
>>> '1 2 3'.split()
26402644
['1', '2', '3']
@@ -2646,7 +2650,9 @@ expression support in the :mod:`re` module).
26462650
If *sep* is not specified or is ``None`` and *maxsplit* is ``0``, only
26472651
leading runs of consecutive whitespace are considered.
26482652

2649-
For example::
2653+
For example:
2654+
2655+
.. doctest::
26502656

26512657
>>> "".split(None, 0)
26522658
[]
@@ -2655,7 +2661,7 @@ expression support in the :mod:`re` module).
26552661
>>> " foo ".split(maxsplit=0)
26562662
['foo ']
26572663

2658-
See also :meth:`join`.
2664+
See also :meth:`join` and :meth:`rsplit`.
26592665

26602666

26612667
.. index::

Doc/using/windows.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,12 @@ customization.
455455
Python runtimes, or false to prevent it.
456456
By default, true.
457457

458+
* - ``shebang_templates``
459+
- (none)
460+
- Mapping from shebang line template to alternative command, such as
461+
``py -V:<tag>`` or a substitute string.
462+
See :ref:`pymanager-shebang` for more details.
463+
458464
* - ``log_level``
459465
- ``PYMANAGER_VERBOSE``, ``PYMANAGER_DEBUG``
460466
- Set the default level of output (0-50).
@@ -568,6 +574,30 @@ which the path to the script and any additional arguments will be appended.
568574
This functionality may be disabled by the ``shebang_can_run_anything``
569575
configuration option.
570576

577+
Since version 26.3 of the Python install manager, custom shebang templates may
578+
be added to your configuration file. Add the ``shebang_templates`` object with
579+
one member for each template (the string to match) and the command to use when
580+
the template is matched. Most commands should be ``py -V:<tag>`` (or ``pyw``) to
581+
launch one of your installed runtimes. The ``py -3.<version>`` form is also
582+
allowed, as is a plain ``py`` to launch the default. No other arguments are
583+
supported.
584+
585+
.. code:: json5
586+
587+
{
588+
"shebang_templates": {
589+
"/usr/bin/python": "py",
590+
"/usr/bin/my_custom_python": "py -V:MyCustomPython/3"
591+
}
592+
}
593+
594+
If the substitute command is not ``py`` or ``pyw``, it will be written back into
595+
the shebang and regular handling continues. If launching arbitrary executables
596+
is permitted, then providing a full path will allow you to redirect from Python
597+
to any executable. The template should match either the entire line (ignoring
598+
leading and trailing whitespace), or up to the first space in the shebang line.
599+
600+
571601
.. note::
572602

573603
The behaviour of shebangs in the Python install manager is subtly different

Doc/whatsnew/3.16.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ os
109109
process via a pidfd. Available on Linux 5.6+.
110110
(Contributed by Maurycy Pawłowski-Wieroński in :gh:`149464`.)
111111

112+
shlex
113+
-----
114+
115+
* Add keyword-only parameter *force* to :func:`shlex.quote` to force quoting
116+
a string, even if it is already safe for a shell without being quoted.
117+
(Contributed by Jay Berry in :gh:`148846`.)
118+
112119
xml
113120
---
114121

Include/dynamic_annotations.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ int RunningOnValgrind(void);
461461

462462
#if DYNAMIC_ANNOTATIONS_ENABLED != 0 && defined(__cplusplus)
463463

464+
extern "C++" {
464465
/* _Py_ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racey reads.
465466
466467
Instead of doing
@@ -476,6 +477,8 @@ int RunningOnValgrind(void);
476477
_Py_ANNOTATE_IGNORE_READS_END();
477478
return res;
478479
}
480+
}
481+
479482
/* Apply _Py_ANNOTATE_BENIGN_RACE_SIZED to a static variable. */
480483
#define _Py_ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \
481484
namespace { \

0 commit comments

Comments
 (0)