Commit graph

15880 commits

Author SHA1 Message Date
Edward Xu
41eb8ee2bb
gh-148613: Fix race in gc_set_threshold and gc_get_threshold (#150356) 2026-06-03 16:58:26 +05:30
Stephen Rosen
50fe49c879
gh-150319: Replace all documentation which says "See PEP 585" (#150325)
* Replace all documentation which says "See PEP 585"

The following classes in the stdlib get simple updates:

- array.array
- asyncio.Future
- asyncio.Task
- collections.defaultdict
- collections.deque
- contextvars.ContextVar
- contextvars.Token
- ctypes.Array
- os.DirEntry
- re.Match
- re.Pattern
- string.templatelib.Interpolation
- string.templatelib.Template
- types.MappingProxyType
- queue.SimpleQueue
- weakref.ref

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:

- BaseExceptionGroup
- coroutines (from generators)
- dict
- enumerate
- frozendict
- frozenset
- generators (and async generators)
- list
- memoryview
- set
- slice
- tuple

Special cases:

- 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

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>

* Correct several class getitem docs

And expand the text for tuples.

Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>

* 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

Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>

* Apply suggestions from code review

These are applied at both the originally indicated locations and in the
corresponding docstring definitions.

Co-authored-by: Alex Waygood <66076021+AlexWaygood@users.noreply.github.com>

* Update Doc/library/re.rst

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>

* Update Objects/enumobject.c

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>

* 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

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* 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.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* 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

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Fix line endings and wrap more tightly

Line endings fixed by pre-commit ; also re-wrapped the MappingProxyType
text which was too long.

* Use 'ContextVars' style in sphinx doc

---------

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>
Co-authored-by: Alex Waygood <66076021+AlexWaygood@users.noreply.github.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-06-02 21:13:34 +01:00
Seth Larson
991224b1e8
gh-149079: Fix O(n^2) canonical ordering in unicodedata.normalize() (GH-149080)
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.

Co-authored-by: ch4n3-yoon <ch4n3.yoon@gmail.com>
Co-authored-by: Seokchan Yoon <13852925+ch4n3-yoon@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <stan@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
2026-06-02 11:39:50 +02:00
Sepehr Rasouli
60fdb3192b
gh-149738: Fix segmentation fault bug in sqllite3 (#149754)
Deleting the `row_factory` or `text_factory` attribute is no longer allowed.
2026-06-02 11:07:08 +02:00
Bernát Gábor
c79e18a8e5
gh-150717: Avoid mark-array allocation for groupless regex patterns (GH-150719)
state_init() always did PyMem_New(state->mark, groups*2), which for a
pattern with no capturing groups is PyMem_Malloc(0) -- a real allocation
(plus matching free) on every match/search/fullmatch call, for an array
that is never read: groupless patterns emit no MARK opcodes and group 0's
span is taken from state->start/ptr.

Guard the allocation with `if (pattern->groups)`. state->mark stays NULL
(set by the preceding memset), and both the error path and state_fini
already PyMem_Free(NULL) safely.
2026-06-02 10:45:30 +03:00
Sergey B Kirpichev
59abdf8207
gh-115119: Remove superfluous TEST_COVERAGE private macro from _decimal module (GH-149756)
It was previously shared with `libmpdec`, which is no longer vendored.
2026-06-01 13:41:21 -05:00
Thomas Kowalski
c5516e7e37
gh-150157: Fix critical section for PyDict_Next() in _pickle.c (GH-150158) 2026-06-01 17:32:13 +03:00
sobolevn
cc0269334f
gh-149534: Fix unification of defaultdict and frozendict with | (#149539) 2026-06-01 16:26:49 +03:00
Thomas Kowalski
c98773633c
gh-149046: fix: correctly handle str subclasses in io.StringIO (#149047) 2026-06-01 13:01:57 +00:00
Sergey B Kirpichev
46b5e3e941
gh-80480: Remove deprecated 'u' array type code (#149535)
Reuse array.typecodes in tests.
2026-06-01 11:57:55 +00:00
Sergey B Kirpichev
5b5ffce05c
Correct frexp() docs for zero and non-finite numbers (GH-149753)
0.5 <= abs(m) < 1 is only true for finite nonzero numbers
2026-05-31 07:29:44 +00:00
Thomas Kowalski
56bd9ea676
gh-150372: Add missing null check on completer_word_break_characters in readline.c (GH-150251) 2026-05-30 19:26:05 +00:00
Thomas Kowalski
1e18c45495
gh-150406: Check result of PyThread_allocate_lock() for netdb_lock (GH-150407) 2026-05-30 16:25:40 +00:00
Serhiy Storchaka
1c7011d8fe
gh-150560: Fix crash in XML parser on invalid XML with multi-byte encoding (GH-150568) 2026-05-30 00:23:32 +03:00
Chien Wong
cf2cd0be82
gh-115988: Add ARM64 and RISCV BCJ filters constants in lzma module (GH-115989)
---------

Signed-off-by: Chien Wong <m@xv97.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2026-05-28 08:05:03 -07:00
Neko Asakura
39bd44fc70
gh-148871: make LOAD_COMMON_CONSTANT use immortal stackref borrows (GH-149625) 2026-05-28 12:27:37 +01:00
Serhiy Storchaka
7de4fcd445
gh-149571: Fix the C implementation of Element.itertext() (GH-149929)
It no longer emits text for comments and processing instructions.
2026-05-27 13:23:28 +03:00
Serhiy Storchaka
8ab7b43a14
gh-62259: Add support of multi-byte encodings in the XML parser (GH-149860)
Supported encodings: "cp932", "cp949", "cp950", "Big5","EUC-JP",
"GB2312", "GBK", "johab", and "Shift_JIS".

Partially supported encodings (only BMP characters): "Big5-HKSCS",
"EUC_JIS-2004", "EUC_JISX0213", "Shift_JIS-2004", "Shift_JISX0213",
"utf-8-sig" and non-standard aliases like "UTF8" (without hyphen).

The parser now raises ValueError for known unsupported
multi-byte encodings such us "ISO-2022-JP" or "raw-unicode-escape"
instead of failing later, when encounter non-ASCII data.
2026-05-26 19:40:25 +00:00
AN Long
ec23ec6870
gh-149931: Fix memory leaks on failed realloc (#149932) 2026-05-26 01:37:14 +01:00
Pablo Galindo Salgado
a5be25d3bd
gh-149619: Harden _remote_debugging error paths (#150349) 2026-05-25 23:22:46 +01:00
Donghee Na
c714b56798
gh-150114: Log the memory usage in regrtest on macOS (gh-150396) 2026-05-26 00:03:06 +09:00
Victor Stinner
dfe7ef6292
gh-150114: Log the memory usage in regrtest on FreeBSD (#150280)
Add _testcapi.get_process_memory_usage().
On FreeBSD, _testcapi is now linked to libkvm.
2026-05-25 13:45:55 +00:00
Pieter Eendebak
43c60ec2fd
gh-149449: Fix use-after-free in _PyUnicode_GetNameCAPI (#150323)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2026-05-24 16:17:38 +00:00
Serhiy Storchaka
287c98f4cb
gh-150285: Fix too long docstrings in Argument Clinic code (GH-150338) 2026-05-24 16:16:12 +03:00
Serhiy Storchaka
a5cb7c34dd
gh-150285: Fix too long docstrings in the os module (GH-150296) 2026-05-24 15:04:01 +03:00
Serhiy Storchaka
9da7923835
gh-150285: Fix too long docstrings in the pyexpat module (GH-150294) 2026-05-24 15:03:45 +03:00
Serhiy Storchaka
9fceb1c0c5
gh-150285: Fix too long docstrings in the zstd module (GH-150291) 2026-05-24 15:03:22 +03:00
Serhiy Storchaka
0466560b31
gh-150285: Fix too long docstrings in the sqlite3 module (GH-150290) 2026-05-24 15:02:58 +03:00
Serhiy Storchaka
cdc499ae77
gh-150285: Fix too long docstrings in the _remote_debugging module (GH-150289) 2026-05-24 15:02:43 +03:00
Serhiy Storchaka
6bed57a3b6
gh-150285: Fix too long docstrings in the decimal module (GH-150288) 2026-05-24 15:02:32 +03:00
Serhiy Storchaka
160dc74122
gh-150285: Fix too long docstrings in the io module (GH-150287) 2026-05-24 15:02:21 +03:00
Serhiy Storchaka
4c0fe2d134
gh-150285: Fix too long docstrings in the curses module (GH-150286) 2026-05-24 15:02:12 +03:00
Pieter Eendebak
dfeeee990b
gh-145192: improve performance of PySequence_GetSlice (#145193) 2026-05-23 15:45:50 +05:30
Kumar Aditya
e8545ed3ea
gh-149816: add missing critical section on self in buffered_iternext (#150295) 2026-05-23 08:57:13 +00:00
Victor Stinner
a7d5a6cc17
gh-150114: Log the memory usage in regrtest on Windows (#150267)
Add _winapi.GetProcessMemoryInfo() function.

Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
2026-05-23 00:04:51 +02:00
Victor Stinner
b770b2350e
Revert "gh-146452: Improve locking granularity in pickle's batch_dict_exact and fix race condition (#150025)" (#150261)
This reverts commit 57a0e570d3.
2026-05-22 22:22:47 +02:00
Victor Stinner
e020836fd4
gh-149879: Fix test_capi on Cygwin (#150252)
Fix Test_Pep523AllowSpecialization tests of test_capi.test_misc.

On Cygwin, _PyEval_EvalFrameDefault in _testinternalcapi is not the
same as _PyEval_EvalFrameDefault in python.exe. So pass NULL
explicitly to use the default function (_PyEval_EvalFrameDefault).
2026-05-22 21:47:32 +02:00
Victor Stinner
8115360153
gh-149879: Fix test_c_stack_unwind on Cygwin (#150084)
On Cygwin, the Python library is called "cygpython3.16.dll".
2026-05-22 21:32:44 +02:00
Pablo Galindo Salgado
661df25692
gh-149584: Fix excessive overhead in the Tachyon profiler regarding the cache behavior (#149649)
Use exact remote reads for interpreter state, thread state, and
interpreter frame structs instead of pulling full remote pages into the
profiler page cache. This matches the core change from
python/cpython#149585.

The profiler clears the page cache between samples, so live entries are
always packed at the front. Track the live count and only clear/search
that prefix instead of scanning all 1024 slots on the hot path.

Use the frame cache to predict the next thread state and top frame
address, then batch interpreter/thread/frame reads with process_vm_readv
when profiling a Linux target. Reuse prefetched frame buffers in the
frame walker when the prediction is valid.

Cache the last FrameInfo tuple per code object/instruction offset, reuse
cached thread id objects, and append cached parent frames directly on
full frame-cache hits. This cuts Python allocation churn in the
steady-state profiler path.
2026-05-20 04:32:08 -07:00
Pablo Galindo Salgado
1f3c2679f1
gh-149321: Remove lazy_imports=none startup mode (#149389) 2026-05-19 16:01:15 -07:00
larryhastings
79088e0d82
gh-150042: queue.SimpleQueue.put: fix minor refleak. (GH-150043)
If queue.SimpleQueue.put can't handoff the item to a
waiting thread, and fails to allocate memory when adding
the item to a ringbuf, it would leak a reference.  Fixed.
2026-05-20 00:27:04 +02:00
Alexey Katsman
d095ceb0f4
gh-149816: Fix UAF in Modules/_pickle.c (GH-150024)
Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
2026-05-20 00:11:17 +02:00
AN Long
3d2aa899ba
gh-149983: Fix PyErr_NoMemory call without GIL in winconsoleio.c (GH-149984) 2026-05-19 22:31:00 +02:00
Kirill Ignatev
8b31d08e62
gh-149816: Fix SNI callback callable race (GH-150018) 2026-05-19 20:36:46 +02:00
Victor Stinner
29415c071f
gh-149473: Emit audit event on calling os.environ.clear() (#149768)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-05-19 18:38:12 +02:00
Jelle Zijlstra
08218030a5
gh-148829: Make sentinels' repr and module customizable (#149654)
Implementation of python/peps#4968; still needs SC approval.
2026-05-19 09:18:56 -07:00
Saul Cooperman
57a0e570d3
gh-146452: Improve locking granularity in pickle's batch_dict_exact and fix race condition (#150025)
Remove assertion that could fail in rare race condition.

Replace the coarse critical section wrapping the entire function with
fine-grained sections covering only PyDict_Next + Py_INCREF.
Also handle PyDict_Next returning 0 in the single-item fast path.
2026-05-18 16:26:08 -07:00
Armaan Vakharia
56737483c2
gh-149590: Remove faulthandler_traverse (#150023)
`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.
2026-05-18 16:00:59 -07:00
sobolevn
14af19e6c0
gh-149816: Fix a RC in _random.Random.__init__ method (#149824) 2026-05-18 18:39:54 +03:00
Maurycy Pawłowski-Wieroński
a2932e9c95
gh-149464: Add os.pidfd_getfd(pidfd, targetfd, flags=0) function (#149465)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-05-18 16:29:58 +02:00