Commit graph

126791 commits

Author SHA1 Message Date
Emma Smith
3b4333583f
gh-132983: Introduce _zstd bindings module (GH-133027)
* Add _zstd module for https://peps.python.org/pep-0784/

This commit introduces the `_zstd` module, with bindings to libzstd from
the pyzstd project. It also includes the unix build system configuration.
Windows build system support will be integrated independently as it
depends on integration with cpython-source-deps.

* Add _zstd to modules

* Fix path for compression.zstd module

* Ignore _zstd module like _io

* Expand module state macros to improve code quality

Also removes module state references from the classes in the _zstd
module and instead uses PyType_GetModuleState()

* Remove backticks suggested in review

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>

* Use critical sections to lock object state

This should avoid races and deadlocks.

* Remove compress/decompress and mark module as not reliant on the GIL

The `compress`/`decompress` functions will be moved to Python code for simplicity.
C implementations can always be re-added in the future.

Also, mark _zstd as not requiring the GIL.

* Lift critical section to avoid clang warning

* Respond to comments by picnixz

* Call out pyzstd explicitly in license description

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>

* Use a much more robust implementation...

... for `get_zstd_state_from_type`

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Use PyList_GetItemRef for thread safety purposes

* Use a macro for the minimum supported version

* remove const from primivite types

* Use PyMem_New in another spot

* Simplify error handling in _get_frame_size

* Another simplification of error handling in get_frame_info

* Rename _module_state to mod_state

* Rewrite comment explaining the context of the code

* Add link to pyzstd

* Add TODO about refactoring dict training code

* Use PyModule_AddObjectRef over PyModule_AddObject

PyModule_AddObject is soft-deprecated, so we should use PyModule_AddObjectRef

* Check result of OutputBufferGrow

* Simplify return logic in `add_constant_to_type`

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Ignore return value of _zstd_clear()

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Remove redundant comments

* Remove __reduce__ from ZstdDict

We should instead document that to pickle a dictionary a user should use
the `.dict_content` attribute.

* Use PyUnicode_FromFormat instead of a buffer

* Don't use C constants/types in error messages

* Make error messages easier to understand for Python users

* Lower minimum required version 1.4.0

* Use casts and make slot function signatures correct

* Be consistent with CPython on const usage

* Make else clauses in line with PEP 7

* Fix over-indented blocks in argument clinic

* Add critical section around ZSTD_DCtx_setParameter

* Add a TODO about refactoring critical sections

* Use Py_UNREACHABLE

* Move bytes operations out of Py_BEGIN_ALLOW_THREADS

* Add TODO about ensuring a lock is held

* Remove asserts that may not be correct

* Add TODO to make ZstdDict and others GC objects

* Make objects GC tracked

* Remove unused include

* Fix some memory issues

* Fix refleaks on module and in ZstdDict

* Update configure to check for ZDICT_finalizeDictionary

* Properly check version in configure

* exit(1) if check fails

* Use AC_RUN_IFELSE

* Use a define() to re-use version check

* Actually properly set _zstd module status based on version

---------

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-05-04 01:29:55 +00:00
Pablo Galindo Salgado
2bc8365231
GH-91048: Add utils for printing the call stack for asyncio tasks (#133284) 2025-05-04 00:51:57 +00:00
Serhiy Storchaka
7363e8d24d
gh-133139: Add curses.assume_default_colors() (GH-133145)
This is a refinement of the curses.use_default_colors() function which
allows to change the color pair 0.
2025-05-03 23:33:22 +03:00
sobolevn
3e256b9118
gh-123539: Add new error message changes to "Whats New" (#133344) 2025-05-03 19:18:40 +02:00
sobolevn
881144fa58
gh-133210: Fix test_rlcompleter in --without-doc-strings mode (#133332) 2025-05-03 18:38:27 +03:00
Hugo van Kemenade
a85f526742
gh-123299: Add PyREPL syntax highlighting to release highlights (#133321) 2025-05-03 17:25:13 +02:00
Sergey B Kirpichev
f16f06f336
gh-133304: workaround for RISC-V in PyFloat_Pack4/Unpack4() (#133328) 2025-05-03 17:07:52 +02:00
Serhiy Storchaka
84a08f8629
gh-133306: Use \z instead of \Z in regular expressions in the stdlib (GH-133337) 2025-05-03 17:58:49 +03:00
Serhiy Storchaka
add0ca9ea0
gh-133306: Use \z instead of \Z in fnmatch.translate() and glob.translate() (GH-133338) 2025-05-03 17:58:21 +03:00
sobolevn
cb3174113e
gh-133117: Enable stricter mypy checks for tomllib (#133206) 2025-05-03 16:57:09 +03:00
Semyon Moroz
1550c30fd5
gh-130160: use .. program:: directive for documenting platform CLI (#133335) 2025-05-03 15:05:04 +03:00
Harry
77c391a1b1
gh-131524: Update platform CLI to use argparse (#131542)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-05-03 08:58:59 +00:00
Serhiy Storchaka
ac56f8cc8d
gh-133306: Support \z as a synonym for \Z in regular expressions (GH-133314)
\Z was an error inherited from PCRE 0.95. It was fixed in PCRE 2.0.
In other engines, \Z means not “anchor at string end”, but
“anchor before optional newline at string end”.

\z means “anchor at string end” in most RE engines.
2025-05-03 07:54:33 +00:00
Kirill Podoprigora
fe44fc4f43
gh-114713: Revert gh-114731 (#133330)
Revert "gh-114713: Handle case of an empty string passed to `zoneinfo.ZoneInfo` (#114731)"

This reverts commit 884df116d7.
2025-05-03 07:47:08 +00:00
sobolevn
ca0a96dfaa
gh-133194: Fix regression with PEP 758 parsing on older feature_version (#133289)
gh-133192: Fix regression with PEP 758 parsing on older `feature_version`
2025-05-03 10:33:14 +03:00
Jelle Zijlstra
345fdce1d0
gh-133037: Add test for shadowing __annotate__ (#133084) 2025-05-02 19:42:49 -07:00
Malcolm Smith
245cd6c532
gh-91156: Document how TextIOWrapper interacts with UTF-8 mode (GH-132885)
Document how TextIOWrapper interacts with UTF-8 mode
2025-05-03 10:20:10 +09:00
Sergey Miryanov
bd2ed7c7ce
gh-91048: Chain some exceptions in _testexternalinspection.c (#132970) 2025-05-03 01:35:30 +02:00
Adam Turner
49ea8a0b2d
Lint: Use Ruff to format `Tools/build/check_warnings.py` (#133317) 2025-05-02 21:26:32 +01:00
Łukasz Langa
fac41f56d4
gh-131507: Add support for syntax highlighting in PyREPL (GH-133247)
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2025-05-02 20:22:31 +02:00
Brandt Bucher
bfcbb28223
GH-113464: Get LLVM from cpython-bin-deps on Windows (GH-133278) 2025-05-02 11:17:15 -07:00
Sergey Miryanov
a0bc0c462f
gh-100926: Move ctype's pointers cache from _pointer_type_cache to StgInfo (GH-131282)
Deprecate _pointer_type_cache and calling POINTER on a string.

Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
Co-authored-by: Jun Komoda <45822440+junkmd@users.noreply.github.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-05-02 19:06:37 +02:00
Zhikang Yan
7e7e49be78
gh-112936: Fix IDLE: no Shell menu item in single-process mode (GH-126598) 2025-05-02 20:03:32 +03:00
Paul Moore
a512905e15
gh-132995: Upgrade bundled pip to 25.1.1 (gh-132997)
* gh-132995: Upgrade bundled pip to 25.1.1
2025-05-02 17:43:13 +01:00
Ken Jin
ddac7ac59a
gh-132744: Check recursion limit in CALL_PY_GENERAL (GH-132746) 2025-05-02 17:36:29 +01:00
Petr Viktorin
987e45e632
gh-128972: Add _Py_ALIGN_AS and revert PyASCIIObject memory layout. (GH-133085)
Add `_Py_ALIGN_AS` as per C API WG vote: https://github.com/capi-workgroup/decisions/issues/61
This patch only adds it to free-threaded builds; the `#ifdef Py_GIL_DISABLED`
can be removed in the future.

Use this to revert `PyASCIIObject` memory layout for non-free-threaded builds.
The long-term plan is to deprecate the entire struct; until that happens
it's better to keep it unchanged, as courtesy to people that rely on it despite
it not being stable ABI.
2025-05-02 18:30:40 +02:00
Sergey B Kirpichev
d78768e3d6
gh-121249: fix complex formatting codes in the struct docs (note 10) (GH-133249)
This amends 85f89cb.
2025-05-02 18:27:07 +02:00
Brandt Bucher
2da48e32f6
GH-133171: Prevent combinations of --disable-gil and --enable-experimental-jit... for now (GH-133179) 2025-05-02 09:26:03 -07:00
Sergey B Kirpichev
f425509349
gh-121249: unconditionally support complex types in struct (GH-132864)
Co-authored-by: Lisandro Dalcin <dalcinl@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-05-02 18:24:52 +02:00
Hugo van Kemenade
e6c518d2eb
gh-133300: argparse: make suggest_on_error a keyword-only parameter (#133302) 2025-05-02 18:11:44 +03:00
Sam Gross
f2379535fe
gh-133164: Add PyUnstable_Object_IsUniqueReferencedTemporary C API (gh-133170)
After gh-130704, the interpreter replaces some uses of `LOAD_FAST` with
`LOAD_FAST_BORROW` which avoid incref/decrefs by "borrowing" references
on the interpreter stack when the bytecode compiler can determine that
it's safe.

This change broke some checks in C API extensions that relied on
`Py_REFCNT()` of `1` to determine if it's safe to modify an object
in-place. Objects may have a reference count of one, but still be
referenced further up the interpreter stack due to borrowing of
references.

This provides a replacement function for those checks.
`PyUnstable_Object_IsUniqueReferencedTemporary` is more conservative:
it checks that the object has a reference count of one and that it exists as a
unique strong reference in the interpreter's stack of temporary
variables in the top most frame.

See also:

* https://github.com/numpy/numpy/issues/28681

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: T. Wouters <thomas@python.org>
Co-authored-by: mpage <mpage@cs.stanford.edu>
Co-authored-by: Mark Shannon <mark@hotpy.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-05-02 13:24:57 +00:00
Hugo van Kemenade
4701ff92d7
gh-130645: Add color to argparse help (GH-132323) 2025-05-02 15:06:10 +02:00
sobolevn
ba16ba3a18
gh-133210: Fix test_descr in --without-doc-strings mode (#133294) 2025-05-02 13:04:27 +00:00
sobolevn
641253cfac
gh-132385: Fix instance error suggestions trigger potential exceptions in traceback (#132387) 2025-05-02 15:52:59 +03:00
Nybblista
20f8ed595d
gh-133279: Assert with HAS_TARGET in the codegen_addop_j function (#133280) 2025-05-02 13:52:48 +01:00
Petr Viktorin
2590774c9b
gh-133290: Use PyObject_SetAttr to set _type_ (GH-133292) 2025-05-02 14:47:07 +02:00
Yongzi Li
df8a02b1e1
Docs: delete title links in turtle.rst and typing.rst (#133283)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2025-05-02 13:15:26 +01:00
Zhikang Yan
e490c00dac
gh-130482: Add ability to specify name for tkinter.OptionMenu and tkinter.ttk.OptionMenu (GH-130502) 2025-05-02 14:38:50 +03:00
sobolevn
1e9cc3d502
gh-133197: Improve error message for incompatible string / bytes prefixes (#133242) 2025-05-02 14:28:17 +03:00
sobolevn
4912b29166
gh-133210: Fix test_pydoc in --without-doc-strings mode (#133271) 2025-05-02 13:12:24 +03:00
sobolevn
a6ddd078d0
gh-123539: Improve SyntaxError msg for import as with not a name (#123629) 2025-05-02 08:34:13 +00:00
Hugo van Kemenade
39afd290ae
gh-123299: Add missing pending removals (#133082)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2025-05-02 11:18:24 +03:00
Xuehai Pan
b8633f9aca
gh-119605: Respect follow_wrapped for __init__ and __new__ when getting class signature with inspect.signature (#132055) 2025-05-01 15:41:44 -07:00
Michael Droettboom
c14134020f
gh-133259: Show path to python.sh script on successful build (#133268)
* gh-133259: Show path to python.sh script on successful build

* wasmtime -> (generic) wasm runtime
2025-05-01 18:49:39 +00:00
Irit Katriel
a4be3bc34f
gh-133258: Fix crash in test_index (GH-133262) 2025-05-01 19:15:53 +02:00
Victor Stinner
d10bd81b45
gh-133261: Use __builtin_frame_address() on GCC 9 and older (#133269)
GCC 9 and older don't have __has_builtin(), but have
__builtin_frame_address() function.
2025-05-01 19:13:03 +02:00
Stan Ulbrych
e5e51bd7f7
gh-130197: Test pygettext --output option (GH-133041) 2025-05-01 19:30:24 +03:00
sobolevn
27e011455d
gh-133210: Fix test_inspect in --without-doc-strings mode (#133250) 2025-05-01 19:08:35 +03:00
Victor Stinner
e26bafd107
gh-133256: Add _Py_NONSTRING macro (#133257)
Fix GCC 15 compiler warnings such as:

    Modules/fcntlmodule.c:27:36: warning: initializer-string for
    array of 'char' truncates NUL terminator but destination lacks
    'nonstring' attribute (9 chars into 8 available)
    [-Wunterminated-string-initialization]
    static const char guard[GUARDSZ] = "\x00\xfa\x69\xc4\x67\xa3\x6c\x58";
2025-05-01 17:55:49 +02:00
Sergey B Kirpichev
ad2f0884b1
gh-130317: Fix test_pack_unpack_roundtrip() and add docs (#133204)
* Skip sNaN's testing in 32-bit mode.
* Drop float_set_snan() helper.
* Use memcpy() workaround for sNaN's in PyFloat_Unpack4().
* Document, that sNaN's may not be preserved by PyFloat_Pack/Unpack API.
2025-05-01 16:20:36 +02:00