gh-138535: Optimize fill_time for typical timestamps (#138537)
While file timestamps can be anything the file system can store, most
lie between the recent past and the near future. Optimize fill_time()
for typical timestamps in three ways:
- When possible, convert to nanoseconds with C arithmetic.
- When using C arithmetic and the seconds member is not required (for
st_birthtime), avoid creating a long object.
- When using C arithmetic, reorder the code to avoid the null checks
implied in Py_XDECREF().
Co-authored-by: Victor Stinner <vstinner@python.org>
Victor Stinner [Mon, 8 Sep 2025 22:45:42 +0000 (00:45 +0200)]
gh-137242: Add a --no-randomize option, and use it in Android CI (#138649)
Adds a --no-randomize option to the CI runner, so that randomisation can be easily
disabled for --fast-ci and --slow-ci configurations on single-threaded testing platforms
like Android, iOS, and Emscripten.
This makes information about the interpreter ABI more accessible.
Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Petr Viktorin [Mon, 8 Sep 2025 10:02:13 +0000 (12:02 +0200)]
gh-137210: Move PYTHON_API_VERSION & PYTHON_ABI_VERSION to patchlevel.h (GH-138545)
Move PYTHON_API_VERSION & PYTHON_ABI_VERSION to patchlevel.h
This allows removing #include "modsupport.h" from python_ver_rc.h,
which allows modsupport.h to use common helpers from Python.h --
specifically, `_Py_PACK_VERSION` for defining limited API.
Ron Frederick [Mon, 8 Sep 2025 08:36:12 +0000 (01:36 -0700)]
gh-138252: Add support in SSL module for getting and setting TLS signature algorithms (#138269)
The signature algorithms allowed for certificate-based client authentication or
for the server to complete the TLS handshake can be defined on a SSL context via
`ctx.set_client_sigalgs()` and `ctx.set_server_sigalgs()`.
With OpenSSL 3.4 or later, the list of available TLS algorithms can be retrieved
by `ssl.get_sigalgs()`.
With OpenSSL 3.5 or later, the selected signature algorithms can be retrieved from
SSL sockets via `socket.client_sigalg()` and `socket.server_sigalg()`.
This commit also partially amends 377b78761814e7d848361e642d376881739d5a29
by using `PyUnicode_DecodeFSDefault` instead of `PyUnicode_DecodeASCII` in
`_ssl._SSLContext.get_groups`, so that functions consistently decode strings
obtained from OpenSSL.
gh-126631: gh-137996: fix pre-loading of `__main__` (GH-135295)
gh-126631: gh-137996: fix pre-loading of `__main__`
The `main_path` parameter was renamed `init_main_from_name`, update the
forkserver code accordingly. This was leading to slower startup times when people
were trying to preload the main module.
---------
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Albert Zeyer [Sun, 7 Sep 2025 07:18:28 +0000 (09:18 +0200)]
gh-118981: multiprocessing.popen_spawn_posix, fix potential hang (gh-118982)
fix potential hang.
It can happen that the child crashes right in the beginning for whatever reason. In this case, the parent will hang when writing into the pipe, because the child fd is not closed yet.
The normal pattern is to close the child fds right after the child proc is forked/executed/spawned, so when the child dies, then also the pipes will be closed, and there will be no hang (the parent gets SIGPIPE instead).
R. David Murray [Sat, 6 Sep 2025 19:01:11 +0000 (15:01 -0400)]
gh-90548: Allow Alpine/MUSL to pass test_c_locale_coercion. (GH-134454)
Like cygwin, MUSL defaults to utf-8 if no variables are set. I have no
idea if the existing tests pass on cygwin, but I made the modifications
such that I shouldn't break it if is. The additional checks needed for
MUSL are guarded by DEFAULT_LOCALE_IS_C being False. Based on this
flag, we expect utf-8 for the encodings and no coercion message, as
long as LC_ALL is not set to C. (That looks like a bit of an issue with
the test structure, but I'm not going to attempt to "fix" that.)
DEFAULT_ENCODING is intentionally not given a default since it is only
used when DEFAULT_LOCALE_IS_C is False, and if you use the flag you'll
need to set it.
After reading through issue 30672, looking at the source, and running a
test on Android, I *think* the current situation is that coercion will
be done if the local is set to POSIX regardless of platform. However,
if the platform doesn't make POSIX equivalent to C, the encodings when
coercion is disabled will not be the same as for C (it is utf-8 on
android, for example). This means the tests would fail if POSIX were
added unconditionally to the EXPECTED_C_LOCALE_EQUIVALENTS as envisioned
in the issue. This *could* be fixed with another flag, but I'm not sure
it is worth the effort. I'm not even sure Python is behaving optimally
in this case (assuming my analysis is correct). So I just altered the
comment and add POSIX if and only if the platform is linux.
gh-88375, gh-111788: Fix parsing errors and normalization in robotparser (GH-138502)
* Don't fail trying to parse weird patterns.
* Don't fail trying to decode non-UTF-8 "robots.txt" files.
* No longer ignore trailing "?" in patterns and URLs.
* Distinguish raw special characters "?", "=" and "&" from the
percent-encoded ones.
* Remove tests that do nothing.
gh-60462: Fix locale.strxfrm() on Solaris (GH-138242)
It should interpret the result of wcsxfrm() as a sequence of abstract
integers, not a sequence of Unicode code points or using other encoding
scheme that does not preserve ordering.
Barney Gale [Wed, 3 Sep 2025 11:57:01 +0000 (12:57 +0100)]
GH-119169: Slightly speed up `os.walk(topdown=True)` (GH-121431)
GH-119186: Slightly speed up `os.walk(topdown=True)`
When `os.walk()` traverses into subdirectories in top-down mode, call
`os.path.join()` once to add a trailing slash, and use string concatenation
thereafter to generate child paths.
Reduce what happens in `load_tests` so that the next change,
moving the `Buffered*` tests to `test_bufferdio` is purely mechanical
movement and updating imports.
This adds two classes, one per I/O implementation, to act as dispatch to
the implementation-specific mocks as well as module members. Previously
the mappings CTestCase and PyTestCase provide were injected directly
during `load_tests`.
CTestCase and PyTestCase inherit from `unittest.TestCase` so when the
split happens default test discovery will work for the classes in
`test_bufferedio`. `test_general` keeps a manual test list for this
refactoring; some of the tests (ex. `ProtocolsTest`) aren't currently
run and fixing that + helpers to not be picked up is out of my current
scope.
CTestCase and PyTestCase have an `io` class member which points to the
implementation meaning that can be removed from individual test cases
which now inherit from them.
This code is picking up `MockRawIO` which is defined globally in the
module but these should use the mock specific to the I/O implementation
being tested.
Co-authored-by: Victor Stinner <vstinner@python.org>
Centralize `io` tests into the `test_io` module so they are easier to
find and work on. This will make it easier to split `test_general` which
takes 30+ seconds in a debug build on my machine.
This renames `test_bufio` to be `test_bufferedio` so that it matches
the implementation file name (`bufferedio.c`).
Validation performed:
Tests are run in parallel after change:
```bash
./python.exe -m test test_io -uall,largefile,extralargefile -M12G -j8
```
Docstring reformat in `test_io/__init__.py` looks reasonable: