Commit Graph

52975 Commits

Author SHA1 Message Date
Serhiy Storchaka 94bee45dee
gh-84978: Add float.from_number() and complex.from_number() (GH-26827)
They are alternate constructors which only accept numbers
(including objects with special methods __float__, __complex__
and __index__), but not strings.
2024-07-15 16:07:00 +00:00
Dominic H 8303d32ff5
gh-117765: Improve documentation for `mocker.patch.dict` (#121755) 2024-07-15 07:14:17 +00:00
Kumar Aditya 48042c52a6
fix outdated comments in asyncio (#121783) 2024-07-15 05:59:19 +00:00
Jelle Zijlstra 50eec501fe
gh-57141: Make shallow argument to filecmp.dircmp keyword-only (#121767)
It is our general practice to make new optional parameters keyword-only,
even if the existing parameters are all positional-or-keyword. Passing
this parameter as positional would look confusing and could be error-prone
if additional parameters are added in the future.
2024-07-14 15:53:32 -07:00
Tomas R 901ea411bf
gh-121708: Improve test coverage for `unittest.util` (GH-121713) 2024-07-14 10:08:47 +02:00
Tian Gao c0af6d4ff1
gh-121651: Fix pdb header test (#121724) 2024-07-13 11:55:22 -07:00
Milan Oberkirch a183474293
gh-121711: Set `-m asyncio` return_code to 1 for ENOTTY (#121714)
Set return_code to 1 for ENOTTY
2024-07-13 17:17:24 +02:00
Gregor 178e44de8f
gh-121657: Display correct error message for yield from outside of a function (GH-121680)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-07-13 17:14:39 +02:00
Sam Gross abc3aeebdb
gh-121605: Increase timeout in test_pyrepl.run_repl (#121606)
We also need to close the `slave_fd` earlier so that reading from
`master_fd` won't block forever when the subprocess finishes.
2024-07-13 15:54:28 +02:00
Tomas R 0a26aa5007
gh-121671: Increase test coverage of `ast.get_docstring` (GH-121674)
Increase test coverage for `ast.get_docstring`
2024-07-13 14:59:15 +02:00
Pablo Galindo Salgado 4b9e10d0ea
gh-121499: Fix multi-line history rendering in the REPL (#121531)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
2024-07-13 12:54:10 +02:00
Marta Gómez Macías e745996b2d
gh-121609: Fix pasting of characters containing unicode character joiner (#121667) 2024-07-13 10:44:18 +00:00
Bas Bloemsaat 0759cecd9d
gh-99242 Ignore error when running regression tests under certain conditions. (GH-121663)
Co-Authored-By: Kevin Diem <kg.diem@gmail.com>
2024-07-13 11:52:08 +02:00
Pablo Galindo Salgado 4e36dd7d87
gh-121497: Make Pyrepl respect correctly the history with input hook set (#121498) 2024-07-13 09:42:14 +00:00
Zachary Ware dc03ce797a
gh-95144: Improve error message of `... in None` (GH-119888) 2024-07-12 16:34:17 +00:00
Sam Gross e8c91d90ba
gh-121103: Put free-threaded libraries in `lib/python3.14t` (#121293)
On POSIX systems, excluding macOS framework installs, the lib directory
for the free-threaded build now includes a "t" suffix to avoid conflicts
with a co-located default build installation.
2024-07-11 16:21:37 -04:00
Eric Snow 5250a03133
gh-117482: Fix Builtin Types Slot Wrappers (gh-121602)
When builtin static types are initialized for a subinterpreter, various "tp" slots have already been inherited (for the main interpreter).  This was interfering with the logic in add_operators() (in Objects/typeobject.c), causing a wrapper to get created when it shouldn't.  This change fixes that by preserving the original data from the static type struct and checking that.
2024-07-11 20:20:14 +00:00
Jelle Zijlstra 58e8cf2bb6
gh-121332: Make AST node constructor check _attributes instead of hardcoding attributes (#121334) 2024-07-11 14:34:53 +00:00
Tian Gao 690b9355e0
gh-121450: Make inline breakpoints use the most recent pdb instance (#121451) 2024-07-10 19:54:27 -07:00
Eric Snow 35a67e36aa
gh-121596: Fix Sharing Interpreter Channels (gh-121597)
This fixes a mistake in gh-113012 and adds a test that verifies the fix.
2024-07-10 21:31:09 +00:00
Ken Jin 3bfc9c831a
gh-120198: Stop the world when setting __class__ on free-threaded build (GH-120672) 2024-07-11 02:02:08 +08:00
Sam Gross af9f6de6ea
gh-107851: Fix spurious failures in fcntl eintr tests (#121556)
On heavily loaded machines, the subprocess may finish its sleep before
the parent process manages to synchronize with it via a failed lock.

This leads to errors like:

  Exception: failed to sync child in 300.3 sec

Use pipes instead to mutually synchronize between parent and child.
2024-07-10 10:36:52 -04:00
sobolevn e2822360da
gh-121571: Do not use `EnvironmentError` in tests, use `OSError` instead (#121572) 2024-07-10 13:11:46 +03:00
Serhiy Storchaka 22a0bdbf9a
Improve zipimport tests (GH-121535) 2024-07-10 11:29:03 +03: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
Mark Shannon bf8686e1ea
GH-118926: Better distinguish between pointer and arrays in interpreter generator (GH-121496) 2024-07-09 11:33:56 +01:00
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
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
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
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
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
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
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
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
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
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
Serhiy Storchaka 17d5b9df10
gh-59110: zipimport: support namespace packages when no directory entry exists (GH-121233) 2024-07-04 15:04:24 +00: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
Max Muoto 7c66906802
gh-121300: Add `replace` to `copy.__all__` (#121302) 2024-07-03 20:33:56 +05:30
Sergey B Kirpichev afee76b6eb
gh-121245: a regression test for site.register_readline() (#121259) 2024-07-03 11:45:43 +01:00
Sergey B Kirpichev 51c4a324c0
gh-61103: Support float and long double complex types in ctypes module (#121248)
This amends 6988ff02a5: memory allocation for
stginfo->ffi_type_pointer.elements in PyCSimpleType_init() should be
more generic (perhaps someday fmt->pffi_type->elements will be not a
two-elements array).

It should finally resolve #61103.

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-07-03 11:08:11 +02:00
Serhiy Storchaka ff5806c78e
gh-121027: Make the functools.partial object a method descriptor (GH-121089)
Co-authored-by: d.grigonis <dgrigonis@users.noreply.github.com>
2024-07-03 09:02:15 +03:00
Barney Gale f09d184821
GH-73991: Support copying directory symlinks on older Windows (#120807)
Check for `ERROR_INVALID_PARAMETER` when calling `_winapi.CopyFile2()` and
raise `UnsupportedOperation`. In `Path.copy()`, handle this exception and
fall back to the `PathBase.copy()` implementation.
2024-07-03 04:30:29 +01:00
Bénédikt Tran 15232a0819
gh-121210: handle nodes with missing attributes/fields in `ast.compare` (#121211) 2024-07-02 16:23:17 +05:30