Commit graph

10452 commits

Author SHA1 Message Date
Batuhan Taskaya
3ff2117ea3
bpo-38131: Improve messages when generating AST nodes from objects with wrong field values (GH-17715) 2026-06-04 10:58:51 +00:00
Nazım Can Altınova
494f2e3c92
gh-150723: Fix perf jitdump files on macOS (#150728)
The perf jitdump format defines the thread id field of the JR_CODE_LOAD
record as a 32-bit value, but on macOS it was declared as a uint64_t
(since pthread_threadid_np() returns a uint64_t). Those extra 8 bytes
plus alignment padding shifted every following field, so parsers reading
the file by the spec misread code_size as the code address and failed to
resolve any Python frames.

Declare thread_id as uint32_t on all platforms and truncate the macOS
thread id when writing the record. The value is only informational.
Symbols are resolved by address, and not thread ids so truncation is
safe here.

* Use mach_absolute_time for macOS jitdump timestamps

On macOS the jitdump file is consumed by profilers such as samply, which
timestamp their samples using mach_absolute_time(). The jitdump events were
stamped with clock_gettime(CLOCK_MONOTONIC), a different clock domain that
keeps advancing while the system is asleep, so the JIT code mappings could be
off by days relative to the samples and no Python frame would resolve. Stamp
jitdump events with mach_absolute_time() on macOS so they share the sampler's
clock domain. Linux continues to use CLOCK_MONOTONIC to stay aligned with perf.

Exercise the -Xperf_jit (jitdump) backend through samply and assert that
Python frames resolve, exercising the binary jitdump path end to end.
Skipped when samply is not installed.
2026-06-03 01:15:34 +01:00
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
Stan Ulbrych
c52d2b16dd
gh-149805: Fix SystemError when compiling __classdict__ class annotation (#149806) 2026-06-02 10:17:03 +01:00
Bartosz Sławecki
5a2d2736a6
gh-150052: Resolve un-loaded lazily loaded submodules via module.__getattr__ instead of publishing lazy values (#150055) (#150744) 2026-06-02 09:58:51 +01:00
Russell Keith-Magee
71fc4c66d3
gh-150644: Tag Apple system log messages as public. (#150645)
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.
2026-06-02 06:25:46 +08:00
Mark Shannon
633b6be8f5
GH-148960: Reduce the size of the debug stencils to less than half. (GH-150551)
For AArch64 linux, reduces the total bytes in the code bodies from 489kb to 218kb.
Reduces the size of the stencils files from 394k lines to 167k lines.
2026-06-01 17:56:16 +01:00
Langyan
13fee461c2
Fix typos in InternalDocs/compiler.md (#149915) 2026-05-29 15:44:20 +05:30
pengyu lee
686996e4d8
gh-150454: Fix wrong-interpreter return in import_run_extension error path (#150455) 2026-05-29 15:33:37 +05:30
Bartosz Sławecki
1d4e965829
gh-148587: Make sys.lazy_modules match PEP and keep internal lazy submodules tracking internal (#150086)
Make sys.lazy_modules match PEP and keep internal lazy submodules tracking internal

Co-authored-by: Dino Viehland <dinoviehland@meta.com>
2026-05-28 17:55:47 -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
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
Mark Shannon
a6793662e7
GH-126910: Make _Py_get_machine_stack_pointer return the actual stack pointer (GH-149103)
* Make _Py_ReachedRecursionLimit inline again
* Remove _Py_MakeRecCheck replacing its use with _Py_ReachedRecursionLimit
* Move the check for C stack swtiching into _Py_CheckRecursiveCall
2026-05-26 15:14:17 +01:00
Pablo Galindo Salgado
a5be25d3bd
gh-149619: Harden _remote_debugging error paths (#150349) 2026-05-25 23:22:46 +01:00
Pablo Galindo Salgado
9989a54a53
gh-149156: Fix perf trampoline crash after fork (#150347) 2026-05-25 13:45:58 +01:00
pengyu lee
71cf3130c6
gh-150379: fix ref leak in C API monitoring events (#150381) 2026-05-25 16:12:33 +05:30
pengyu lee
5498eba545
gh-150374: Fix double release of import lock in lazy import reification (#150376) 2026-05-25 09:09: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
ivonastojanovic
0563890872
gh-149619: Fix _remote_debugging permissions error on Linux (#150012)
When running profiling on Linux without sudo, attempts to read
process memory would fail with the misleading error 'Failed to find
the PyRuntime section in process <pid> on Linux platform'.

The actual issue is a permissions error because profiling was not
run with sudo. We were clearing the exception on Linux when trying
to read memory, instead, we should bubble up the permissions error
and show it properly.
2026-05-24 14:12:05 +01:00
Serhiy Storchaka
e1e06be119
gh-150285: Fix too long docstrings in builtins (GH-150293)
* gh-150285: Fix too long docstrings in builtins

* Revert bytes and bytearray class multiline docstrings to make IDLE happy.
2026-05-24 15:03:32 +03:00
stratakis
b0a149a8c6
gh-149800: Split perf trampoline assembly into per-architecture files (#149894) 2026-05-23 08:03:52 -04:00
Pieter Eendebak
dfeeee990b
gh-145192: improve performance of PySequence_GetSlice (#145193) 2026-05-23 15:45:50 +05:30
pengyu lee
32823af153
gh-150178: Fix refcount leaks in hamt allocation failure paths (#150179) 2026-05-23 14:03:40 +05:30
Stan Ulbrych
32104a11e3
Remove accidentally added Python/deepfreeze/deepfreeze.c (gh-150192) 2026-05-21 12:37:49 -04:00
Hai Zhu
0828782773
gh-149358: Generating JIT recorder transformers and stabilizing family layouts (GH-149359) 2026-05-21 17:06:52 +01:00
Hai Zhu
441af3a934
gh-149335: Avoid JIT trace buffer asserts with overhead above FITNESS_INITIAL (GH-149633) 2026-05-21 15:57:31 +01:00
Pieter Eendebak
f2fa291db8
gh-148871: Add CONSTANT_EMPTY_TUPLE to LOAD_COMMON_CONSTANT (GH-149688) 2026-05-21 15:54:46 +01: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
Tim Stumbaugh
de9c32fc34
PEP 810 - Update some error strings (#150126) 2026-05-20 00:47:44 +00:00
Pablo Galindo Salgado
1f3c2679f1
gh-149321: Remove lazy_imports=none startup mode (#149389) 2026-05-19 16:01:15 -07:00
Peter Bierma
409fa8e1f3
gh-150027: Avoid copying during construction of frozenset objects (GH-150028) 2026-05-19 13:57:37 -04:00
Lukas Geiger
18281db0d0
gh-144140: Optimize len for frozen dict/set constants in optimizer (#149969) 2026-05-18 12:20:42 +05:30
Pieter Eendebak
6ee879ffa1
gh-138325: steal list items in INTRINSIC_LIST_TO_TUPLE opcode (#149960) 2026-05-18 12:07:12 +05:30
Victor Stinner
c575172425
gh-149879: Fix sys.orig_argv[0] on Cygwin: add ".exe" suffix (#149885) 2026-05-15 15:55:34 +00:00
Carlo Bramini
50476a7e87
gh-148758: Fix dynamic loading file extensions for Cygwin (#148759)
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-05-13 21:50:24 +00:00
Petr Viktorin
125f26358a
gh-149685: Use the _Py prefix for private C macros (GH-149686) 2026-05-13 19:14:05 +02:00
Jelle Zijlstra
4087ff8599
gh-149642: Fix interaction between exec and lazy_imports=all (#149643) 2026-05-12 19:59:09 -07:00
Sergey Miryanov
1a79fd0ad6
GH-149501: Fix compilation warning in _YIELD_VALUE uop (#149502) 2026-05-12 22:47:35 +05:30
Stan Ulbrych
6a0be131c3
gh-149595: Remove the sys._enablelegacywindowsfsencoding() function (#149596)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2026-05-12 17:11:34 +01:00
stratakis
da8477b25c
gh-139808: Add branch protections for aarch64 in asm_trampoline.S (#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

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-05-12 15:42:44 +00:00
Alper
8a4895985f
gh-145235: Make dict watcher API thread-safe for free-threaded builds (gh-145233)
In free-threaded builds, concurrent calls to PyDict_AddWatcher, PyDict_ClearWatcher, PyDict_Watch, and PyDict_Unwatch can race on the shared callback array and the per-dict watcher tags. This change adds a mutex to serialize watcher registration and removal, atomic operations for tag updates, and atomic acquire/release synchronization for callback dispatch in _PyDict_SendEvent.
2026-05-11 11:39:55 -04:00
Hai Zhu
c341e341b2
gh-149459: Fix segfault when _LOAD_SPECIAL guard deoptimizes (#149478) 2026-05-08 11:20:27 +00:00
Neko Asakura
d2d24e46d3
gh-100239: expose sq_repeat helpers for BINARY_OP_EXTEND (#148791) 2026-05-08 11:12:20 +00:00
Neko Asakura
49918f5b0c
gh-149481: skip FOR_ITER inline specialization for Python __next__ (#149491)
Co-authored-by: Savannah Ostrowski <savannah@python.org>
Co-authored-by: Stan Ulbrych <stan@python.org>
2026-05-07 23:02:04 +00:00
Neil Schemenauer
13188dbf85
gh-148937: revert process RSS based GC deferral (#149475) 2026-05-07 14:32:14 +03:00
Peter Bierma
2b7c28a440
gh-149101: Implement PEP 788 (GH-149116)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Sam Gross <colesbury@gmail.com>
2026-05-06 17:39:30 -04:00
Alex Malyshev
646853df13
gh-145559: Add PyUnstable_DumpTraceback() and PyUnstable_DumpTracebackThreads() (#148145)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-05-06 15:01:12 +00:00
Daniele Parmeggiani
1bdfc0f253
gh-146270: Fix PyMember_SetOne(..., NULL) not being atomic (gh-148800)
Fixes a sequential consistency bug whereby two threads that are deleting a struct member may observe both their deletions to be successful.
2026-05-06 09:50:24 -04:00
Hugo van Kemenade
e7613f2735
gh-148766: Add colour to Python help (#148767) 2026-05-06 16:48:04 +03:00
Wulian233
0b75b7338d
gh-100239: specialize mixed int/float inplace binary ops (GH-149413) 2026-05-06 13:59:08 +01:00