Eric Snow [Wed, 30 Apr 2025 23:34:05 +0000 (17:34 -0600)]
gh-132775: Add _PyPickle_GetXIData() (gh-133107)
There's some extra complexity due to making sure we we get things right when handling functions and classes defined in the __main__ module. This is also reflected in the tests, including the addition of extra functions in test.support.import_helper.
gh-132987: Support __index__() in the posix module (GH-133096)
Support it for the dev_t values in mknod(), major(), minor() and makedev(),
CPU numbers in sched_setaffinity(), group numbers in setgroups(),
configuration name in fpathconf(), pathconf(), confstr(), and sysconf().
Neil Schemenauer [Mon, 28 Apr 2025 20:28:44 +0000 (13:28 -0700)]
gh-127266: avoid data races when updating type slots (gh-131174)
In the free-threaded build, avoid data races caused by updating type slots
or type flags after the type was initially created. For those (typically
rare) cases, use the stop-the-world mechanism. Remove the use of atomics
when reading or writing type flags. The use of atomics is not sufficient to
avoid races (since flags are sometimes read without a lock and without
atomics) and are no longer required.
Neil Schemenauer [Mon, 28 Apr 2025 19:54:55 +0000 (12:54 -0700)]
gh-122320: Limit dict key versions used by test_opcache. (gh-132961)
The `test_load_global_module()` test consumes a lot of dict key versions.
Skip the test if we have consumed half of the available versions that can be
used for the "load global" cache.
Barney Gale [Mon, 28 Apr 2025 19:18:56 +0000 (20:18 +0100)]
GH-128520: pathlib ABCs tests: use explicit text encoding (#133105)
Follow-up to fbffd70. Set `encoding='utf-8'` when reading and writing text
in the tests for the private pathlib ABCs, which allows the tests to run
with `-W error -X warn_default_encoding`
Neil Schemenauer [Mon, 28 Apr 2025 18:52:08 +0000 (11:52 -0700)]
gh-132942: Fix races in type lookup cache (gh-133032)
Two races related to the type lookup cache, when used in the
free-threaded build. This caused test_opcache to sometimes fail (as
well as other hard to re-produce failures).
Eric Snow [Mon, 28 Apr 2025 18:46:22 +0000 (12:46 -0600)]
gh-132775: Drop PyUnstable_InterpreterState_GetMainModule() (gh-132978)
We replace it with _Py_GetMainModule(), and add _Py_CheckMainModule(), but both in the internal-only C-API. We also add _PyImport_GetModulesRef(), which is the equivalent of _PyImport_GetModules(), but which increfs before the lock is released.
This is used by a later change related to pickle and handling __main__.
Barney Gale [Mon, 28 Apr 2025 18:04:20 +0000 (19:04 +0100)]
GH-128520: pathlib ABCs: raise text encoding warnings at correct stack level (#133051)
Ensure that warnings about unspecified text encodings are emitted from
`ReadablePath.read_text()`, `WritablePath.write_text()` and `magic_open()`
with the correct stack level set.
- Add @cpython_only decorator to lazy import tests
- Rename reference to SOURCE format
- Always two newlines between test case classes
- Merge two classes of ForwardRef tests
- Use get_annotations instead of annotationlib.get_annotations
- Format test_annotationlib with Black (not expecting that we'll keep this up
but it's close to Black-formatted right now)
Petr Viktorin [Mon, 28 Apr 2025 13:48:48 +0000 (15:48 +0200)]
gh-87135: Raise PythonFinalizationError when joining a blocked daemon thread (gh-130402)
If `Py_IsFinalizing()` is true, non-daemon threads (other than the current one)
are done, and daemon threads are prevented from running, so they
cannot finalize themselves and become done. Joining them (without timeout)
would block forever.
Raise PythonFinalizationError instead of hanging.
Raise even when a timeout is given, for consistency with trying to join your own thread.
See gh-123940 for a use case: calling `join()` from `__del__`. This is
ill-advised, but an exception should at least make it easier to diagnose.
gh-53032: support IEEE 754 contexts in the decimal module (#122003)
This was in C version from beginning, but available only
on conditional compilation (EXTRA_FUNCTIONALITY). Current
patch adds function to create IEEE contexts to the
pure-python module as well.
Steve Dower [Mon, 28 Apr 2025 12:57:47 +0000 (13:57 +0100)]
gh-132930: Implement PEP 773 (GH-132931)
This change to the core CPython repo:
* Adds PyManager support to PC/layout
* Adds a warning message to the legacy py.exe if subcommands are invoked
* Add deprecation message to traditional installer
* Updates using/windows docs
Michał Górny [Sun, 27 Apr 2025 22:19:59 +0000 (00:19 +0200)]
gh-133005: Support `tarfile.open(mode="w|xz", preset=...)` (GH-133007)
* gh-133005: Support `tarfile.open(mode="w|xz", preset=...)`
Support passing the `preset` option to `tarfile.open` when the file
is open with `mode="w|xz"`. This aligns the behavior with `"w:xz"`
mode.
* Also raise an error for `compresslevel` or `preset` with wrong mode
Raise an error if `compresslevel` or `preset` argument is specified
for stream mode with incorrect compression. This should reduce the risk
of mistakes and align the stream modes with regular modes, that raise
an implicit TypeError on unsupported arguments.
* Apply suggestions from code review
Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
Valters Jansons [Sun, 27 Apr 2025 21:56:00 +0000 (00:56 +0300)]
gh-132026: Ensure _MIPS_SIM has defined _ABI identifiers for comparison (GH-132027)
When built on a MIPS architecture, `_MIPS_SIM` is used to determine
architecture specifics. The value is expected to match either
`_ABIO32`, `_ABIN32` or `_ABI64`.
In `gcc` config/mips/mips.h these values are defined as compiler
`builtin_define` inside of a switch/case. That means, mips64el and
mips64 architectures know about `_ABI64` but don't know about `_ABIO32`
and `_ABIN32`. In turn, when CPython tries to use them in comparison,
they may be undefined identifiers.
In default compiler behavior, the undefined identifier will be
evaluated as zero, and it will not match `_MIPS_SIM`. However, the
issues pop up when `-Wundef` (or, even worse, `-Werror=undef`) compiler
flag is enabled. Then suddenly it's visible as a warning or error.