Commit graph

51117 commits

Author SHA1 Message Date
Sam Gross cf6f23b0e3
gh-88402: Add new sysconfig variables on Windows (GH-110049)
Co-authored-by: Filipe Laíns <filipe.lains@gmail.com>
2023-10-04 22:50:29 +00:00
Xuehai Pan 3bbe3b7c82
gh-110222: Add support of PyStructSequence in copy.replace() (GH-110223) 2023-10-04 19:47:41 +03:00
Xuehai Pan 9561648f4a
gh-110235: Raise TypeError for duplicate/unknown fields in PyStructSequence constructor (GH-110258) 2023-10-04 19:44:17 +03:00
Hugo van Kemenade d8c00d2a60
Lint: Remove files that no longer fail to parse or with F811 (#110356) 2023-10-04 16:11:32 +03:00
Serhiy Storchaka 254e30c487
gh-109151: Enable readline in the sqlite3 CLI (GH-109152) 2023-10-04 14:16:44 +03:00
Nikita Sobolev e9f2352b7b
gh-110332: Remove mentions of random.WichmannHill from test_zlib (#110334) 2023-10-04 12:51:45 +02:00
Victor Stinner efd8c7a7c9
gh-109276: regrtest: shorter list of resources (#110326) 2023-10-04 09:39:50 +00:00
Victor Stinner 1337765225
gh-110335: asyncio test_unix_events cleans multiprocessing (#110336)
test_unix_events tests using the multiprocessing module now call
multiprocessing.util._cleanup_tests().
2023-10-04 09:19:08 +00:00
Victor Stinner 1de9406f91
gh-110166: Fix gdb CFunctionFullTests on ppc64le clang build (#110331)
CFunctionFullTests now also runs "bt" command before "py-bt-full",
similar to CFunctionTests which also runs "bt" command before
"py-bt". So test_gdb can skip the test if patterns like "?? ()" are
found in the gdb output.
2023-10-04 08:57:35 +00:00
Nikita Sobolev 1465386720
gh-110171: libregrtest always sets random.seed (#110172) 2023-10-04 06:42:12 +00:00
Serhiy Storchaka 5b9a3fd6a0
gh-110273: dataclasses.replace() now raise TypeError for all invalid arguments (GH-110274)
dataclasses.replace() now raises TypeError instead of ValueError if
specify keyword argument for a field declared with init=False or miss keyword
argument for required InitVar field.
2023-10-04 09:20:14 +03:00
Alex Waygood bfe7e72522
gh-109653: Defer importing warnings in several modules (#110286) 2023-10-04 06:09:43 +01:00
Eric Snow 269005e784
gh-110300: Fix Refleaks in test_interpreters and test__xxinterpchannels (gh-110318) 2023-10-04 00:36:50 +00:00
elfstrom a376a72bd9
gh-109917: Fix test instability in test_concurrent_futures (#110306)
The test had an instability issue due to the ordering of the dummy
queue operation and the real wakeup pipe operations. Both primitives
are thread safe but not done atomically as a single update and may
interleave arbitrarily. With the old order of operations this can lead
to an incorrect state where the dummy queue is full but the wakeup
pipe is empty. By swapping the order in clear() I think this can no
longer happen in any possible operation interleaving (famous last
words).
2023-10-03 22:59:49 +01:00
Guido van Rossum d67edcf0b3
gh-109979: Auto-generate the target for DEOPT_IF() (#110193)
In Python/bytecodes.c, you now write
```
    DEOPT_IF(condition);
```
The code generator expands this to
```
    DEOPT_IF(condition, opcode);
```
where `opcode` is the name of the unspecialized instruction.
This works inside macro expansions too.

**CAVEAT:** The entire `DEOPT_IF(condition)` statement must be on a single line.
If it isn't, the substitution will fail; an error will be printed by the code generator
and the C compiler will report some errors.
2023-10-03 10:13:50 -07:00
Eric Snow f5198b09e1
gh-109860: Use a New Thread State When Switching Interpreters, When Necessary (gh-110245)
In a few places we switch to another interpreter without knowing if it has a thread state associated with the current thread.  For the main interpreter there wasn't much of a problem, but for subinterpreters we were *mostly* okay re-using the tstate created with the interpreter (located via PyInterpreterState_ThreadHead()).  There was a good chance that tstate wasn't actually in use by another thread.

However, there are no guarantees of that.  Furthermore, re-using an already used tstate is currently fragile.  To address this, now we create a new thread state in each of those places and use it.

One consequence of this change is that PyInterpreterState_ThreadHead() may not return NULL (though that won't happen for the main interpreter).
2023-10-03 09:20:48 -06:00
Xuehai Pan 2d4865d775
gh-110267: Add tests for pickling and copying PyStructSequence objects (GH-110272) 2023-10-03 17:09:49 +03:00
Alex Waygood dddc757303
gh-110276: Run test_str, not test_unicode, as part of the PGO build (#110277)
`test_unicode` does not exist
2023-10-03 13:54:21 +01:00
Nikita Sobolev bb2e96f6f4
gh-109956: Also test typing.NamedTuple with copy.replace() (GH-109957) 2023-10-03 14:13:13 +03:00
Guido van Rossum 6678ef41d2
Add --inline-caches flag to dis command line (#110249) 2023-10-03 00:49:34 +00:00
Alex Waygood 21a6263020
gh-109653: Reduce the import time of random by 60% (#110221) 2023-10-02 22:56:31 +00:00
Eric Snow a8f5dab58d
gh-76785: Module-level Fixes for test.support.interpreters (gh-110236)
* add RecvChannel.close() and SendChannel.close()
* make RecvChannel and SendChannel shareable
* expose ChannelEmptyError and ChannelNotEmptyError
2023-10-02 20:47:41 +00:00
Alex Waygood 014aacda62
Enable ruff on Lib/test/test_typing.py (#110179) 2023-10-02 14:13:48 -06:00
Eric Snow 1dd9dee45d
gh-105716: Support Background Threads in Subinterpreters Consistently (gh-109921)
The existence of background threads running on a subinterpreter was preventing interpreters from getting properly destroyed, as well as impacting the ability to run the interpreter again. It also affected how we wait for non-daemon threads to finish.

We add PyInterpreterState.threads.main, with some internal C-API functions.
2023-10-02 20:12:12 +00:00
Eric Snow a040a32ea2
gh-109853: Fix sys.path[0] For Subinterpreters (gh-109994)
This change makes sure sys.path[0] is set properly for subinterpreters. Before, it wasn't getting set at all. This PR does not address the broader concerns from gh-109853.
2023-10-02 19:59:05 +00:00
Victor Stinner 4d0d1c3866
gh-110014: Remove PY_TIMEOUT_MAX from limited C API (#110217)
If the timeout is greater than PY_TIMEOUT_MAX,
PyThread_acquire_lock_timed() uses a timeout of PY_TIMEOUT_MAX
microseconds, which is around 280.6 years. This case is unlikely and
limiting a timeout to 280.6 years sounds like a reasonable trade-off.

The constant PY_TIMEOUT_MAX is not used in PyPI top 5,000 projects.
2023-10-02 18:07:56 +02:00
Jelle Zijlstra 732ad44cec
gh-110178: Use fewer weakrefs in test_typing.py (#110194)
Confirmed that without the C changes from #108517, this test still segfaults with only 10 weakrefs.
2023-10-02 08:03:53 -07:00
Steve Dower 1b3bc610fd
gh-83180: Made launcher treat shebang 'python' tags as low priority so that active virtual environments are preferred (GH-108101) 2023-10-02 12:22:55 +00:00
AN Long 44b1e4ea48
gh-108963: using random to generate unique string in sys.intern test (#109491) 2023-10-02 13:07:56 +02:00
Charles Machalow 29b875bb93
gh-109590: Update shutil.which on Windows to prefer a PATHEXT extension on executable files (GH-109995)
The default arguments for shutil.which() request an executable file, but extensionless files are not executable on Windows and should be ignored.
2023-10-02 09:27:30 +01:00
Victor Stinner 65c285062c
gh-110164: regrtest disables random if SOURCE_DATE_EPOCH (#110168)
If the SOURCE_DATE_EPOCH environment variable is defined, regrtest
now disables randomization of tests.
2023-10-01 22:41:03 +02:00
Alex Waygood d642c5bbf5
gh-110180: Remove unused _PickleUsingNameMixin class from typing (#110181) 2023-10-01 16:28:02 +01:00
Barney Gale 15de493395
GH-107465: Add pathlib.Path.from_uri() classmethod. (#107640)
This method supports file URIs (including variants) as described in RFC 8089, such as URIs generated by `pathlib.Path.as_uri()` and `urllib.request.pathname2url()`.

The method is added to `Path` rather than `PurePath` because it uses `os.fsdecode()`, and so its results vary from system to system. I intend to deprecate `PurePath.as_uri()` and move it to `Path` for the same reason.

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2023-10-01 16:14:02 +01:00
Nikita Sobolev 06faa9a39b
gh-110160: Fix flaky test_find_periodic_pattern in string_tests (#110170) 2023-10-01 16:20:01 +02:00
Raymond Hettinger 62405c7867
gh-110150: Fix base case handling in quantiles() (gh-110151) 2023-09-30 23:35:54 -05:00
Victor Stinner a46e960768
gh-109649: Use os.process_cpu_count() (#110165)
Replace os.cpu_count() with os.process_cpu_count() in modules:

* compileall
* concurrent.futures
* multiprocessing

Replace os.cpu_count() with os.process_cpu_count() in programs:

* _decimal deccheck.py test
* freeze.py
* multissltests.py
* python -m test (regrtest)
* wasm_build.py

Other changes:

* test.pythoninfo logs os.process_cpu_count().
* regrtest gets os.process_cpu_count() / os.cpu_count() in headers.
2023-10-01 03:14:57 +02:00
Victor Stinner 53eb9a676f
gh-110152: regrtest handles cross compilation and HOSTRUNNER (#110156)
* _add_python_opts() now handles cross compilation and HOSTRUNNER.
* display_header() now tells if Python is cross-compiled, display
  HOSTRUNNER, and get the host platform.
* Remove Tools/scripts/run_tests.py script.
* Remove "make hostrunnertest": use "make buildbottest"
  or "make test" instead.
2023-09-30 22:37:23 +00:00
Victor Stinner c81521020d
gh-109649: Add os.process_cpu_count() function (#109907)
* Refactor os_sched_getaffinity_impl(): move variable definitions to
  their first assignment.
* Fix test_posix.test_sched_getaffinity(): restore the old CPU mask
  when the test completes!
* Doc: Specify that os.cpu_count() counts *logicial* CPUs.
* Doc: Specify that os.sched_getaffinity(0) is related to the calling
  thread.
2023-10-01 00:12:51 +02:00
Victor Stinner 2c234196ea
gh-109276: regrtest: add WORKER_FAILED state (#110148)
Rename WORKER_ERROR to WORKER_BUG. Add WORKER_FAILED state: it does
not stop the manager, whereas WORKER_BUG does.

Change also TestResults.display_result() order: display failed tests
at the end, the important important information.

WorkerThread now tries to get the signal name for negative exit code.
2023-09-30 22:48:26 +02:00
Victor Stinner c62b49ecc8
gh-110088: Fix asyncio test_prompt_cancellation() (#110157)
Don't measure the CI performance: don't test the maximum elapsed
time. The check failed on a slow CI.
2023-09-30 22:40:10 +02:00
Victor Stinner 0def8c712b
gh-109748: Fix again venv test_zippath_from_non_installed_posix() (#110149)
Call also copy_python_src_ignore() on listdir() names.

shutil.copytree(): replace set() with an empty tuple. An empty tuple
becomes a constant in the compiler and checking if an item is in an
empty tuple is cheap.
2023-09-30 20:23:26 +02:00
Victor Stinner 74e425ec18
gh-110014: Fix _POSIX_THREADS and _POSIX_SEMAPHORES usage (#110139)
* pycore_pythread.h is now the central place to make sure that
  _POSIX_THREADS and _POSIX_SEMAPHORES macros are defined if
  available.
* Make sure that pycore_pythread.h is included when _POSIX_THREADS
  and _POSIX_SEMAPHORES macros are tested.
* PY_TIMEOUT_MAX is now defined as a constant, since its value
  depends on _POSIX_THREADS, instead of being defined as a macro.
* Prevent integer overflow in the preprocessor when computing
  PY_TIMEOUT_MAX_VALUE on Windows:
  replace "0xFFFFFFFELL * 1000 < LLONG_MAX"
  with "0xFFFFFFFELL < LLONG_MAX / 1000".
* Document the change and give hints how to fix affected code.
* Add an exception for PY_TIMEOUT_MAX  name to smelly.py
* Add PY_TIMEOUT_MAX to the stable ABI
2023-09-30 19:25:54 +02:00
Victor Stinner f3bb00ea12
gh-107954: Refactor initconfig.c: add CONFIG_SPEC (#110146)
Add a specification of the PyConfig structure to factorize the code.
2023-09-30 17:24:06 +00:00
Barney Gale 89966a694b
GH-89812: Add pathlib._PathBase (#106337)
Add private `pathlib._PathBase` class. This will be used by an experimental PyPI package to incubate a `tarfile.TarPath` class.

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2023-09-30 15:45:01 +01:00
Victor Stinner 14098b78f7
gh-107888: Fix test_mmap PROT_EXEC comment (#110125) 2023-09-29 23:56:19 +02:00
Sam Gross 2973970af8
gh-110119: Temporarily skip test_cppext on --disable-gil builds. (#110123)
The current version of pip does not support "t" in the ABI flags. Skip
the test in `--disable-gil` builds until we can update pip.
2023-09-29 13:50:51 -07:00
Victor Stinner 5ae6c6d053
gh-109566: regrtest --fast-ci no longer enables --nowindows (#110121)
The --nowindows option is deprecated and does nothing but logs a
warning.
2023-09-29 19:49:39 +00:00
Victor Stinner 6351842121
gh-109047: concurrent.futures catches PythonFinalizationError (#109810)
concurrent.futures: The *executor manager thread* now catches
exceptions when adding an item to the *call queue*. During Python
finalization, creating a new thread can now raise RuntimeError. Catch
the exception and call terminate_broken() in this case.

Add test_python_finalization_error() to test_concurrent_futures.

concurrent.futures._ExecutorManagerThread changes:

* terminate_broken() no longer calls shutdown_workers() since the
  call queue is no longer working anymore (read and write ends of
  the queue pipe are closed).
* terminate_broken() now terminates child processes, not only
  wait until they complete.
* _ExecutorManagerThread.terminate_broken() now holds shutdown_lock
  to prevent race conditons with ProcessPoolExecutor.submit().

multiprocessing.Queue changes:

* Add _terminate_broken() method.
* _start_thread() sets _thread to None on exception to prevent
  leaking "dangling threads" even if the thread was not started
  yet.
2023-09-29 19:31:19 +00:00
Furkan Onder 3439cb0049
gh-66143: Allow copying and pickling of CodecInfo object (GH-109235)
Co-authored-by: Robert Lehmann <mail@robertlehmann.de>
2023-09-29 20:07:09 +03:00
James Hilton-Balfe 7d57288f6d
gh-109495: Remove unused slots from the Python implementation of datetime (GH-109494) 2023-09-29 19:57:32 +03:00