125736 Commits

Author SHA1 Message Date
Bénédikt Tran
f693f84227
gh-129173: simplify PyCodec_XMLCharRefReplaceErrors logic (#129894)
Writing the decimal representation of a Unicode codepoint only requires to know the number of digits.

---------

Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-03-03 11:43:22 +00:00
Ned Batchelder
efbc5929ca
docs: internal notes have moved, correct references (#130762) 2025-03-03 06:38:49 -05:00
Bénédikt Tran
8f11af45de
gh-130149: refactor tests for HMAC (#130150)
Since we plan to introduce a built-in implementation for HMAC based on HACL*,
it becomes important for the HMAC tests to be flexible enough to avoid code
duplication.

In addition to the new layout based on mixin classes, we extend test coverage by
also testing the `__repr__` of HMAC objects and the HMAC one-shot functions.

We also fix the import to `_sha256` which, since gh-101924, resulted in some tests being
skipped as the module is no more available (its content was moved to the `_sha2` module).
2025-03-03 11:22:05 +01:00
Yuki Kobayashi
a105f99019
gh-101100: Fix sphinx warnings in library/email.errors.rst (#130774) 2025-03-03 11:56:45 +02:00
Victorien
373eb1b47a
gh-101100: Fix Sphinx documentation warnings in collections.rst (#130629) 2025-03-03 11:46:38 +02:00
Mike Castle
a85eeb9771
gh-129015: Improve disambiguation between NotImplemented and NotImplementedError (#129562)
---------

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2025-03-03 09:23:41 +01:00
Bénédikt Tran
097846502b
gh-127667: fix memory leaks in hashlib (#127668)
- Correctly handle `NULL` values returned by `EVP_MD_CTX_md`.
- Correctly free resources in error branches.
- Consistently suppress `_setException()` return value when needed.
- Collapse `_setException() + return NULL` into a single statement.
2025-03-03 09:20:33 +01:00
Kumar Aditya
7e3b788e8f
gh-128002: use efficient linked list implementation for eager tasks in asyncio (#130518) 2025-03-03 06:36:43 +00:00
Charles Machalow
f97e4098ff
gh-128041: Add terminate_workers and kill_workers methods to ProcessPoolExecutor (GH-128043)
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>
Commit-message-mostly-authored-by: Claude Sonnet 3.7 (because why not -greg)
2025-03-02 18:01:45 -08:00
Brandt Bucher
7afa476874
GH-130415: Use boolean guards to narrow types to values in the JIT (GH-130659) 2025-03-02 13:21:34 -08:00
Bénédikt Tran
c6513f7a62
gh-128481: indicate that the default value for FrameSummary.end_lineno changed in 3.13 (#130755)
The value taken by `FrameSummary.end_lineno` when passing `end_lineno=None` changed in gh-112097.

Previously, a `end_lineno` could be specified to be `None` directly but since 939fc6d, passing None makes
the constructor use the value of `lineno` instead.
2025-03-02 18:16:51 +01:00
Kanishk Pachauri
a42168d316
gh-130637: Add validation for numeric response data in stat() method (#130646)
Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
2025-03-02 08:05:40 -05:00
Bénédikt Tran
990ad272f6
gh-89083: add support for UUID version 6 (RFC 9562) (#120650)
Add support for generating UUIDv6 objects according to RFC 9562, §5.6 [1].

The functionality is provided by the `uuid.uuid6()` function which takes as inputs an optional 48-bit
hardware address and an optional 14-bit clock sequence. The UUIDv6 temporal fields are ordered
differently than those of UUIDv1, thereby providing improved database locality.

[1]: https://www.rfc-editor.org/rfc/rfc9562.html#section-5.6

---------

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-03-02 12:41:56 +01:00
Hugo Beauzée-Luyssen
214562ed4d
gh-130740: Move some stdbool.h includes after Python.h (#130738)
Move some `#include <stdbool.h>` after `#include "Python.h"` when `pyconfig.h` is not
included first and when we are in a platform-agnostic context. This is to avoid having
features defined by `stdbool.h` before those decided by `Python.h`.
2025-03-02 09:56:49 +00:00
Damien
051f0e5683
gh-128481: Improve documentation for traceback.FrameSummary (#128484)
Complete the `traceback.FrameSummary` signature and add missing
documentation for the `colno` and `end_{col,line}no` attributes.
2025-03-02 10:29:12 +01:00
Arijit Kumar Das
37145cb89f
Fix grammar typo in Doc/c-api/arg.rst (#130741) 2025-03-02 10:24:34 +01:00
Tim Hoffmann
c71e55869e
Add link in the importlib.metadata.version() docs (#130739)
Link the specification for the returned data makes it clearer what this is
and what the format of the version string can be.
2025-03-02 10:23:32 +01:00
Barney Gale
c9932a9ec8
GH-127381: pathlib ABCs: remove WritablePath.mkdir() arguments (#130611)
Remove the *mode*, *parents* and *exist_ok* arguments from
`WritablePath.mkdir()`. These arguments imply support for POSIX permissions
and checking for preexistence of the path or its parents, but subclasses of
`WritablePath` may not have these capabilities.

The public `Path.mkdir()` method retains these arguments.
2025-03-01 21:25:38 +00:00
Barney Gale
a55dffd66d
GH-127381: pathlib ABCs: remove ReadablePath.exists() and is_*() (#130520)
Remove `ReadablePath` methods duplicated by `ReadablePath.info`. To be
specific, we remove `exists()`, `is_dir()`, `is_file()` and `is_symlink()`.

The public `Path` class retains these methods.
2025-03-01 21:24:19 +00:00
Apostol Fet
5181ddb29f
gh-130160: use .. program:: directive for documenting cProfile CLI (#130314)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2025-03-01 23:39:25 +03:00
Duprat
a98a6bd112
gh-129401: Test repr rlock failing randomly (#129959)
Fix and simplify a test of `test_repr_rlock` about multiprocessing.RLock primitive.
2025-03-01 15:28:14 -05:00
Barney Gale
5326c27fc6
Revert "GH-116380: Speed up glob.[i]glob() by making fewer system calls. (#116392)" (#130743)
This broke tests on the 'aarch64 Fedora Stable Clang Installed 3.x' and
'AMD64 Fedora Stable Clang Installed 3.x' build bots.

This reverts commit da4899b94a9a9083fed4972b2473546e0d997727.
2025-03-01 20:04:01 +00:00
Sam Gross
5221d9ce0e
Revert "gh-128364: Fix flaky test_timeout test (gh-130724)" (gh-130732)
Change broke Android and iOS buildbots that do not have multiprocessing.

This reverts commit cfa0b1dc375e63cde28e61a47108c645b0e74834.
2025-03-01 17:22:13 +00:00
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