5167 Commits
Author SHA1 Message Date
Itamar Oren 0e35313484 gh-160689 : Link only the bootstrap modules into the build helper programs (#160537)
The build-helper programs (`Programs/_freeze_module` and `_bootstrap_python`) don't need to link extension modules that they don't need.

This PR makes sure the helper programs get only the modules they need to do their job, regardless of what the build configuration sets for the final built runtime and interpreter.

This follows the same pattern as what `PCbuild/_freeze_module.vcxproj` does with `PC/config_minimal.c`, and lets "extra" builtin modules (from `Setup.local` or `MODULE_BUILDTYPE=static`) depend on frozen modules or `getpath`.
2026-10-26 15:09:33 -07:00
Inada NaokiandEmma Smith b26fc41b5c Remove obsolete and unused configure macros (#159513)
Co-authored-by: Emma Smith <emma@emmatyping.dev>
2026-10-25 05:18:16 +00:00
Pablo Galindo SalgadoandLysandros Nikolaou b77cb891e9 gh-153568: Skip the expression precedence chain for single-token atoms (#153575)
A bare name or number followed by a token that cannot extend an expression now produces its AST node directly. This avoids the expression precedence chain for common arguments, assignments, and subscripts.

Rules declare the hook with a fastpath flag. The Rule constructor exposes memo and fastpath attributes, and the C generator emits the hook call.

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
2026-10-23 14:23:10 -07:00
Lysandros Nikolaou e548b472f3 gh-153195: Allow splitting the PEG grammar into several files (#159917)
Add an @include meta to pegen: the rules of an included grammar file are
appended to the including file's rules. The C generator emits the rules
of each included file into a separate C file next to the main output.

Use it to move the invalid_* rules from Grammar/python.gram into
Grammar/invalid.gram, which generates Parser/parser_invalid.c.
2026-10-23 12:58:39 -07:00
Osama AbdelkaderandStan Ulbrych 1c75034ced gh-131498: Remove commented-out dead code in cases_generator/analyzer.py (#141168)
Remove the unused analyze_deferred_refs() function that was completely
commented out. This function is not referenced anywhere in
the codebase and removing it improves code cleanliness.

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
2026-10-23 11:28:12 -07:00
Cody MaloneyandClaude Opus 5.5 3fc4d1f9b3 gh-87613: Allow Argument Clinic vectorcall on heap types (#160115)
Heap types have no static type object so switch from `Py_Is` to an
assert that the shadowed `tp_new` / `tp_init` function is the expected
one to validate the vectorcall is only used with the right type.

Heap types can have zero-argument `__new__` and `__init__` so add
support  for that producing the same error message via a new helper
`_PyArg_NoPositionalStack()`.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 03:13:30 +00:00
Donghee Na 45538495be gh-114258: Update Argument Clinic for `__str__`. (gh-160402) 2026-10-23 02:31:41 +00:00
Lysandros Nikolaou 0b8bb7154c gh-160284: Number each keyword once in the PEG generator (#160290)
`KeywordCollectorVisitor` checked the quoted spelling of a keyword against
keys stored without quotes, so the check never matched and every
occurrence of a keyword in the grammar took a new token type. The 35
hard keywords were numbered between 500 and 721 instead of 500 to 534.
2026-10-22 19:25:07 +00:00
Donghee Na 3b3c692295 gh-114258: Use Argument Clinic for `__hash__` (gh-160059) 2026-10-22 07:54:04 +00:00
Donghee Na c58b7136b2 gh-114258: Use Argument Clinic for `__bool__` (GH-160057) 2026-10-22 05:45:16 +00:00
Donghee Na c1c4c18dfc gh-114258: Use Argument Clinic for `__getitem__` (gh-160068) 2026-10-22 01:06:48 +00:00
Donghee Na 6e1bd24e4d gh-114258: Update Argument Clinic for __contain__ slots (gh-160093) 2026-10-21 23:22:03 +00:00
Itamar Oren 13c758d730 gh-159998: Fix libpython.dynamic in build-details.json for framework builds (#160005)
In framework builds, `libpython.dynamic` now joins `PYTHONFRAMEWORKPREFIX` with `LDLIBRARY` instead of `LIBDIR` with `LDLIBRARY`, so it points at the framework library that is actually installed. Other builds are unchanged.
2026-10-21 23:10:54 +00:00
Itamar Oren fc1a634099 gh-160004: Fix build-details.json paths with --config-file-path (#160007)
`make_paths_relative()` now keeps the absolute `base_prefix` for computing the other paths, and only the stored `base_prefix` is made relative to the config file's directory. This is the same fix python-build-standalone carries in `patch-python-relative-build-details.patch` (by @geofft). That patch also changes the Makefile to generate relative paths by default; this PR leaves the Makefile alone.
2026-10-21 23:05:50 +00:00
Peter BiermaandPetr Viktorin aed4ad8c43 gh-141004: Document missing descriptor C APIs (GH-159709)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2026-10-21 22:24:45 +00:00
Peter Bierma 5a17b2ecfd gh-114258: Use Argument Clinic for __add__/__iadd__ (GH-160051) 2026-10-21 21:59:07 +00:00
Peter Bierma fe70b06917 gh-114258: Use Argument Clinic for __mul__/__imul__ (GH-160049) 2026-10-21 20:17:22 +00:00
Peter Bierma 65b7e9444a gh-114258: Use Argument Clinic for __repr__ (GH-160011) 2026-10-21 18:06:57 +00:00
Peter BiermaandPetr Viktorin 01ff2e22e1 gh-141004: Document remaining parts of the public C API (GH-159892)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2026-10-21 19:21:48 +02:00
Peter Bierma 796b26b360 gh-114258: Use Argument Clinic for __setitem__ (GH-160048) 2026-10-21 17:09:15 +00:00
Donghee Na 2c142a14ed gh-114258: Use Argument Clinic for __len__ (GH-160012) 2026-10-21 12:06:29 -04:00
Donghee Na f9c0e1ea27 gh-114258: Update AC to support @critical_section for tp_iternext (gh-159962) 2026-10-21 00:25:02 +00:00
Peter Bierma 6f439ee069 gh-141004: Document Py_FrozenMain (#159724) 2026-10-20 17:44:33 +00:00
Kumar Aditya cb12c5e514 gh-157361: Implement aiter() in Python instead of C (#157687)
gh-157361: Implement aiter() in Python instead of C

Move both forms of aiter() into the frozen _pybuiltins module and remove
the C async_callable_iterator types. The callable form now returns an
iterator whose __anext__() is a plain coroutine, so call-graph tools can
see through it into the awaited result of the callable.
2026-10-20 15:33:36 +05:30
Victor Stinner 71ba39dc05 gh-159603: Use pthread_attr_get_np() on FreeBSD (#159604)
Use pthread_attr_get_np() on FreeBSD to get the stack size (and guard
size) of the current thread.

Check if pthread_attr_get_np() function and <pthread_np.h> header are
available in configure.

Update test_json.test_recursion. On FreeBSD 16 with a default stack size of
512 MB, the json C implementation no longer raises RecursionError in
test_highly_nested_objects_encoding(). Reduce also max_depth from 5,000 to
2,000 so test_highly_nested_objects_encoding() of the Python implementation
only takes 1.6 seconds, instead of 12 seconds.
2026-10-19 20:54:27 -07:00
Itamar Oren e41b38b7cd gh-159759: Fix libpython.static in PEP 739 build-details.json (#159766)
When a shared library is also built, point `libpython.static` at `LIBPL`,
the only place `make install` puts the static library, and don't list it for
framework builds, which don't install one. Static-only builds keep the
existing `LIBDIR` value, which is installed in that configuration.
2026-10-19 17:50:16 -07:00
Lysandros Nikolaou fa8600cb1d gh-159799: Require pathlib.[Pure]Path for file paths in the PEG generator (#159800)
The pegen entry points now take `pathlib.Path` objects instead of
strings, and the command-line tools (`python -m pegen`, `keywordgen`,
`first_sets`, `grammar_visualizer`) parse their path arguments into
`Path` objects.

The generators' `generate` and `prepare` take a `pathlib.PurePath`
since they only use the file's name (for the "generated by" comment
in the output) and callers pass names that are not files, such as
`"<string>"`.
2026-10-19 17:05:29 -07:00
Peter Bierma 6297f8dc51 gh-141004: Document Py_UniversalNewlineFgets (GH-159713) 2026-10-19 21:55:48 +00:00
Peter Bierma 4c34b7ebf1 gh-141004: Document missing pyport.h macros (GH-159719) 2026-10-19 23:49:42 +02:00
Pablo Galindo Salgado 6af655301a gh-159465: Improve incomplete input detection (#159466)
* gh-159465: Improve incomplete input detection

* gh-159465: Track newline effects and preserve parser layout

* gh-159465: Share incomplete-input error cleanup
2026-10-18 11:54:19 +01:00
Locked-chess-official 8177932f6c gh-159227: lint PC/pyconfig.h for check-capi-macros rule (GH-159228) 2026-10-16 17:02:42 +02:00
Victor Stinner 35a000974a Revert "gh-158445: Allocate memory in the heap in Py_GetVersion() (#158608)" (#159519)
This reverts commit f5e913c7f7.

Truncating the static buffer to 20 bytes caused a regression in debuggers
and crash reporters checking `version` static buffer, see:
https://github.com/python/cpython/pull/158608#issuecomment-6027641907
2026-10-16 10:49:53 +00:00
dependabot[bot] c04ad8ce36 build(deps): bump the pip group across 1 directory with 4 updates (#158387)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-10-13 09:46:52 +02:00
An LongandPieter Eendebak 0768eed8b5 gh-81057: Inline single-use error messages in _decimal and make the rest const (#156809)
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
2026-10-12 20:50:59 +00:00
Hugo van Kemenade ce5c012a8a Fix mypy bump for Tools/peg_generator/pegen/build.py (#159256) 2026-10-12 23:46:02 +03:00
Victor Stinner 8992704916 gh-144175: Remove internal _PyArg_ParseStack() function (#159150)
Replace internal _PyArg_ParseStack() with public PyArg_ParseArray()
in Argument Clinic.
2026-10-12 19:56:53 +02:00
Hood Chatham 0ec3aee262 gh-129040: Use wasm-gc to handle pointer casts in wasi (GH-158617)
This makes it so that in wasi builds if `-DPY_CALL_TRAMPOLINE` is passed, a call trampoline adaptor is used to prevent traps when there is a call signature mismatch between a C slot handler and the signature that the interpreter uses to call it.

This requires Clang >= 22. PEP 11 specifies that builds of Python 3.15 use WASI SDK version 33 which includes clang 23.1.0, so this could be used with Python 3.15 WASI builds but not earlier ones.

It requires a WebAssembly runtime that supports wasm-gc. Wasmtime has supported wasm-gc since version 27.0 released November 25, 2024. Some other runtimes still don't support it, but for those runtimes people can use builds with the trampoline disabled.

This also removed the Emscripten trampoline support for JS runtimes with no wasm-gc support. This removes a lot of implementation complexity and allows WASI and Emscripten to share code. The main concern is that it drops support for some very old iPhones, but every iPhone model released since 2018 is compatible with versions of Safari that support wasm-gc.

Tests were added that define handlers with various wrong numbers of arguments. The tests also run on non-webassembly platforms since they should work there as well.
2026-10-09 22:25:44 +00:00
Victor StinnerandPetr Viktorin 20cb7fc707 gh-158886: Add INCREF/DECREF macros to stable_abi.toml (GH-158941)
* Add 7 INCREF/DECREF macros
* distinguish between 'const' and 'macro' in stable_abi.dat
  The file now has the 'kind' from the toml, not the ReST role.
* Fix kind of PY_VECTORCALL_ARGUMENTS_OFFSET
* Make it explicit that macros aren't part of the ABI
* Add is_static_inline_function to the TOML file (these are treated as macros in the docs)


Co-authored-by: Petr Viktorin <encukou@gmail.com>
2026-10-08 14:12:57 +02:00
cfd6cf7154 gh-157407: Use _PyUnicode_AsUTF8NoNUL for AC 's' and 'z' converters (#158210)
* gh-157407: Use _PyUnicode_AsUTF8NoNUL for AC 's' and 'z' converters

The code was doing the same as the helper added in GH-111957 but inline.
That resulted in significantly more `.text` for most functions. Refactor
the Arguemnt Clinic converters code to deduplicate a bit while keeping
generated code close to original.

On my Linux x64 box this reduces `.text` by ~6200 bytes in a clang
release build (no PGO or LTO). Performance is flat.

The helper was already exported for `_sqlite3`, update the comment that
it is used in AC generated code as well.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Update Include/internal/pycore_unicodeobject.h

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>

* Remove NEWS, add period

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
2026-10-05 17:03:27 +00:00
Pablo Galindo Salgado 0b8aa89a05 gh-153569: Simplify tokenizer state (#158124)
* Use diagnostic line for missing-brace errors

* Keep implicit prepared newline metadata in the reader

* Reuse parsed formatted string kind in lexer

* Transfer owned tokenizer encoding strings

* Remove unused tokenizer state and redundant branches

* Avoid rescanning partial decoded tokenizer lines

* Reuse prepared tokenizer line terminators for CR detection

* Reuse interactive tokenizer chunks without carriage returns

* Release tokenizer constructor resources on allocation failure

* Narrow interactive newline normalization wrapper

* Close duplicated tokenizer descriptors when fdopen fails

* Preserve cached tokenizer lines when newline allocation fails

* Collect cycles involving tokenizer readline callbacks

* Preserve buffered text when decoding source files

* Clear the transferred syntax error line before cleanup

* Propagate tokenizer column conversion failures

* Allocate parser repetition buffers on first match

* Allocate type comment storage only when needed

* Reuse decoded multiline text when counting token columns

* Skip empty decoded tokenizer chunks

* Check parser array growth before allocating

* Name tokenizer bounds and derive byte lengths from their data

* Set the tokenizer exception when file input size overflows

* gh-153569: Send exact line endings in the REPL test

* Share parser repetition buffer growth

* Fold Unicode input coverage into the existing REPL test

* Keep parser array growth policy private

* Drop obsolete bitmap stress from source discard test

* Preserve input failures while scanning string literals

* fixup! Preserve input failures while scanning string literals

* fixup! fixup! Preserve input failures while scanning string literals

* gh-153569: Remove assertion-only lexer bookkeeping
2026-10-05 14:28:51 +01: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
Victor Stinner 7eada7c2c6 gh-158451: Fix python-gdb.py for invalid Unicode strings (#158475)
python-gdb.py is now able to format an invalid Unicode string:
render invalid characters as "\Uhhhhhhhh" instead of raising an
exception.

The PyUnicodeWriter API fills a UCS-4 buffer with 0xff byte pattern
to detect usage of uninitialized characters. It produces invalid
characters '\Uffffffff'.

PyBytesObjectPtr now iterates on bytes (list of integers), instead of
creating a temporary Unicode string. Add more bytes tests in test_gdb
pretty printer.

Remove the unused 'ch2' variable.
2026-09-30 14:12:59 +02:00
Zachary Ware 84d46019be gh-158010: Update CI to use latest OpenSSL and AWS-LC releases (#158412) 2026-09-29 14:58:55 +00:00
Adam TurnerandSerhiy Storchaka c8b7c46f9e gh-64490: Tweak AC implementation for **kwds (GH-139133)
Check for parameters following a var-keyword parameter in one place
instead of three, and improve the error messages for a var-keyword
parameter used with non-positional parameters and for a var-positional
or var-keyword parameter in an optional group.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-09-28 18:04:51 +03:00
Serhiy Storchaka 9e9c3c49b4 gh-158320: Reject optional groups with a var-positional parameter in Argument Clinic (GH-158323)
Such a combination is ambiguous: the number of arguments does not tell
whether the group is passed or all arguments belong to the var-positional
parameter.
2026-09-28 16:10:44 +03:00
Pieter EendebakandClaude Opus 5 1c4fa4f98e gh-157407: Argument Clinic: parse positional-only defining_class methods without _PyArg_Parser (#157483)
* gh-136681: Drop _PyArg_Parser for positional-only defining-class methods

A method that takes a defining class and whose other parameters are all
positional-only (e.g. decimal.Decimal.from_float) was routed through
Argument Clinic's generic keyword path: it emitted a static _PyArg_Parser,
an (empty) keyword tuple and an _PyArg_UnpackKeywords() call, even though
it accepts no keyword arguments.

Such methods now go through parse_pos_only(): the wrapper still uses the
mandatory METH_METHOD|METH_FASTCALL|METH_KEYWORDS convention (the only one
that delivers the defining class), but it rejects keywords with
_PyArg_NoKwnames() and reads positional arguments directly, with no
parser, keyword tuple or argsbuf.

This converts 135 methods across 19 clinic headers, removing the static
_PyArg_Parser, the keyword arrays/tuples and the per-call
_PyArg_UnpackKeywords() + parser_init() overhead for each.

_PyArg_NoKwnames() is now exported (PyAPI_FUNC) so generated code in
shared extension modules can use it, like _PyArg_NoKeywords().

Error messages for these methods now match ordinary positional-only
functions ("expected ... arguments" / "takes no keyword arguments"
instead of the _PyArg_UnpackKeywords phrasing); affected stdlib tests
are updated accordingly.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* gh-157407: Rename NEWS entry to the correct issue number

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-27 21:31:22 +00:00
Serhiy Storchaka db3ffd065c gh-156261: Use the uid_t and gid_t converters in the pwd and grp modules (GH-156294)
They are moved to Argument Clinic, so that pwd.getpwuid() and
grp.getgrgid() can declare the type of their parameter instead of
converting it in the "impl" function.

pwd.getpwuid() now raises OverflowError instead of KeyError for a user id
out of the range of uid_t, as grp.getgrgid() already did.
2026-09-27 19:08:10 +03:00
Sergey B Kirpichev 198bc76836 gh-151464: exclude '<>' token from tokenize output (#154854)
* gh-151464: exclude '<>' token from tokenize output

Was:
```
$ echo '1 <> 2' | python -m tokenize
1,0-1,1:            NUMBER         '1'
1,2-1,4:            OP             '<>'
1,5-1,6:            NUMBER         '2'
1,6-1,7:            NEWLINE        '\n'
2,0-2,0:            ENDMARKER      ''
```

Now (regardless on ``__future__.barry_as_FLUFL`` import):
```
$ echo '1 <> 2' | ./python -m tokenize
1,0-1,1:            NUMBER         '1'
1,2-1,3:            OP             '<'
1,3-1,4:            OP             '>'
1,5-1,6:            NUMBER         '2'
1,6-1,7:            NEWLINE        '\n'
2,0-2,0:            ENDMARKER      ''
```
in accordance with the Grammar:
https://docs.python.org/3.14/reference/lexical_analysis.html#operators-and-delimiters

Also adds a custom error message for ``<>`` ("not equal" in Pascal
and Python 2).

* +1

* address review: lowercase and move invalid rule

* address review: news

* address review: move test_guido_as_bdfl_ineq_tokens()

* address review: revert _PyTokenizer_From* changes

* + revert unrelated change

* address review: remove whatsnew entry
2026-09-25 19:51:59 +01:00
Pablo Galindo Salgado b7f81d4fab Refactor pegen C generation into explicit compilation phases (#157501)
* Move pegen grammar analysis into its own module

* Record pegen helper rule kinds explicitly

* Introduce immutable C parser data and separate lowering

* Add C emitters with local rule and output state

* Route C generation through the prepared parser model

* Fix pegen import formatting for lint

* Preserve and test shared-prefix preparation after rebase
2026-09-24 16:27:08 +00:00
Pablo Galindo Salgado 2a96282d9a gh-153569: consolidate tokenizer input, layout, and diagnostics (#157055)
* gh-153569: move tokenizer input state and relocation into the reader

* gh-153569: borrow diagnostic lines through the source API

* gh-153569: group indentation and logical-line state

* gh-153569: remove unused tokenizer cursor and source lookup APIs

* gh-153569: report tokenizer diagnostics without rewinding the scanner

* gh-153569: use tokenizer views and remove obsolete API remnants
2026-09-24 16:26:47 +00:00