125763 Commits

Author SHA1 Message Date
Sam Gross
cfa0b1dc37
gh-128364: Fix flaky test_timeout test (gh-130724) 2025-03-01 16:20:43 +00:00
Bénédikt Tran
ddc27f9c38
gh-128974: Fix UnicodeError.__str__ when custom attributes have side-effects (#128975)
Fix some crashes when (custom) attributes of `UnicodeError` objects implement `object.__str__` with side-effects.
2025-03-01 12:01:20 +01:00
Sam Gross
75f38af781
Revert "gh-128942: make array module thread safe (#128943)" (#130707)
The change regressed performance on scimark benchmarks from the
pyperformance benchmark suite.

This reverts commit 8ba0d7bbc295781bf27902380521db97a272c442.
2025-02-28 16:57:48 -05:00
Barney Gale
da4899b94a
GH-116380: Speed up glob.[i]glob() by making fewer system calls. (#116392)
## Filtered recursive walk

Expanding a recursive `**` segment entails walking the entire directory
tree, and so any subsequent pattern segments (except special segments) can
be evaluated by filtering the expanded paths through a regex. For example,
`glob.glob("foo/**/*.py", recursive=True)` recursively walks `foo/` with
`os.scandir()`, and then filters paths through a regex based on "`**/*.py`,
with no further filesystem access needed.

This fixes an issue where `glob()` could return duplicate results.

## Tracking path existence

We store a flag alongside each path indicating whether the path is
guaranteed to exist. As we process the pattern:

- Certain special pattern segments (`""`, `"."` and `".."`) leave the flag
  unchanged
- Literal pattern segments (e.g. `foo/bar`) set the flag to false
- Wildcard pattern segments (e.g. `*/*.py`) set the flag to true (because
  children are found via `os.scandir()`)
- Recursive pattern segments (e.g. `**`) leave the flag unchanged for the
  root path, and set it to true for descendants discovered via
  `os.scandir()`.

If the flag is false at the end, we call `lstat()` on each path to filter
out missing paths.

## Minor speed-ups

- Exclude paths that don't match a non-terminal non-recursive wildcard
  pattern _prior_ to calling `is_dir()`.
- Use a stack rather than recursion to implement recursive wildcards.
  - This fixes a recursion error when globbing deep trees.
- Pre-compile regular expressions and pre-join literal pattern segments.
- Convert to/from `bytes` (a minor use-case) in `iglob()` rather than
  supporting `bytes` throughout. This particularly simplifies the code
  needed to handle relative bytes paths with `dir_fd`.
- Avoid calling `os.path.join()`; instead we keep paths in a normalized
  form and append trailing slashes when needed.
- Avoid calling `os.path.normcase()`; instead we use case-insensitive regex
  matching.

## Implementation notes

Much of this functionality is already present in pathlib's implementation
of globbing. The specific additions we make are:

1. Support for `dir_fd`
2. Support for `include_hidden`
3. Support for generating paths relative to `root_dir`

This unifies the implementations of globbing in the `glob` and `pathlib`
modules.

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-02-28 20:33:51 +00:00
Barney Gale
b545450961
GH-130608: Remove dirs_exist_ok argument from pathlib.Path.copy() (#130610)
This feature isn't sufficiently motivated.
2025-02-28 19:29:20 +00:00
Tian Gao
fdcbc29f26
gh-130660: Restore sys.ps1 and sys.ps2 after code.interact (#130661) 2025-02-28 13:15:55 -05:00
Mark Shannon
54965f3fb2
GH-130296: Avoid stack transients in four instructions. (GH-130310)
* Combine _GUARD_GLOBALS_VERSION_PUSH_KEYS and _LOAD_GLOBAL_MODULE_FROM_KEYS into _LOAD_GLOBAL_MODULE

* Combine _GUARD_BUILTINS_VERSION_PUSH_KEYS and _LOAD_GLOBAL_BUILTINS_FROM_KEYS into _LOAD_GLOBAL_BUILTINS

* Combine _CHECK_ATTR_MODULE_PUSH_KEYS and _LOAD_ATTR_MODULE_FROM_KEYS into _LOAD_ATTR_MODULE

* Remove stack transient in LOAD_ATTR_WITH_HINT
2025-02-28 18:00:38 +00:00
Petr Viktorin
ab11c09705
gh-129666: Revert "gh-129666: Add C11/C++11 to docs and -pedantic-errors to GCC/clang test_c[pp]ext tests (GH-130686)" (GH-130688)
This reverts commit 003e6d2b9776c07147a9c628eb028fd2ac3f0008.
2025-02-28 16:05:36 +00:00
Petr Viktorin
003e6d2b97
gh-129666: Add C11/C++11 to docs and -pedantic-errors to GCC/clang test_c[pp]ext tests (GH-130686) 2025-02-28 16:03:02 +01:00
Sam Gross
cc17307faa
gh-124878: Add temporary TSAN suppression for free_threadstate (gh-130602)
The race condition with `free_threadstate` and daemon threads exists in
both the free threading and default builds. We were missing a
suppression in the default build.
2025-02-28 09:27:51 -05:00
Sam Gross
038e4d606b
gh-130605: Use relaxed atomics to set the GIL switch interval (gh-130654)
The interval may be concurrently read by a thread attempting to acquire
the GIL.
2025-02-28 09:27:18 -05:00
Hugo van Kemenade
c1b4a6bd61
gh-130665: Only apply locale to calendar CLI via --locale and not LANG env var (#130676) 2025-02-28 16:24:05 +02:00
Petr Viktorin
e21863ce78
gh-46236: PyUnicode docs improvements (GH-129966)
Move deprecated PyUnicode API docs to new section

Move Py_UNICODE to a new "Deprecated API" section.

Formally soft-deprecate PyUnicode_READY, and move it

Document and soft-deprecate PyUnicode_IS_READY, and move it

Document PyUnicode_IS_ASCII, PyUnicode_CHECK_INTERNED

PyUnicode_New docs: Clarify requirements for "fresh" strings

PyUnicodeWriter_DecodeUTF8Stateful: Link "error-handlers"



Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-02-28 15:11:44 +01:00
Ilya Bazhenov
9f0879baf1
gh-130607: Extend and cleanup IPv6 tests (GH-121518)
Extend IPv6 tests and made little syntax refactoring
2025-02-28 11:31:30 +01:00
Hugo Beauzée-Luyssen
830f04b505
Postpone <stdbool.h> inclusion after Python.h (#130641)
Remove inclusions prior to Python.h.

<stdbool.h> will cause <features.h> to be included before Python.h can
define some macros to enable some additional features, causing multiple
types not to be defined down the line.
2025-02-28 10:09:27 +01:00
Petr Viktorin
fecf8bc8f2
gh-130595: Fix leak in WITH_EXCEPT_START error case (GH-130626)
Co-authored-by: Ken Jin <kenjin@python.org>
2025-02-28 08:58:50 +00:00
Tomas R.
24c52cb14c
gh-130655: Increase test coverage of gettext._expand_lang() (GH-130656) 2025-02-28 10:40:36 +02:00
Cody Maloney
7f39137662
gh-129726: Break gzip.GzipFile reference loop (#130055)
A reference loop was resulting in the `fileobj` held by the `GzipFile`
being closed before the `GzipFile`.

The issue started with gh-89550 in 3.12, but was hidden in most cases
until 3.13 when gh-62948 made it more visible.
2025-02-28 09:09:24 +01:00
leleliu008
e41981704f
gh-130617 : fix time_clockid_converter on DragonFlyBSD (#130634)
Signed-off-by: leleliu008 <leleliu008@gmail.com>
2025-02-28 08:56:00 +01:00
Russell Keith-Magee
9211b3dabe
gh-129200: Add locking to the iOS testbed startup sequence. (#130564)
Add a lock to ensure that only one iOS testbed per user can start at a time, so
that the simulator discovery process doesn't collide between instances.
2025-02-28 07:33:10 +08:00
Tian Gao
6140b0896e
gh-127271: Remove the PyCell_Get usage for framelocalsproxy (#130383) 2025-02-27 18:12:04 -05:00
Adam Turner
043ab3af9a
GH-121970: Extract `issue_role` into a new extension (#130615)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2025-02-27 19:06:13 +00:00
Sam Gross
7aeaa5af2c
gh-130091: Reorder _PyThreadState_Attach to avoid data race (gh-130092)
This moves `tstate_activate()` down to avoid a data race in the free
threading build on the `_PyRuntime`'s thread-local `autoTSSkey`. This
key is deleted during runtime finalization, which may happen
concurrently with a call to `_PyThreadState_Attach`.

The earlier `tstate_try/wait_attach` ensures that the thread is blocked
before it attempts to access the deleted `autoTSSkey`.

This fixes a TSAN reported data race in
`test_threading.test_import_from_another_thread`.
2025-02-27 13:57:19 -05:00
Pablo Galindo Salgado
e06bebb87e
gh-130618: Fix parser error when using lambdas inside f-strings (#130638) 2025-02-27 15:51:17 +00:00
Yuki Kobayashi
b26286ca49
Docs: Fix a misplaced statement in the document for ServerProxy (GH-130616)
The sentence "If an HTTPS URL ..." explains what the parameter means,
so moved it to the paragraph explaining what the other parameters mean.
2025-02-27 16:14:56 +01:00
Tomasz Pytel
e85f81f430
gh-129107: fix thread safety of bytearray where two critical sections are needed (#130227) 2025-02-27 20:29:58 +05:30
Tomasz Pytel
8ba0d7bbc2
gh-128942: make array module thread safe (#128943)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-02-27 14:00:14 +00:00
Sam Gross
d027787c8d
gh-130421: Fix data race on timebase initialization (gh-130592)
Windows and macOS require precomputing a "timebase" in order to convert
OS timestamps into nanoseconds. Retrieve and compute this value during
runtime initialization to avoid data races when accessing the time.
2025-02-27 13:27:54 +00:00
Fredrik Ahlberg
45a24f54af
gh-129288: Add optional l2_cid and l2_bdaddr_type in BTPROTO_L2CAP socket address tuple (#129293)
Add two optional, traling elements in the AF_BLUETOOTH socket address tuple:

- l2_cid, to allow e.g raw LE ATT connections
- l2_bdaddr_type. To be able to connect L2CAP sockets to Bluetooth LE devices,
  the l2_bdaddr_type must be set to BDADDR_LE_PUBLIC or BDADDR_LE_RANDOM.
2025-02-27 12:51:47 +00:00
Victor Stinner
a083633fa0
gh-109959: Remove test_glob.test_selflink() (#130551)
The test is not reliable, it fails randomly on Linux:
https://github.com/python/cpython/issues/109959#issuecomment-2577550700
2025-02-27 11:07:08 +01:00
Mark Shannon
2a18e80695
GH-128534: Instrument branches for async for loops. (GH-130569) 2025-02-27 09:36:41 +00:00
Adam Turner
fda056e64b
gh-130604: Always run all matrix workflows in GitHub Actions (#130603) 2025-02-26 21:44:48 +00:00
Sam Gross
959f43315e
gh-130605: Temporarily disable test_concurrent_futures in TSAN CI job (gh-130606)
There are a number of data races in the default build without
suppressions that are exposed by this test. Disable the test for now
under TSAN until we have suppressions or fix the data races.
2025-02-26 21:36:53 +00:00
Barney Gale
b251d409f9
GH-125413: Add private pathlib.Path method to write metadata (#130238)
Replace `WritablePath._copy_writer` with a new `_write_info()` method. This
method allows the target of a `copy()` to preserve metadata.

Replace `pathlib._os.CopyWriter` and `LocalCopyWriter` classes with new
`copy_file()` and `copy_info()` functions. The `copy_file()` function uses
`source_path.info` wherever possible to save on `stat()`s.
2025-02-26 21:07:27 +00:00
shenxianpeng
5ba69e747f
gh-127785: Reduce permissions in the check labels workflow (#130596) 2025-02-26 20:47:41 +00:00
Victor Stinner
daeb0efaf4
gh-111178: Fix function signatures in sliceobject.c (#130575)
Rename slicehash() to slice_hash() for consistency.
2025-02-26 21:37:22 +01:00
Victor Stinner
05aba4e799
gh-111178: Fix function signatures in instruction_sequence.c (#130591) 2025-02-26 21:36:26 +01:00
Victor Stinner
d5d4cbbd8f
gh-111178: Fix function signatures in namespaceobject.c (#130590) 2025-02-26 21:35:56 +01:00
Victor Stinner
1b635d86cd
gh-111178: Fix function signatures in symtable.c (#130589) 2025-02-26 21:35:24 +01:00
Adam Turner
3f3e1c4095
Doc: Strip trailing whitespace in `pydoc_topics` (#130492) 2025-02-26 20:10:55 +00:00
Sam Gross
45bc120d45
gh-130519: Fix crash in QSBR when destructor reenters QSBR (gh-130553)
The `free_work_item()` function in QSBR may call arbitrary code via
Python object destructors, which may reenter the QSBR code. Reorder
the processing of work items to be robust to reentrancy.

Also fix the TODO for the out of memory situation.
2025-02-26 14:55:15 -05:00
Dino Viehland
5c8e8704c3
gh-130595: Keep traceback alive for WITH_EXCEPT_START (#130562)
Keep traceback alive for WITH_EXCEPT_START
2025-02-26 10:41:26 -08:00
Petr Viktorin
9e474a98af
gh-128982: Revert "#128982: Substitute regular expression in http.cookiejar.join_header_words for an efficient alternative (GH-128983)" and add tests (GH-130584)
* Revert "gh-128982: Substitute regular expression in `http.cookiejar.join_header_words` for an efficient alternative (GH-128983)"

This reverts commit 56e190068177855266f32a7efa329d145b279f94.

* Add tests
2025-02-26 15:42:39 +01:00
Bénédikt Tran
56e1900681
gh-128982: Substitute regular expression in http.cookiejar.join_header_words for an efficient alternative (GH-128983)
The function does not anymore rely on a regular expression
to find alphanumeric characters and underscores.
2025-02-26 13:01:32 +01:00
Paul Moore
64ccbbbf36
gh-130379: Fix incorrect zipapp logic to avoid including the target in itself (gh-130509) 2025-02-26 11:25:30 +00:00
Bénédikt Tran
f976892b7d
gh-111178: fix UBSan failures in Modules/_hashopenssl.c (GH-129802)
Fix UBSan failures for `EVPobject`, `HMACobject`
2025-02-26 09:24:44 +00:00
Mark Shannon
129db32d6f
GH-130396: Treat clang -Og as optimized for gdb tests (GH-130550) 2025-02-26 09:01:58 +00:00
Mark Shannon
263d56e1e2
GH-130396: Increase trashcan overhead (GH-130552)
Double trashcan overhead
2025-02-26 08:54:24 +00:00
Bénédikt Tran
59d3ad0c62
gh-111178: fix UBSan failures in Modules/_tkinter.c (GH-129795)
Fix UBSan failures for `TkappObject`, `PyTclObject`, `TkttObject`

Implement CHECK_TCL_APPARTMENT as a static inline function
2025-02-26 09:40:48 +01:00
Bénédikt Tran
18bc5b7839
gh-111178: fix UBSan failures in Modules/_zoneinfo.c (GH-129798)
Fix UBSan failures for `PyZoneInfo_ZoneInfo`

Fix semantic naming
2025-02-26 09:36:59 +01:00