Commit Graph
10631 Commits
Author SHA1 Message Date
Pengyu Lee 1b015e66f0 gh-157906: fix an incorrect architecture macro check in free-threaded GC (gh-157907)
Fix typo in free-threaded GC prefetch check for 32-bit x86 MSVC.
2026-10-03 11:36:01 -07:00
Victor Stinner b42fdf6b44 Fix _PyOS_GetOpt() error message for non-ASCII characters (#158626)
Replace %c with %lc.
2026-10-03 15:37:58 +02:00
Victor Stinner f5e913c7f7 gh-158445: Allocate memory in the heap in Py_GetVersion() (#158608)
Py_GetVersion() now allocates memory on the heap, instead of using a
static buffer, to no longer truncate the version if it's longer than
299 bytes.

Update Py_GetCompiler() and Py_GetBuildInfo() tests: they are now
always a part of sys.version.
2026-10-03 15:15:08 +02:00
Bhuvansh 20d5e67fc5 gh-156204: Guard recursion in PyErr_GivenExceptionMatches (GH-156205) 2026-10-02 16:22:05 -04:00
00a1c3a0c9 gh-158140: Resolve lazily imported sibling submodules independently (#158521)
* gh-158140: Resolve lazy siblings through the pending-child registry

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: T. Wouters <thomas@python.org>
2026-10-02 19:20:04 +02:00
be87a85e2f gh-155695: Remove resolved names from sys.lazy_modules more consistently (#157714)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2026-10-02 19:17:48 +03:00
a6a63b6f5b gh-142349: Simplify lazy import resolution (#158282)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2026-10-01 16:20:45 +00:00
Victor Stinner 82fcaf881c Cleanup Python/getopt.c: add _PyOS_GetOpt structure (#158362)
Replace global variables with a new _PyOS_GetOpt structure:

* _PyOS_opterr => getopt->error
* _PyOS_optind => getopt->index
* _PyOS_optarg => getopt->arg

Changes:

* Add tests to test_cmd_line.
* Rename _PyOS_ResetGetOpt() to _PyOS_GetOpt_Init(). Add argc and
  argv parameters.
* Don't expose longindex in the structure, it's only used internally.
* Move _PyOS_LongOption structure from the internal C API to
  getopt.c.
2026-10-01 14:58:55 +00:00
John 0906d2ab93 gh-157468: Validate correct builtins used under JIT (GH-157766)
* Expose two possible builtin JIT gaps

* Add trace and runtime guard for builtin dict

* Check _GUARD_BUILTINS_IS_CANONICAL once per frame

* Add check and fix for globals being folded
2026-10-01 12:15:51 +01:00
An Long 1071f7400e gh-155823: Fix stale stack on _SEND_VIRTUAL_TIER_TWO exhausted exit (GH-155844) 2026-10-01 12:08:48 +01:00
Jun Luo 069c74a6b7 gh-157833: Fix specialized C calls with additional method flags (GH-157834) 2026-09-30 14:37:24 +01:00
Lukas Geiger 83de667b25 gh-158072: Fix JIT crash with omitted default arguments (GH-158128) 2026-09-30 14:32:18 +01:00
Hai Zhu b98c065756 gh-158380: Fix the stack operand used by JIT dict access guards (GH-158381) 2026-09-30 14:18:13 +01:00
Gregory P. Smith b7b4f3ecf2 gh-158446: Reject float format precision near INT_MAX (GH-158474)
Formatting a float or complex with a precision within about 1000 of
INT_MAX could crash or produce incorrect output.
PyOS_double_to_string() now raises ValueError("precision too big") for
such precisions, as the format string parsers already do for
precisions above INT_MAX.

The limit applies regardless of presentation type or value, so a few
calls that previously succeeded (inf, nan, or 'g' with such a
precision) now raise as well.
2026-09-30 05:22:37 +00:00
Himesh Rupchandani c3cb46870b gh-158364: Don't report other interpreters' threads in sys._current_frames (GH-158369) 2026-09-29 22:24:24 -04:00
Pengyu LeeandVictor Stinner aa287d7f44 gh-158241: Prevent double release of assembler byte writers (#158242)
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-09-29 10:48:11 +00:00
Daniele Parmeggiani baec76438e gh-157914: Revert "gh-135871: Reload lock internal state while spinning in PyMutex_LockTimed (gh-146064)" (gh-158082) 2026-09-27 17:29:07 +00:00
Serhiy Storchaka dc590064bd gh-155496: Use Argument Clinic for more functions and methods (GH-158134)
Convert to Argument Clinic:

* builtins dir() and vars()
* property.__set_name__()
* memoryview.__exit__()
* structseq __replace__()
* types.SimpleNamespace.__replace__()
* re.Match.group()
* sys.getsizeof() and sys.set_asyncgen_hooks()
* atexit.register()
* os.scandir() iterator __exit__()
* _dbm, _gdbm and _decimal context manager __exit__()
* _functools lru_cache __copy__() and __deepcopy__()
* _elementtree.SubElement()
* _interpreters.new_config()
* _tkinter call() and wantobjects()
* zoneinfo.ZoneInfo.__init_subclass__()
* internal hamt and stdprinter methods
2026-09-27 19:00:22 +03:00
Brittany ReynosoandPablo Galindo Salgado 1e8ff18a12 gh-157757: Fix to make lazy import a.b as c import the module a.b (#158092)
* Import the module a lazy `import a.b as c` names

`import a.b as c` compiles to `IMPORT_NAME a.b` followed by `IMPORT_FROM b`.
Lazily, IMPORT_NAME leaves a placeholder holding "a.b", and IMPORT_FROM
rewrote it into the placeholder `lazy from a import b` produces.  Reification
then imported `a` alone and read `b` off it, so the module `a.b` was never
imported under its own name: an attribute of the package shadowing it answered
instead, and `math.pi`, which no module backs, bound the float where the eager
statement raises ModuleNotFoundError.

Mark the dotted import on the placeholder and keep the whole name on it.
Reification imports that name and then walks its components with IMPORT_FROM,
which is what the eager statement does.

The test pinning `lazy import math.pi as pi` as working is inverted, since the
eager statement raises.

* Stop excluding test_trace from the lazy-imports-all run

It passes now that a lazy `import a.b as c` imports the module: the
KeyError on 'test.tracedmodules.testmod' came from the submodule never
being imported under its own name.

* Rename lz_submodule to lz_dotted_as and trim the comments

The flag means "bind the whole dotted name, not the root", which the old
name did not say, and import.c already has unrelated lazy_pending_submodules
machinery to be confused with.

* Chain lazy IMPORT_FROM placeholders instead of flagging dotted imports

Each deferred IMPORT_FROM off a placeholder without a fromlist now keeps
the previous placeholder in lz_from and the attribute name in lz_attr.
Reification walks back to the placeholder IMPORT_NAME left, runs that
import, and replays the lookups in order with _PyEval_ImportFrom, which
is what the eager bytecode does.  This drops the lz_dotted_as flag and
also follows a custom __lazy_import__ that returns a placeholder for a
different module name.

* Chain every deferred IMPORT_FROM onto the previous placeholder

`lazy from a import b` now records its lookup the same way as `import
a.b as c`, so a placeholder holds either the module name and fromlist or
the previous placeholder and an attribute name, and reification has a
single path.  The import passes only the name being resolved as the
fromlist, so accessing b still does not import the other names'
submodules.

* Treat an empty fromlist on a lazy import placeholder as no fromlist

__import__("a.b", fromlist=()) returns the top-level package `a`, the same
as fromlist=None, but the placeholder kept the empty tuple.  Every consumer
of lz_attr then read it as a real fromlist: reification narrowed it to the
chained attribute and replayed the lookups on `a.b`, _PyEval_LazyImportFrom
took the attribute off sys.modules["a.b"], and the repr named `a.b.attr`.

_PyLazyImport_New already collapses None to NULL for exactly this reason,
so collapse an empty tuple there too and every site follows.

* gh-157757: Preserve empty fromlists for custom import hooks

---------

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2026-09-26 20:19:25 +00:00
Marc MuellerandPieter Eendebak 972cfaae3f gh-138912: Add fast path for match class patterns without sub-patterns (#144820)
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
2026-09-26 13:00:10 -07:00
Marc Mueller 109a192eb5 gh-151907: Reduce duplication in codegen comprehension functions (GH-154846) 2026-09-26 12:49:38 -04:00
Trent Nelson f156510960 gh-151518: Avoid STW starvation of attaching threads (#152826)
* gh-151518: Avoid STW starvation of attaching threads

Free-threaded stop-the-world pauses can otherwise starve a thread trying to reattach after it was suspended while detached.  A tight manual gc.collect() loop can release and immediately request the next stop-the-world pause, repeatedly parking the detached thread before it can attach and make progress.

Add a distinct _Py_THREAD_SUSPENDED_DETACHED state for tstates parked from DETACHED.  tstate_wait_attach() marks an attach waiter only after observing that detached-origin suspended state, and park_detached_threads() skips only those active waiters on later stop-the-world passes.  The ordinary successful tstate_try_attach() path remains the baseline CAS-only path.

Teach the related stop-the-world paths about both suspended states, including start_the_world() and tstate_delete_common().  Keep the new wait flag after the existing hot free-threaded _PyThreadStateImpl fields so their offsets do not move.

Add a free-threaded GC regression test that runs a subprocess with a tight gc.collect() worker and verifies the main thread can reattach after sleeping and stop the worker.

* gh-151518: Track attach waiters in the thread state

Represent active attach waiters with suspended-waiting and
detached-waiting states. Preserve waiter registration when the
world resumes, and keep passive detached threads immediately parkable.

Restore the thread-state padding and retain the single-CAS
uncontended attach path.

* gh-151518: Simplify the GC fairness regression

Use explicit warmup imports and a joined non-daemon collector.
Run the child through script_helper with a faulthandler watchdog
so a stalled attachment still fails with a traceback.

Describe the bug as a fairness issue in the NEWS entry.

* gh-151518: Exercise STW fairness directly

* gh-151518: Preserve attach waiters when resuming BRC suspensions

Share the waiter-aware resume transition between stop-the-world pauses
and biased reference count merging so a concurrently registering waiter
keeps its opportunity to attach.

Restore the support import needed by the new upstream GC regression and
align the thread-state constants.

* gh-151518: Strengthen the STW attach fairness regression

Hold each test pause for 10 ms and repeat pauses in C to reduce the
opportunities for a waiting thread to run between pause requests.

Clarify that parking rechecks the thread state before sleeping.

* gh-151518: Restrict STW test pauses to free-threaded builds

STW is a no-op in GIL builds. Avoid waiting in the helper there,
since WASI cannot perform the blocking futex operation.

* gh-151518: Wake only registered attach waiters

Avoid a parking-lot lookup when resuming a suspended thread that
has not tried to reattach. Use the old state from the successful CAS
so concurrent waiter registration still receives a wakeup.
2026-09-25 11:24:14 -07:00
Victor Stinner fe7717c611 gh-158080: Py_InitializeFromConfig() no longer exits Python (#158085)
If a command line option wants to exit Python, move this option
processing from PyConfig_Read() to Py_Main(). So
Py_InitializeFromInitConfig() and Py_InitializeFromConfig() can no
longer return an exit code.

Deprecate PyInitConfig_GetExitCode(), PyStatus_Exit(), and PyStatus_IsExit()
functions, and PyStatus.exitcode member.

Renumber getopt.c long options to start at 1, instead of 0.
2026-09-25 11:34:05 +00:00
sobolevnandPablo Galindo Salgado dbac44740f gh-145868: Suggest names on typos in __future__ imports (#154347)
* gh-145868: Suggest names on typos in `__future__` imports

* Address review

* Address review

* gh-145868: Suggest only valid future features

---------

Co-authored-by: Pablo Galindo Salgado <pablogsal@gmail.com>
2026-09-24 16:29:48 +00:00
Victor Stinner 7242fea93c gh-158001: Remove global configuration variables from C API (#158020)
Keep 4 variables in the stable ABI:

* Py_FileSystemDefaultEncodeErrors
* Py_FileSystemDefaultEncoding
* Py_HasFileSystemDefaultEncoding
* Py_UTF8Mode

Mark the 4 variables as ABI only in Misc/stable_abi.toml.
2026-09-24 16:42:02 +02:00
Victor Stinner a5a4659548 gh-158001: Remove Py_SetProgramName() function (#158024)
Remove Py_SetProgramName(), Py_SetPythonHome(), PySys_SetArgv() and
PySys_SetArgvEx() functions, deprecated since Python 3.11.

Mark the 4 functions as abi_only in stable_abi.toml.
2026-09-24 12:52:54 +02:00
Victor Stinner 82936545cc gh-154757: Remove deprecated PyEval_InitThreads() function (#158037)
Remove it from the C API, but keep it in the stable ABI.
2026-09-24 10:47:59 +02:00
Inada Naoki bd0913a840 gh-157407: Fix a compilation error on Windows. (#158048)
`&PyUnicode_Type` cannot be determined at compile time on Windows.
Caused by #157393.
2026-09-24 15:06:56 +09:00
7884f48af4 gh-152708: Fix AST generation asymmetry for unary positive in match statements (#152712)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: johnslavik <bartosz@ilikepython.com>
2026-09-23 19:56:53 -07:00
Irit Katriel a9d42dceee gh-124697: Represent inlined comprehensions as subscopes in the symbol table (#156819) 2026-09-23 20:31:57 +01:00
Victor Stinner 2f5791df35 gh-158001: No longer read global config vars in PyConfig_Read() (#158014)
PyConfig_Read() and _PyPreConfig_Read() no longer read global config
variables (such as Py_BytesWarningFlag). Instead, PyConfig_Read() now
copies PyPreConfig members (isolated, use_environment and dev_mode).

_PyPreConfig_Read() still reads the last global configuration
variable: Py_UTF8Mode.
2026-09-23 21:21:38 +02:00
Kumar Aditya 030e913a74 gh-157838: Merge biased refcounts on behalf of detached threads (#157839) 2026-09-23 22:08:56 +05:30
Victor Stinner becfd65c38 gh-158001: Avoid deprecated variable in Py_GETENV() (#158003)
No longer use deprecated Py_IgnoreEnvironmentFlag in Py_GETENV().
Instead, use PyConfig.use_environment when Python is initialized.

Modify also PySys_SetArgv() to use PyConfig.isolated when Python is
initialized.
2026-09-23 17:46:59 +02:00
Inada NaokiandPieter Eendebak 16b357b6cd gh-157407: Reduce code size of ast and unicodeobject (#157393)
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
2026-09-23 23:13:51 +09:00
Kumar Aditya d4f52c445b gh-157526: Call __instancecheck__ and __subclasscheck__ without creating a bound method (#157670) 2026-09-22 11:16:30 +05:30
Peter Gessler f8b0e26a6a gh-150737: Optimize bytecode for empty unpack cases such as `{*()}`. (#150812) 2026-09-20 21:53:10 -07:00
ノウラ | Flare 9193375382 gh-157549: Use sysconf() for the page size in remote_debug.h (#157800)
getpagesize() is not an ISO C or POSIX function. Darwin hides the prototype under -std=c11, so the _remote_debugging build fails with -Werror=implicit-function-declaration. That is the failure in the reported x86_64-apple-darwin → arm64-apple-darwin cross build.

Call sysconf(_SC_PAGESIZE) instead, which is already how resource.getpagesize() works. Fall back to 4096 if sysconf() fails.

--without-remote-debug is unchanged. That flag only disables the target-side attach protocol (Py_REMOTE_DEBUG); it does not exclude the _remote_debugging client module.
2026-09-19 16:11:49 +00:00
Serhiy Storchaka 6b5d4143f3 gh-113318: Better implementation of @getter and @setter in Argument Clinic (GH-156066)
The value of a @setter is now a parameter, which can use a converter,
and a @getter can define a return converter.  Declaring the value is
optional.

The accessors of an attribute are now collected in a Property, so the
entry of PyGetSetDef is identified by the Python name instead of the C
basename, and is composed without the help of the preprocessor unless
some accessor is compiled conditionally.
2026-09-19 18:48:39 +03:00
Shamil 6dad8b88cc gh-156114: Fix crash in perf trampoline with unencodable code names (#156300) 2026-09-18 17:04:21 -04:00
Serhiy StorchakaandClaude Opus 5 76f22f9cf2 gh-156942: Raise the exception where the marshalling error is detected (GH-156944)
Previously the marshal writer recorded an error code and converted it into
an exception at the end, replacing the exception which was already raised
with ValueError("unmarshallable object").  Error messages now name the type
of the unsupported object and the required version.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-18 17:14:25 +00:00
Serhiy Storchaka 92db1519aa gh-86427: Determine the stdio encoding for every standard stream on Windows (GH-155416)
It was the ANSI code page instead of the encoding of the device the stream
is connected to, as in 3.7.

The stdio encoding is now left undefined in this mode and determined for
every standard stream.
2026-09-18 20:03:25 +03:00
Victor Stinner 86c93a5b84 gh-155742: Use PyBytesWriter in _Py_strhex_impl() (#157734)
Replace soft deprecated PyBytes_FromStringAndSize() with
PyBytesWriter.

Replace also PyBytes_FromStringAndSize(NULL, 0) with
Py_GetConstant(Py_CONSTANT_EMPTY_BYTES) in other functions.

Replace also PyBytes_FromStringAndSize(NULL, 0) with
PyBytes_FromStringAndSize("", 0) in _Py_GetConstant_Init().
2026-09-18 14:09:09 +02:00
Victor StinnerandNathan Goldbaum d1878ccb44 gh-157415: Fix data race in pthread wrapper (#157430)
Use free() instead of PyMem_RawFree() in pythread_wrapper() to avoid
a data race if another thread calls PyMem_SetAllocator() in parallel.

Reenable @nomemtest tests on TSAN.

Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
2026-09-17 16:34:50 +02:00
Victor StinnerandPetr Viktorin 8bcbcf8cfc gh-155742: Check singletons consistency at Python exit (#157572)
In debug mode at Python exit, check if immutable singleton objects
have been modified by mistake to detect bugs in C extensions.

Add tests corrupting bytes, str, bool and int singleton objects.

Add pycore_global_objects_fini.h internal header file.
pycore_global_objects_fini_generated.h is now fully generated by the
script.

Co-authored-by: Petr Viktorin <encukou@gmail.com>
2026-09-17 16:03:45 +02:00
Kumar Aditya 0a6c1ed341 gh-157361: Implement anext() in Python instead of C (#157362) 2026-09-16 18:58:59 +05:30
Bartosz Sławecki 1bfcc3cc87 gh-156909: Fix AST.__repr__ call getting the _fields attribute (GH-157490) 2026-09-15 08:26:26 +02:00
Victor Stinner ab5b14789d gh-155742: Use PyBytesWriter in Python/assemble.c (#157349)
Replace soft deprecated _PyBytes_Resize() with PyBytesWriter.
2026-09-14 23:52:44 +02:00
Bartosz Sławecki b62380fdb8 gh-156021: Don't include ... for empty AST node representations (GH-156022) 2026-09-14 14:06:22 +02:00
Victor Stinner 658612ae77 gh-128509: Use bytes singletons in marshal (#157398)
Replace soft deprecated PyBytes_FromStringAndSize(NULL, n) with
PyBytes_FromStringAndSize(str, n) so marshal can get bytes singleton.
2026-09-13 12:11:07 +00:00
Pablo Galindo Salgado 7bfa97f4dc gh-153569: hide tokenizer state behind token and source operations (#156654)
Make pegen and _tokenize consume tokenizer operations instead of accessing the tokenizer layout. Return token kind, span, location, and raw-string context together, so parser actions use the context of the cached token.

Represent persistent scanner positions as offsets and remove pointer save/restore bookkeeping when input storage grows.
2026-09-12 14:30:00 +01:00