125818 Commits

Author SHA1 Message Date
Mark Shannon
2bef8ea8ea
GH-127705: Use _PyStackRefs in the default build. (GH-127875) 2025-03-10 14:06:56 +00:00
Yuki Kobayashi
7cc99a54b7
gh-101100: Fix sphinx warnings in library/asyncio-subprocess.rst (#130994) 2025-03-10 12:38:08 +00:00
Stan Ulbrych
98fa4a49fe
gh-80421: Correct definitions of time (#130984)
Based on the Wikipedia article, UTC is better said to be a successor than a renaming of GTC and language agnostic rather than an English-French compromise.
2025-03-09 16:09:23 -04:00
Barney Gale
475f933ed8
GH-130614: pathlib ABCs: revise test suite for path joining (#130988)
Test `pathlib.types._JoinablePath` in a dedicated test module. These tests
cover `LexicalPath`, `PurePath` and `Path`, where `LexicalPath` is defined
in a new `test.test_pathlib.support` package.
2025-03-09 17:02:37 +00:00
Barney Gale
bbd6d17ef8
GH-130614: pathlib ABCs: support alternate separator in full_match() (#130991)
In `pathlib.types._JoinablePath.full_match()`, treat alternate path
separators in the path and pattern as if they were primary separators. e.g.
if the parser is `ntpath`, then `P(r'foo/bar\baz').full_match(r'*\*/*')` is
true.
2025-03-09 16:36:59 +00:00
Barney Gale
ba64cc5db4
GH-130614: pathlib ABCs: retain original separator in with_name() (#130990)
In `pathlib.types._JoinablePath.with_name()`, retain any alternative path
separator preceding the old name, rather stripping and replacing it with a
primary separator. As a result, this method changes _only_ the name.
2025-03-09 16:36:20 +00:00
donBarbos
c240c2d88a
gh-130160: use .. program:: directive for documenting pdb CLI (#130996) 2025-03-09 11:55:23 -04:00
donBarbos
92e5f826ac
gh-130160: use .. program:: directive for documenting webbrowser CLI (#130995)
use `.. program::` directive for documenting `webbrowser` CLI
2025-03-09 09:57:59 +03:00
Affan Shaikhsurab
a3990df612
gh-123726: Document caveats of zipfile.Path around name sanitization (#130537)
Add a note to the `zipfile.Path` class documentation clarifying that it does not sanitize filenames. This emphasizes the caller's responsibility to validate or sanitize inputs, especially when handling untrusted ZIP archives, to prevent path traversal vulnerabilities. The note also references the `extract` and `extractall` methods for comparison and suggests using `os.path.abspath` and `os.path.commonpath` for safe filename resolution.
2025-03-08 16:37:05 -05:00
Sam Gross
edd1eca336
gh-130954: Fix multiprocessing test_notify_n (#130955)
The test could deadlock trying join on the worker processes.
Apply the same technique as gh-130933.

Join the process before the test ends in `test_notify` as well.
2025-03-08 13:04:30 -05:00
Chris Markiewicz
72e5b25efb
gh-128646: Implement GzipFile.readinto[1]() methods (GH-128647)
The new methods simply delegate to the underlying buffer, much like the existing GzipFile.read[1] methods.  This avoids extra allocations caused by the BufferedIOBase.readinto implementation previously used.

This commit also factors out a common readability check rather than copying it an additional two times.
2025-03-07 21:04:45 -06:00
Diego Russo
7879081198
gh-130917: update timer and workload in test_signal (#130918)
The workload to advance the virtual timeout is too lightweight for some
platforms. As result the test goes in timeout as it never reaches the
end of the timer. By having a heavier workload, the virtual timer
advances rapidly and the SIGVTALRM is sent before the timeout.
2025-03-07 16:10:02 -05:00
morotti
b1b4f9625c
gh-117151: IO performance improvement, increase io.DEFAULT_BUFFER_SIZE to 128k (GH-118144)
Co-authored-by: rmorotti <romain.morotti@man.com>
2025-03-07 11:36:12 -08:00
Barney Gale
4bf25a0dc8
GH-128520: Merge pathlib._local into pathlib (#130748)
The `pathlib` module used to import stuff from both `_abc` and `_local`,
but nowadays the `_local` module provides the entire public pathlib
implementation, so there's no reason for the indirection.
2025-03-07 19:24:57 +00:00
Sam Gross
12db45211d
gh-130851: Only intern constants of types generated by the compiler (#130901)
The free-threading build interns and immortalizes most constants
generated by the bytecode compiler. However, users can construct their
own code objects with arbitrary constants. We should not intern or
immortalize these objects if they are not of a type that we know how to
handle.

This change fixes a reference leak failure in the recently added
`test_code.test_unusual_constants` test. It also addresses a potential
crash that could occur when attempting to destroy an immortalized
object during interpreter shutdown.
2025-03-07 10:34:53 -05:00
Sam Gross
c476410dc5
gh-110206: Fix multiprocessing test_notify_all (#130933)
The test could deadlock trying join on the worker processes due to a
combination of behaviors:

* The use of `assertReachesEventually` did not ensure that workers
  actually woken.release() because the SyncManager's Semaphore does not
  implement get_value.

* This mean that the test could finish and the variable "sleeping" would
  got out of scope and be collected. This unregisters the proxy leading
  to failures in the worker or possibly the manager.

* The subsequent call to `p.join()` during cleanUp therefore never
  finished.

This takes two approaches to fix this:

1) Use woken.acquire() to ensure that the workers actually finish
   calling woken.release()

2) At the end of the test, wait until the workers are finished, while `cond`,
   `sleeping`, and `woken` are still valid.
2025-03-07 09:58:09 -05:00
Mark Shannon
89df62c120
GH-128534: Fix behavior of branch monitoring for async for (GH-130847)
* Both branches in a pair now have a common source and are included in co_branches
2025-03-07 14:30:31 +00:00
Boris Verkhovskiy
e5527f2cdd
Correct function name in Doc/extending/embedding.rst (#127539) 2025-03-07 14:06:36 +01:00
Shantanu
0a9ae5ed48
gh-130932: Fix incorrect exception handling in _PyModule_IsPossiblyShadowing (#130934)
I chose to not raise an exception here because I think it would be
confusing for module attribute access to start raising something other
than AttributeError if e.g. the cwd goes away

Without the change in moduleobject.c
```
./python.exe -m unittest test.test_import.ImportTests.test_script_shadowing_stdlib_cwd_failure
...
Assertion failed: (PyErr_Occurred()), function _PyObject_SetAttributeErrorContext, file object.c, line 1253.
```
2025-03-06 23:41:28 -08:00
scotscotmcc
8190571a75
gh-130893: Fix typo in SqliteInteractiveConsole.runsource docstring (#130894) 2025-03-06 22:10:37 -08:00
Cody Maloney
886a4d74ee
gh-129011: Update comments in FileIO to match current code (#129012) 2025-03-06 17:18:22 -08:00
Stan Ulbrych
a385add401
gettext: Remove outdated "TODO" comment (#130890) 2025-03-06 23:41:03 +00:00
Sam Gross
a025f27d94
gh-130920: Fix data race in STORE_SUBSCR_LIST_INT (#130923)
The write of the item to the list needs to use an atomic operation in
the free threading build.

Co-authored-by: Tomasz Pytel <tompytel@gmail.com>
2025-03-06 15:59:48 -05:00
mpage
6c6600f683
gh-118331: Fix test_list.ListTest.test_no_memory under trace refs build (#130921)
Fix `test_list.ListTest.test_no_memory` under trace refs build

Memory allocation ends up failing in _PyRefchainTrace(), which produces
different output. Assert that we don't segfault, which is the thing
we want to test and is less brittle than checking output.
2025-03-06 12:11:50 -08:00
Sam Gross
c4d37eefb7
gh-128364: Fix flaky test_concurrent_futures.test_wait tests (gh-130742)
Use events instead of relying on `time.sleep()`. The tests are also now about
four times faster.
2025-03-06 12:30:58 -05:00
Sam Gross
052cb717f5
gh-124878: Fix race conditions during interpreter finalization (#130649)
The PyThreadState field gains a reference count field to avoid
issues with PyThreadState being a dangling pointer to freed memory.
The refcount starts with a value of two: one reference is owned by the
interpreter's linked list of thread states and one reference is owned by
the OS thread. The reference count is decremented when the thread state
is removed from the interpreter's linked list and before the OS thread
calls `PyThread_hang_thread()`. The thread that decrements it to zero
frees the `PyThreadState` memory.

The `holds_gil` field is moved out of the `_status` bit field, to avoid
a data race where on thread calls `PyThreadState_Clear()`, modifying the
`_status` bit field while the OS thread reads `holds_gil` when
attempting to acquire the GIL.

The `PyThreadState.state` field now has `_Py_THREAD_SHUTTING_DOWN` as a
possible value. This corresponds to the `_PyThreadState_MustExit()`
check. This avoids race conditions in the free threading build when
checking `_PyThreadState_MustExit()`.
2025-03-06 10:38:34 -05:00
Sebastian Rittau
c6dd2348ca
gh-127647: Add typing.Reader and Writer protocols (#127648) 2025-03-06 07:36:19 -08:00
Ken Jin
9c691500f9
gh-128563: Clarify wording in Whats new for Tail call (#130911)
Clarify wording in Whats new for Tail call
2025-03-06 13:38:05 +00:00
Sergey B Kirpichev
2352bd418a
gh-130860: Fix width calculation, when separators in fractional part (GH-130865)
This amends f39a07be47
2025-03-06 14:26:29 +02:00
Jamie Phan
10cdd7f91f
GH-130903: typo in optimizer DSL for _GUARD_BOTH_UNICODE (#130904)
Typo introduced in gh-118910.
2025-03-06 12:11:08 +01:00
Tomasz Pytel
aeb2327386
gh-130574: renumber RESUME opcode from 149 to 128 (GH-130685) 2025-03-06 08:59:36 +00:00
Ken Jin
e4a60248b0
gh-128563: Add correction note to tail call in whats new (#130908)
* Add correction note to tail call in whats new

* Update 3.14.rst
2025-03-06 14:43:53 +08:00
Bartosz Sławecki
293fa3433e
gh-85795: Raise a clear error when super() is used in typing.NamedTuple subclasses (#130082) 2025-03-05 20:45:47 -08:00
Charles Machalow
5e73ece95e
gh-128041: Fix incorrect bullet placement in "What's new" (GH-130900) 2025-03-05 22:59:56 +00:00
Tshepang Mbambo
1b5db5adfe
GH-130153: Reword the wildcard matching part of the tutorial (GH-129954) 2025-03-05 14:59:47 -08:00
Charles Machalow
ba05a4ebcb
gh-128041: Add terminate_workers and kill_workers methods to ProcessPoolExecutor (GH-130849)
This adds two new methods to `multiprocessing`'s `ProcessPoolExecutor`:
- **`terminate_workers()`**: forcefully terminates worker processes using `Process.terminate()`
- **`kill_workers()`**: forcefully kills worker processes using `Process.kill()`

These methods provide users with a direct way to stop worker processes without `shutdown()` or relying on implementation details, addressing situations where immediate termination is needed.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Sam Gross @colesbury
Commit-message-mostly-authored-by: Claude Sonnet 3.7 (because why not -greg)
2025-03-05 14:31:42 -08:00
Diego Russo
02de9cb9a8
gh-129964: Fix JIT crash on Windows on Arm (GH-130882) 2025-03-05 12:40:50 -08:00
Brandt Bucher
5d8db36bbb
GH-115802: JIT using the "medium" code model on x86_64-unknown-linux-gnu (GH-130097) 2025-03-05 11:54:33 -08:00
mpage
d7bb7c7817
gh-118331: Fix a couple of issues when list allocation fails (#130811)
* Fix use after free in list objects

Set the items pointer in the list object to NULL after the items array
is freed during list deallocation. Otherwise, we can end up with a list
object added to the free list that contains a pointer to an already-freed
items array.

* Mark `_PyList_FromStackRefStealOnSuccess` as escaping

I think technically it's not escaping, because the only object that
can be decrefed if allocation fails is an exact list, which cannot
execute arbitrary code when it is destroyed. However, this seems less
intrusive than trying to special cases objects in the assert in `_Py_Dealloc`
that checks for non-null stackpointers and shouldn't matter for performance.
2025-03-05 10:42:09 -08:00
Burkov Egor
2904ec2273
gh-130878: Add extra check to prepare_ssl.py (GH-130879) 2025-03-05 17:08:30 +00:00
Sebastian Rittau
4f6218959e
Update links from typing.readthedocs.io to typing.python.org (#130877) 2025-03-05 17:26:44 +02:00
Sam Gross
2905690a91
gh-130851: Don't crash when deduping unusual code constants (#130853)
The bytecode compiler only generates a few different types of constants,
like str, int, tuple, slices, etc. Users can construct code objects with
various unusual constants, including ones that are not hashable or not
even constant.

The free threaded build previously crashed with a fatal error when
confronted with these constants. Instead, treat distinct objects of
otherwise unhandled types as not equal for the purposes of deduplication.
2025-03-05 15:04:49 +01:00
Mark Shannon
78d50e91ff
GH-127705: better double free message. (GH-130785)
* Add location information when accessing already closed stackref

* Add #def option to track closed stackrefs to provide precise information for use after free and double frees.
2025-03-05 14:00:42 +00:00
Serhiy Storchaka
f33d21e24f
gh-127750: Improve repr of functools.singledispatchmethod (GH-130220) 2025-03-05 13:10:05 +02:00
Victor Stinner
67a942d427
gh-116742: Fix subprocess test_check_output_timeout() (#130836)
Fix a race condition in test_check_output_timeout() of
test_subprocess. Don't write into stdout anymore, since there is no
reliable way to synchronize the parent and the child processes.

Change the timeout from 3 seconds to 0.1 seconds, and remove
@requires_resource('walltime') decorator.
2025-03-05 10:51:33 +00:00
Serhiy Storchaka
63d25f8d0c
gh-130824: Clean up test wrappers for PyLong_*AndOverflow functions (GH-130871) 2025-03-05 11:50:53 +01:00
Peter Bierma
90130807d9
gh-130824: Add tests for NULL in PyLong_*AndOverflow functions (GH-130828)
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2025-03-05 09:58:39 +01:00
Adam Turner
e53d105872
GH-125722: Increase minimum supported Sphinx to 8.2.0 (#130444) 2025-03-05 00:31:01 +00:00
Sam Gross
2f6e0e9f70
gh-130794: Process interpreter QSBR queue in _PyMem_AbandonDelayed. (gh-130808)
This avoids a case where the interpreter's queue of memory to be freed
could grow rapidly if there are many short lived threads.
2025-03-04 18:04:04 -05:00
Bert Peters
cb67b44ca9
gh-127371 Avoid unbounded growth SpooledTempfile.writelines (GH-127372) 2025-03-05 00:06:07 +02:00