[3.13] gh-129011: Update docs for Raw I/O read, readinto, and write (GH-135328) (#150959)
gh-129011: Update docs for Raw I/O read, readinto, and write (GH-135328)
Update `RawIOBase` and `FileIO` documentation to match implementation
behavior around `.read`, `.readinto`, `.readall` and `.write`.
In particular:
- They may make more than one system call (PEP-475)
- Add warnings if `.write()` requires a wrapping retry loop (see: gh-126606)
- "Raw I/O" `.write`` may not write all bytes
- `buffering=0` example results in a "Raw I/O"
(cherry picked from commit e4db68b9c990ed1bb7562094bee2e73f4450d42b)
ass_subscript_slice() returned early when the computed slice length
was zero, bypassing validation performed for non-empty slices.
(cherry picked from commit fc9c4db1302f8be7527e70cf0938b629985a1d72)
[3.13] Correct Stable ABI documentation for METH_FASTCALL (GH-149593) (GH-150851)
The current documentation says:
>
> METH_FASTCALL
> Part of the Stable ABI since version 3.7.
>
> [...]
>
> Added in version 3.7.
>
> Changed in version 3.10: METH_FASTCALL is now part of the stable ABI.
so is contradictory about when it was added to the Stable ABI. Looking at the header it seems like 3.10 is right.
(cherry picked from commit 58beae7319c58d850184d621d6635de23f71a229)
[3.13] gh-91099: fix[imaplib]: call Exception with string instance (GH-31823) (#150809)
* bpo-46943: fix[imaplib]: call Exception with string instance
Adjust the behavior of 'login' to be similar to `authenticate()`,
where self.error is called with a str() instance.
(cherry picked from commit 29805f00a1b65163230d17584c30e2b955086abb)
Co-authored-by: Florian Best <spaceone@users.noreply.github.com> Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
The following classes are documented publicly as functions, and are
therefore updated internally (`__class_getitem__.__doc__`) but not in the
public docs:
- functools.partial
- itertools.chain
The following builtin types have updates to `__class_getitem__.__doc__`
but not to any documentation pages:
- union objects are now documented as "supporting class-level []",
rather than anything to do with generics.
- Templates might be generic over a single type (union, in theory) or
over a TypeVarTuple. As this is not currently fully settled, it is
marked with a comment and a mild hint that it is a single type is used
(namely, "type" is singular rather than "types", plural)
* Apply suggestions from code review
* Correct several class getitem docs
And expand the text for tuples.
* Add notes on generic typing of builtins
* Fix typo in tuple.__class_getitem__ docstring
* Typo fix: malformed refs
Fix `generic` links which weren't marked as `:ref:`.
* Strike unnecessary docs on generic-ness
* Apply suggestions from code review
These are applied at both the originally indicated locations and in the
corresponding docstring definitions.
* Update Doc/library/re.rst
* Update Objects/enumobject.c
* Remove tuple generic doc in 'stdtypes' page
This is covered in more detail in the cross-linked typing documentation.
The other copy of this documentation -- in the docstring for
`tuple.__class_getitem__` -- is left in place.
* Fix whitespace around new doc of generics
Per review, do not introduce or remove whitespace such that section
breaks are altered by the introduction of doc on various generic types.
In most cases, this is a removal of an extra line.
In one case (Arrays), it is the reintroduction of a line.
Additionally, two other minor fixes are included:
- incorrect indent on 'defaultdicts'
- make `mappingproxy.__class_getitem__.__doc__` consistent with other
mapping type generic docs
* Move placement of memoryview generic note
Previous placement was at the end of the main docstring, which is
consistent with other types but places it after a section on various
methods (which makes it read somewhat inconsistently). Moving it up
helps resolve.
* Ensure sphinxdoc does not start sentences lowercase
Lowercase class names at the start of sentences are marked out with the
`class` role. In the case of `deque`, documentation already refers to
these as `Deques`, so this form is preferred.
* Apply suggestions from code review
* Fix line endings and wrap more tightly
Line endings fixed by pre-commit ; also re-wrapped the MappingProxyType
text which was too long.
BufferedRandom does not inherit from BufferedReader and BufferedWriter
in the C implementation.
(cherry picked from commit 551bc2cb5ed4719c35ca3ea0f320167dd750389e)
Petr Viktorin [Tue, 2 Jun 2026 16:12:42 +0000 (18:12 +0200)]
[3.13] gh-149079: Fix O(n^2) canonical ordering in unicodedata.normalize() (GH-149080) (#150780)
Replace the insertion sort used for canonical ordering of combining
characters with a hybrid approach: insertion sort for short runs (< 20)
and counting sort for longer runs, reducing worst-case complexity from
O(n^2) to O(n). This prevents denial of service via crafted Unicode
strings with many combining characters in alternating CCC order.
(cherry picked from commit 991224b1e8311c85f198f6dd8208bf8cff7fc26f)
Victor Stinner [Tue, 2 Jun 2026 13:13:35 +0000 (15:13 +0200)]
[3.13] gh-89554: Document _thread.LockType as a class (#150684) (#150786)
gh-89554: Document _thread.LockType as a class (#150684)
_thread.LockType is a class (the type of lock objects), but was documented
with the ".. data::" directive, so ":class:" cross-references to it cannot
resolve against a py:class target.
Switch the entry to ".. class::", move it next to the lock methods, and
document acquire(), release() and locked() as methods of the class. Keep
the old _thread.lock.* URL fragments working with raw HTML anchors.
[3.13] gh-89554: Document weakref type objects as classes (GH-150678) (GH-150758)
Use the "class" directive instead of "data" for ReferenceType,
ProxyType and CallableProxyType.
(cherry picked from commit 10c421970beca89df92a918f2247fb8850d3b6cc)
Co-authored-by: Bernát Gábor <gaborjbernat@gmail.com>
[3.13] gh-89554: Document NoneType, NotImplementedType and EllipsisType as classes (GH-150682) (GH-150757)
Always use the directive and the role "class" instead of "data" for
NoneType, NotImplementedType and EllipsisType.
(cherry picked from commit e40190e104c81b61cdc6f71a391e28de53bbc1d8)
Co-authored-by: Bernát Gábor <gaborjbernat@gmail.com>
[3.13] gh-150644: Tag Apple system log messages as public. (GH-150645) (#150740)
macOS 26 changed the default visibility of "dynamic" system messages. This
changes the logging strategy to tag all messages as "public" so they are
visible in the system log without special configuration.
(cherry picked from commit 71fc4c66d3e675a5481b6b76e6c707c9b6f1e0e0)
Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
Victor Stinner [Mon, 1 Jun 2026 15:44:54 +0000 (17:44 +0200)]
[3.13] gh-150436: Skip subprocess test on STATUS_DLL_INIT_FAILED (#150704) (#150721)
gh-150436: Skip subprocess test on STATUS_DLL_INIT_FAILED (#150704)
If a subprocess spawned with CREATE_NEW_CONSOLE creation flag fails
with STATUS_DLL_INIT_FAILED return code, skip the test. It's likely a
memory allocation failure in the desktop heap memory which caused the
DLL init failure.
[3.13] gh-149489: Fix ElementTree serialization to HTML (GH-149490) (GH-150596) (GH-150609)
* The content of elements "xmp", "iframe", "noembed", "noframes",
and "plaintext" is no longer escaped.
* The "plaintext" element no longer have the closing tag.
(cherry picked from commit c42e6d3f1a066186f74d3971df4c512bc11c7997)
[3.13] gh-139808: Add branch protections for aarch64 in asm_trampoline.S (GH-130864) (GH-150189) (#150194)
[3.14] gh-139808: Add branch protections for aarch64 in asm_trampoline.S (GH-130864) (GH-150189)
gh-139808: Add branch protections for aarch64 in asm_trampoline.S (GH-130864)
Apply protection against ROP/JOP attacks for aarch64 on asm_trampoline.S.
The BTI flag must be applied in assembler sources for this class
of attacks to be mitigated on newer aarch64 processors.
See also:
https://sourceware.org/annobin/annobin.html/Test-branch-protection.html
and
https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/enabling-pac-and-bti-on-aarch64
The 3.14 backport makes Python/jit_unwind.c changes in
Python/perf_jit_trampoline.c.
[3.13] gh-150046: Fix `test_add_python_opts` to ignore `PYTHON*` env vars (GH-150089) (#150563)
gh-150046: Fix `test_add_python_opts` to ignore `PYTHON*` env vars (GH-150089)
Avoid the runtime environment from affecting the tests' behaviours,
which notably checks the warning filters which can be controlled by
various PYTHON environment variables.
(cherry picked from commit ef2246f788832a64ba7c5215c8e72f8e539e59b4)
ThreadingMock._increment_mock_call() was not thread-safe.
Multiple threads calling the mock simultaneously could lose
increments due to race conditions on call_count and other
attributes.
Fix by overriding _increment_mock_call in ThreadingMixin
and wrapping it with the existing _mock_calls_events_lock.
(cherry picked from commit 388e023fe1197c1ffed374520ed45df4ac72b8f5)
[3.13] gh-149902: Remove dead packaging docs link and add a new section for external resources (GH-150030) (#150239)
Co-authored-by: Mia Albert <micha@2231puppy.tech> Co-authored-by: Stan Ulbrych <stan@python.org> Co-authored-by: Ned Batchelder <ned@nedbatchelder.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
[3.13] gh-137571: Protect against possible UnboundLocalError in gzip._GzipReader.read() (GH-150222) (GH-150231)
This has not been observed in practice, but we cannot be 100% sure that
it will not happen with some weird gzip data.
(cherry picked from commit 28eac9a7263ad8dcfa9b536aa238549131857e0f)
Jelle Zijlstra [Fri, 22 May 2026 05:09:41 +0000 (22:09 -0700)]
[3.13] gh-149995: Update typing.py docstrings and documentation (#150217)
Some of these docstrings read as if they were written when typing.py was
first written, and things have evolved since then.
A few motivations:
- Call protocols protocols instead of ABCs. They are also ABCs, but the fact
they are protocols is more relevant to typing.
- Avoid recommending direct use of .__annotations__ and steer users to
annotationlib instead.
- For TypedDict, mention NotRequired before total=False since it is more
general and probably more frequently useful.
- For overloads, mention runtime use first instead of stub use. I think early on
there was talk of allowing overload only in stubs, but it is now heavily used at
runtime too and that's more likely to be relevant to users.
(cherry picked from commit f159419ae2ef1aebbd90ce9427b55e27738c960c)
Shamil [Wed, 20 May 2026 03:33:22 +0000 (06:33 +0300)]
[3.13] gh-142831: Fix use-after-free in json encoder during re-entrant mutation (gh-142851) (#150079)
gh-142831: Fix use-after-free in json encoder during re-entrant mutation (gh-142851)
User callbacks invoked during JSON encoding (e.g. the `default` callback or
a custom string encoder) can mutate or clear the dict or sequence being
encoded, invalidating borrowed references to items, keys, and values. Hold
strong references unconditionally while iterating.
`faulthandler_traverse` visits Python objects owned by `_PyRuntime`, not
by the module instance. With multi-phase init allowing multiple module
instances, each instance's GC traversal decrements `gc_refs` on the same
runtime-owned objects, driving it negative when two instances are
collected simultaneously.
(cherry picked from commit 56737483c2ffdaadfec648fd38d409c6b10941c0)
[3.13] Link to existing rules in compound_stmts.rst (GH-149811) (GH-149838)
Link to existing rules in compound_stmts.rst (GH-149811)
In gh-138418, `!` was added to links to rules that don't exist in
the docs, in order to silence broken link warnings.
However, productionlist doesn't parse the `!`, which ends up in
the rendered documentation. (It's possible that gh-127835 broke
the `!` support.)
Replace the names with ones that appear in docs:
- `star_named_expression` in the grammar corresponds to
`flexible_expression` in the docs
- `star_named_expressions` in the grammar corresponds to
`flexible_expression_list` in the docs
- `named_expression` in the grammar corresponds to
`assignment_expression` in the docs
Having two sets of names isn't great of course. Consolidating them
is tracked in (subissues of) gh-127833.
(cherry picked from commit c37529293d1e05081cb4e8668162c76583b88007)
RFC 2047 Section 6.2 requires that "any 'linear-white-space' that
separates a pair of adjacent 'encoded-word's is ignored." The modern
header value parser correctly implements that for unstructured headers,
but had missed a case in structured headers. This could cause a parsed
address header to include extraneous spaces in a display-name.
Switch to @bitdancer's fix from review feedback. Recharacterize space
between ews as fws after parsing in get_phrase.
RDM: This fix is dependent on the fact that "subsequent" atoms will never have
leading whitespace because that's been consumed already. I don't think
it's worth adding extra code for the possibility of leading whitespace
because the parser won't produce it. It's a bit of parser fragility in the
face of code changes, but I think that's a minor concern given the
parser design (which is that it consumes whitespace greedily)
(cherry picked from commit 7a4c6dfb8839eb05fb87baf70364680e45001dd4)
Co-authored-by: Mike Edmunds <medmunds@gmail.com> Co-authored-by: R David Murray <rdmurray@bitdance.com>