Commit Graph

122872 Commits

Author SHA1 Message Date
satori1995 9585a1a2a2
GH-121439: Allow PyTupleObjects with an ob_size of 20 in the free_list to be reused (gh-121428) 2024-07-10 07:48:25 +00:00
Brett Cannon f62161837e
GH-121521: Detect when wasmtime is not installed in `Tools/wasm/wasi.py` (GH-121522) 2024-07-09 15:08:01 -07:00
Brett Cannon 8020946814
GH-120372: Switch to wasmtime 22 (GH-121523)
Along the way, make the cache key in GitHub Actions for `config.cache` be more robust in the face of potential env var changes from `Tools/wasm/wasi.py`.
2024-07-09 15:02:25 -07:00
Sam Gross 04397434aa
gh-117657: Skip test when running under TSan (GH-121549)
The ProcessPoolForkserver combined with resource_tracker starts a thread
after forking, which is not supported by TSan.

Also skip test_multiprocessing_fork for the same reason
2024-07-09 14:12:45 -07:00
Sam Gross 9c08f40a61
gh-117657: Fix TSAN races in setobject.c (#121511)
The `used` field must be written using atomic stores because `set_len`
and iterators may access the field concurrently without holding the
per-object lock.
2024-07-09 12:11:43 -04:00
sobolevn 649d5b6d7b
gh-121533: Improve `PyCell_[Get,Set]` docs: mention the exceptions (#121534)
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-07-09 18:47:35 +03:00
Rafael Fontenelle 9ba2a4638d
Docs: fix typo and duplicate word in configure.rst (#121410) 2024-07-09 14:24:37 +02:00
Mark Shannon bf8686e1ea
GH-118926: Better distinguish between pointer and arrays in interpreter generator (GH-121496) 2024-07-09 11:33:56 +01:00
AN Long facf9862da
gh-121333: Clarify what is the default executor for asyncio.run_in_executor (#121335)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2024-07-09 14:52:07 +05:30
Eric Snow 15d48aea02
gh-121110: Fix Extension Module Tests Under Py_TRACE_REFS Builds (gh-121503)
The change in gh-118157 (b2cd54a) should have also updated clear_singlephase_extension() but didn't.  We fix that here.  Note that clear_singlephase_extension() (AKA _PyImport_ClearExtension()) is only used in tests.
2024-07-08 15:10:00 -06:00
Sam Gross 218edaf0ff
gh-121018: Fix typo in NEWS entry (#121510) 2024-07-08 16:44:56 -04:00
Hugo van Kemenade 006b53a42f
NEWS: Fix Sphinx warnings and increase threshold for new news nits (#121482)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-07-08 14:30:05 -06:00
Irit Katriel 2be37ec8e2
gh-121404: remove direct accesses to u_private from codegen functions (#121500) 2024-07-08 21:02:01 +01:00
Sam Gross 1d3cf79a50
gh-121368: Fix seq lock memory ordering in _PyType_Lookup (#121388)
The `_PySeqLock_EndRead` function needs an acquire fence to ensure that
the load of the sequence happens after any loads within the read side
critical section. The missing fence can trigger bugs on macOS arm64.

Additionally, we need a release fence in `_PySeqLock_LockWrite` to
ensure that the sequence update is visible before any modifications to
the cache entry.
2024-07-08 14:52:07 -04:00
Marc Mueller 31873bea47
gh-121487: Fix deprecation warning for ATOMIC_VAR_INIT in mimalloc (gh-121488) 2024-07-08 14:32:30 -04:00
Barney Gale db00fee3a2
GH-119169: Simplify `os.walk()` exception handling (#121435)
Handle errors from `os.scandir()` and `ScandirIterator` similarly, which
lets us loop over directory entries with `for`.
2024-07-08 17:41:01 +01:00
Max Muoto 5289550b33
gh-121374: Correct docstrings in `_interpchannels` (gh-121418) 2024-07-08 10:32:17 -06:00
Mark Shannon 8ad6067bd4
GH-121012: Set index to -1 when list iterators become exhausted in tier 2 (GH-121483) 2024-07-08 14:20:13 +01:00
Michael Droettboom d69529d31c
gh-121338: Remove #pragma optimize (#121340) 2024-07-08 08:48:42 -04:00
Alyssa Coghlan 59be79ae60
gh-108297: Update crashers README for test_crashers removal (#121475)
Update Lib/test/crashers/README for test_crashers removal
2024-07-08 05:24:31 +00:00
CBerJun bf74db731b
gh-121461: Fix os.path.normpath documentation indentation (#121466) 2024-07-08 03:51:03 +00:00
Marc Mueller 5aa1e60e0c
gh-121467: Fix makefile to include mimalloc headers (#121469) 2024-07-07 17:45:21 -07:00
Shantanu c8669489d4
Fix sphinx reference target (#121470)
This was introduced in https://github.com/python/cpython/pull/121164
and appears to be causing test failures on main
2024-07-07 17:18:28 -07:00
Barney Gale b765e4adf8
GH-73991: Fix "Operation not supported" on Fedora buildbot. (#121444)
Follow-up to #120806. Use `os_helper.skip_unless_xattr` to skip testing
xattr preservation when unsupported.
2024-07-07 17:27:52 +01:00
Ken Jin 3bddd07c2a
Add Fidget-Spinner to stackrefs CODEOWNERS (GH-121455) 2024-07-07 21:45:06 +08:00
Sergey B Kirpichev 68e279b37a
gh-121351: Skip test_not_wiping_history_file() if no readline (#121422) 2024-07-07 00:53:54 +02:00
Kirill Podoprigora 114389470e
gh-119909: Fix ``NameError`` in ``asyncio`` REPL (#121341) 2024-07-06 16:49:33 -04:00
Kirill Podoprigora 53e12025cd
Regen ``Doc/requirements-oldest-sphinx.txt`` (#121437)
regen dependencies
2024-07-06 20:04:41 +02:00
Bénédikt Tran ada964fba0
[docs] fix a Sphinx directive in `c-api/object.rst` (#121430) 2024-07-06 19:57:26 +02:00
Barney Gale 88fc0655d4
GH-73991: Support preserving metadata in `pathlib.Path.copy()` (#120806)
Add *preserve_metadata* keyword-only argument to `pathlib.Path.copy()`, defaulting to false. When set to true, we copy timestamps, permissions, extended attributes and flags where available, like `shutil.copystat()`. The argument has no effect on Windows, where metadata is always copied.

Internally (in the pathlib ABCs), path types gain `_readable_metadata` and `_writable_metadata` attributes. These sets of strings describe what kinds of metadata can be retrieved and stored. We take an intersection of `source._readable_metadata` and `target._writable_metadata` to minimise reads/writes. A new `_read_metadata()` method accepts a set of metadata keys and returns a dict with those keys, and a new `_write_metadata()` method accepts a dict of metadata. We *might* make these public in future, but it's hard to justify while the ABCs are still private.
2024-07-06 17:18:39 +01:00
Victor Stinner 6239d41527
gh-121359: Run test_pyrepl in isolated mode (#121414)
run_repl() now pass the -I option (isolated mode) to Python if the
'env' parameter is not set.
2024-07-05 22:30:08 +02:00
Yuxin Wu 892e3a1b70
Update example of str.split, bytes.split (#121287)
In `{str,bytes}.strip(chars)`, multiple characters are not treated as a
prefix/suffix, but as individual characters. This may make users confuse
whether `split` has similar behavior.
Users may incorrectly expect that
`'Good morning, John.'.split(', .') == ['Good', 'morning', 'John']`

Adding a bit of clarification in the doc.

Co-authored-by: Yuxin Wu <ppwwyyxx@users.noreply.github.com>
2024-07-05 13:08:29 -07:00
Serhiy Storchaka 8ecb8962e3
gh-121288: Make error message for index() methods consistent (GH-121395)
Make error message for index() methods consistent

Remove the repr of the searched value (which can be arbitrary large)
from ValueError messages for list.index(), range.index(), deque.index(),
deque.remove() and ShareableList.index().  Make the error messages
consistent with error messages for other index() and remove()
methods.
2024-07-05 10:50:45 -07:00
AraHaan 0e77540d86
Fixed regenerating files in a checkout path with spaces (GH-121384) 2024-07-05 17:33:52 +01:00
Sergey B Kirpichev d4faa7bd32
gh-121149: improve accuracy of builtin sum() for complex inputs (gh-121176) 2024-07-05 10:01:05 -05:00
Serhiy Storchaka cecd6012b0
gh-59110: Fix a debug output for implicit directories (GH-121375) 2024-07-05 11:44:07 +03:00
Josh Brobst db39bc42f9
gh-121390: tracemalloc: Fix tracebacks memory leak (#121391)
The tracemalloc_tracebacks hash table has traceback keys and NULL
values, but its destructors do not reflect this -- key_destroy_func is
NULL while value_destroy_func is raw_free. Swap these to free the
traceback keys instead.
2024-07-05 08:39:48 +02:00
Ali Tavallaie cb688bab08
gh-90437: Fix __main__.py documentation wording (GH-116309)
Co-authored-by: Éric <merwok@netwok.org>
Co-authored-by: Frank Dana <ferdnyc@gmail.com>
2024-07-04 15:49:14 -07:00
Victor Stinner 5f660e8e2c
gh-121084: Fix test_typing random leaks (#121360)
Clear typing ABC caches when running tests for refleaks (-R option):
call _abc_caches_clear() on typing abstract classes and their
subclasses.
2024-07-04 19:38:30 +02:00
Gabriele N. Tornetta f5c8d67de6
gh-106597: Remove unnecessary CFrame offsets (#121369) 2024-07-04 17:28:23 +00:00
Serhiy Storchaka 17d5b9df10
gh-59110: zipimport: support namespace packages when no directory entry exists (GH-121233) 2024-07-04 15:04:24 +00:00
Nice Zombies db1729143d
gh-118507: Amend news entry to mention ntpath.isfile bugfix (GH-120817) 2024-07-04 15:56:06 +01:00
Irit Katriel 67a05de17c
gh-121272: move async for/with validation from compiler to symtable (#121361) 2024-07-04 14:47:21 +01:00
Jongbum Won 715ec630dd
gh-121355: Fix incorrect word in simple_stmts.rst (#121356) 2024-07-04 06:34:34 -07:00
Cody Maloney 06a1c3fb24
gh-120754: Update estimated_size in C truncate (#121357)
Sometimes a large file is truncated (test_largefile). While
estimated_size is used as a estimate (the read will stil get the number
of bytes in the file), that it is much larger than the actual size of
data can result in a significant over allocation and sometimes lead to
a MemoryError / running out of memory.

This brings the C implementation to match the Python _pyio
implementation.
2024-07-04 12:59:18 +00:00
Irit Katriel 19d1e43e43
gh-121352: use _Py_SourceLocation in symtable (#121353) 2024-07-04 11:28:44 +01:00
Cody Maloney 2f5f19e783
gh-120754: Reduce system calls in full-file FileIO.readall() case (#120755)
This reduces the system call count of a simple program[0] that reads all
the `.rst` files in Doc by over 10% (5706 -> 4734 system calls on my
linux system, 5813 -> 4875 on my macOS)

This reduces the number of `fstat()` calls always and seek calls most
the time. Stat was always called twice, once at open (to error early on
directories), and a second time to get the size of the file to be able
to read the whole file in one read. Now the size is cached with the
first call.

The code keeps an optimization that if the user had previously read a
lot of data, the current position is subtracted from the number of bytes
to read. That is somewhat expensive so only do it on larger files,
otherwise just try and read the extra bytes and resize the PyBytes as
needeed.

I built a little test program to validate the behavior + assumptions
around relative costs and then ran it under `strace` to get a log of the
system calls. Full samples below[1].

After the changes, this is everything in one `filename.read_text()`:

```python3
openat(AT_FDCWD, "cpython/Doc/howto/clinic.rst", O_RDONLY|O_CLOEXEC) = 3`
fstat(3, {st_mode=S_IFREG|0644, st_size=343, ...}) = 0`
ioctl(3, TCGETS, 0x7ffdfac04b40)        = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR)                   = 0
read(3, ":orphan:\n\n.. This page is retain"..., 344) = 343
read(3, "", 1)                          = 0
close(3)                                = 0
```

This does make some tradeoffs
1. If the file size changes between open() and readall(), this will
still get all the data but might have more read calls.
2. I experimented with avoiding the stat + cached result for small files
in general, but on my dev workstation at least that tended to reduce
performance compared to using the fstat().

[0]

```python3
from pathlib import Path

nlines = []
for filename in Path("cpython/Doc").glob("**/*.rst"):
    nlines.append(len(filename.read_text()))
```

[1]
Before small file:

```
openat(AT_FDCWD, "cpython/Doc/howto/clinic.rst", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=343, ...}) = 0
ioctl(3, TCGETS, 0x7ffe52525930)        = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR)                   = 0
lseek(3, 0, SEEK_CUR)                   = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=343, ...}) = 0
read(3, ":orphan:\n\n.. This page is retain"..., 344) = 343
read(3, "", 1)                          = 0
close(3)                                = 0
```

After small file:

```
openat(AT_FDCWD, "cpython/Doc/howto/clinic.rst", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=343, ...}) = 0
ioctl(3, TCGETS, 0x7ffdfac04b40)        = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR)                   = 0
read(3, ":orphan:\n\n.. This page is retain"..., 344) = 343
read(3, "", 1)                          = 0
close(3)                                = 0
```

Before large file:

```
openat(AT_FDCWD, "cpython/Doc/c-api/typeobj.rst", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=133104, ...}) = 0
ioctl(3, TCGETS, 0x7ffe52525930)        = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR)                   = 0
lseek(3, 0, SEEK_CUR)                   = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=133104, ...}) = 0
read(3, ".. highlight:: c\n\n.. _type-struc"..., 133105) = 133104
read(3, "", 1)                          = 0
close(3)                                = 0
```

After large file:

```
openat(AT_FDCWD, "cpython/Doc/c-api/typeobj.rst", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=133104, ...}) = 0
ioctl(3, TCGETS, 0x7ffdfac04b40)        = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR)                   = 0
lseek(3, 0, SEEK_CUR)                   = 0
read(3, ".. highlight:: c\n\n.. _type-struc"..., 133105) = 133104
read(3, "", 1)                          = 0
close(3)                                = 0
```

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-07-04 09:17:00 +02:00
Bénédikt Tran 9728ead361
gh-121141: add support for `copy.replace` to AST nodes (#121162) 2024-07-03 20:10:54 -07:00
Chris Markiewicz 94f50f8ee6
gh-117983: Defer import of threading for lazy module loading (#120233)
As noted in gh-117983, the import importlib.util can be triggered at
interpreter startup under some circumstances, so adding threading makes
it a potentially obligatory load.
Lazy loading is not used in the stdlib, so this removes an unnecessary
load for the majority of users and slightly increases the cost of the
first lazily loaded module.

An obligatory threading load breaks gevent, which monkeypatches the
stdlib. Although unsupported, there doesn't seem to be an offsetting
benefit to breaking their use case.

For reference, here are benchmarks for the current main branch:

```
❯ hyperfine -w 8 './python -c "import importlib.util"'
Benchmark 1: ./python -c "import importlib.util"
  Time (mean ± σ):       9.7 ms ±   0.7 ms    [User: 7.7 ms, System: 1.8 ms]
  Range (min … max):     8.4 ms …  13.1 ms    313 runs
```

And with this patch:

```
❯ hyperfine -w 8 './python -c "import importlib.util"'
Benchmark 1: ./python -c "import importlib.util"
  Time (mean ± σ):       8.4 ms ±   0.7 ms    [User: 6.8 ms, System: 1.4 ms]
  Range (min … max):     7.2 ms …  11.7 ms    352 runs
```

Compare to:

```
❯ hyperfine -w 8 './python -c pass'
Benchmark 1: ./python -c pass
  Time (mean ± σ):       7.6 ms ±   0.6 ms    [User: 5.9 ms, System: 1.6 ms]
  Range (min … max):     6.7 ms …  11.3 ms    390 runs
```

This roughly halves the import time of importlib.util.
2024-07-03 20:50:46 +00:00
Tian Gao e245ed7d1e
gh-118714: Make the pdb post-mortem restart/quit behavior more reasonable (#118725) 2024-07-03 11:30:20 -07:00