gh-130959: Reject whitespace in fractions, in pure Python `fromisoformat()` (#130962)
Fix the pure Python implementation of `fromisoformat()` to reject any
non-digit characters, including whitespace, in the fractional part
of time specification. This makes the behavior consistent with the C
implementation, and prevents incorrect parsing of these fractions
(e.g. `.400 ` would be misinterpreted as `.04`).
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
(cherry picked from commit 33494b4d0d)
Co-authored-by: Michał Górny <mgorny@gentoo.org>
gh-130932: cwd cannot be removed on Solaris/Illumos (GH-131037)
(cherry picked from commit 69309a55bc)
Co-authored-by: Jakub Kulík <Kulikjak@gmail.com>
gh-117174: Add a new route in linecache to fetch interactive source code (GH-117500)
(cherry picked from commit a931a8b324)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
gh-125331: Allow the parser to activate future imports on the fly (GH-125482)
(cherry picked from commit 3bd3e09588)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
gh-124927: Fix conversion issue between coordinates and position in REPL (GH-125001)
(cherry picked from commit 6ab5c4aa05)
Co-authored-by: FeH2 <i@feh2.im>
gh-131020: py.exe launcher does not correctly detect a BOM when searching for the shebang (GH-131021)
(cherry picked from commit 36ef3bfe39)
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
gh-80421: Correct definitions of time (GH-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.
(cherry picked from commit 98fa4a49fe)
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
gh-123726: Document caveats of zipfile.Path around name sanitization (GH-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.
(cherry picked from commit a3990df612)
Co-authored-by: Affan Shaikhsurab <51104750+AffanShaikhsurab@users.noreply.github.com>
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.
(cherry picked from commit edd1eca336)
Co-authored-by: Sam Gross <colesbury@gmail.com>
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.
(cherry picked from commit 12db45211d)
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.
(cherry picked from commit 7879081198)
Co-authored-by: Diego Russo <diego.russo@arm.com>
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.
(cherry picked from commit c476410dc5)
Co-authored-by: Sam Gross <colesbury@gmail.com>
Correct function name in `Doc/extending/embedding.rst` (GH-127539)
(cherry picked from commit e5527f2cdd)
Co-authored-by: Boris Verkhovskiy <boris.verk@gmail.com>
gh-130932: Fix incorrect exception handling in _PyModule_IsPossiblyShadowing (GH-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.
```
(cherry picked from commit 0a9ae5ed48)
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
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.
(cherry picked from commit 2905690a91)
Co-authored-by: Sam Gross <colesbury@gmail.com>
Update links from typing.readthedocs.io to typing.python.org (GH-130877)
(cherry picked from commit 4f6218959e)
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
gh-116742: Fix subprocess test_check_output_timeout() (GH-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.
(cherry picked from commit 67a942d427)
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 90130807d9)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
gh-130547: Fix race between dict_dealloc and split_keys_entry_added (gh-130778)
(cherry picked from commit 80e6d3ec49)
Co-authored-by: Donghee Na <donghee.na@python.org>
This avoids a case where the interpreter's queue of memory to be freed
could grow rapidly if there are many short lived threads.
(cherry picked from commit 2f6e0e9f70)
gh-130730: Fix multiprocessing test_active_children() (GH-130837)
Replace a sleep with an event: sleep is not a reliable
synchronization primitive.
(cherry picked from commit 3dd3675492)
Co-authored-by: Victor Stinner <vstinner@python.org>
gh-130727: Retry test_wmi on TimeoutError (GH-130832)
Use sleeping_retry() in test_wmi to retry multiple times on
TimeoutError. Wait up to LONG_TIMEOUT seconds (5 minutes by default).
(cherry picked from commit f67ff9e820)
Co-authored-by: Victor Stinner <vstinner@python.org>
gh-129567: Add a note to `typing.TypedDict` docs about name mangling (GH-130233)
(cherry picked from commit 63ffb406bb)
Co-authored-by: sobolevn <mail@sobolevn.me>
gh-130737: Fix multiprocessing test_notify() (GH-130797)
Replace hardcoded delay (100 ms) with a loop awaiting until a
condition is true: replace assertReturnsIfImplemented() with
assertReachesEventually().
Use sleeping_retry() in assertReachesEventually() to tolerate slow
buildbots and raise an exception on timeout (30 seconds).
(cherry picked from commit 8a64a62002)
Co-authored-by: Victor Stinner <vstinner@python.org>
gh-128388: pyrepl on Windows: add meta and ctrl+arrow keybindings (GH-128389)
Fix `Lib/_pyrepl/windows_console.py` to support more keybindings, like the
`Ctrl`+`←` and `Ctrl`+`→` word-skipping keybindings and those with meta (i.e. Alt),
e.g. to `kill-word` or `backward-kill-word`.
Specifics: if Ctrl is pressed, emit "ctrl left" and "ctrl right" instead of just "left" or
"right," and if Meta/Alt is pressed, emit the special key code for meta before
emitting the other key that was pressed.
(cherry picked from commit 688f3a0d4b)
Co-authored-by: Paulie Peña <203125+paulie4@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
gh-130379: Fix incorrect zipapp logic to avoid including the target in itself (gh-130509)
(cherry picked from commit 64ccbbbf36)
Co-authored-by: Paul Moore <p.f.moore@gmail.com>
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.
(cherry picked from commit b26286ca49)
Co-authored-by: Yuki Kobayashi <drsuaimqjgar@gmail.com>
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` (this caused some
build failures when compiling CPython with `zig cc`).
(cherry-picked from commit 214562ed4d)
---------
Co-authored-by: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
gh-127667: fix memory leaks in `hashlib` (GH-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.
(cherry-picked from commit 097846502b)
gh-130637: Add validation for numeric response data in `stat()` method (GH-130646)
(cherry picked from commit a42168d316)
Co-authored-by: Kanishk Pachauri <itskanishkp.py@gmail.com>
Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
gh-128481: indicate that the default value for `FrameSummary.end_lineno` changed in 3.13 (GH-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.
(cherry picked from commit c6513f7a62)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Add link in the `importlib.metadata.version()` docs (GH-130739)
Link the specification for the returned data makes it clearer what this is
and what the format of the version string can be.
(cherry picked from commit c71e55869e)
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
* gh-128481: Improve documentation for `traceback.FrameSummary` (GH-128484)
Complete the `traceback.FrameSummary` signature and add missing
documentation for the `colno` and `end_{col,line}no` attributes.
(cherry picked from commit 051f0e5683)
Co-authored-by: Damien <81557462+Damien-Chen@users.noreply.github.com>
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 cfa0b1dc37.
(cherry picked from commit 5221d9ce0e)
Co-authored-by: Sam Gross <colesbury@gmail.com>