Commit Graph

120249 Commits

Author SHA1 Message Date
Nikita Sobolev 2ac4cf4743
gh-112640: Add `kwdefaults` parameter to `types.FunctionType.__new__` (#112641) 2024-01-11 00:42:30 -08:00
Peter Lazorchak f653caa5a8
gh-89811: Check for valid tp_version_tag in specializer (GH-113558) 2024-01-11 13:33:05 +08:00
Donghee Na c65ae26f2b
gh-111968: Unify naming scheme for freelist (gh-113919) 2024-01-11 08:51:51 +09:00
Kirill Podoprigora 9d33c23857
gh-113896: Fix test_builtin.BuiltinTest.test___ne__() (#113897)
Fix DeprecationWarning in test___ne__().

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-01-11 00:39:48 +01:00
AN Long fafb3275f2
gh-87868: Skip `test_one_environment_variable` in `test_subprocess` when the platform or build cannot do that (#113867)
* improve the assert for test_one_environment_variable
* skip some test in test_subprocess when python is configured with shared
* also skip the test if AddressSanitizer is enabled

---------

Co-authored-by: Steve Dower <steve.dower@microsoft.com>
2024-01-10 15:17:05 -08:00
Victor Stinner 1d75fa43a2
gh-77046: os.pipe() sets _O_NOINHERIT flag on fds (#113817)
On Windows, set _O_NOINHERIT flag on file descriptors
created by os.pipe() and io.WindowsConsoleIO.

Add test_pipe_spawnl() to test_os.

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
2024-01-10 23:02:17 +01:00
Seth Michael Larson e82b096335
gh-112302: Point core developers to SBOM devguide on errors (#113490)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2024-01-10 19:21:04 +00:00
Sam Gross 73ae2023a7
gh-113753: Clear finalized bit when putting PyAsyncGenASend back into free list (#113754) 2024-01-10 10:18:38 -08:00
Raymond Hettinger 901a971e16
gh-113625: Align object addresses in the Descriptor HowTo Guide (#113894) 2024-01-10 17:23:40 +01:00
Serhiy Storchaka 7049721835
Add @requires_zlib() decorator for gh-109858 tests (GH-113918) 2024-01-10 15:56:40 +00:00
Donghee Na f728f7242c
gh-111968: Use per-thread freelists for float in free-threading (gh-113886) 2024-01-10 15:47:13 +00:00
Mark Shannon a0c9cf9456
GH-113860: All executors are now defined in terms of micro ops. Convert counter executor to use uops. (GH-113864) 2024-01-10 15:44:34 +00:00
Victor Stinner 93930eaf0a
gh-111139: Optimize math.gcd(int, int) (#113887)
Add a fast-path for the common case.

Benchmark:

    python -m pyperf timeit \
        -s 'import math; gcd=math.gcd; x=2*3; y=3*5' \
        'gcd(x,y)'

Result: 1.07x faster (-3.4 ns)

    Mean +- std dev: 52.6 ns +- 4.0 ns -> 49.2 ns +- 0.4 ns: 1.07x faster
2024-01-10 16:38:56 +01:00
Serhiy Storchaka 66363b9a7b
gh-109858: Protect zipfile from "quoted-overlap" zipbomb (GH-110016)
Raise BadZipFile when try to read an entry that overlaps with other entry or
central directory.
2024-01-10 15:55:36 +02:00
Serhiy Storchaka 183b97bb9d
gh-111789: Use PyDict_GetItemRef() in Modules/_zoneinfo.c (GH-112078) 2024-01-10 15:35:10 +02:00
Serhiy Storchaka be5e65fdf6
gh-66515: Fix locking of an MH mailbox without ".mh_sequences" file (GH-113482)
Guarantee that it either open an existing ".mh_sequences" file or create
a new ".mh_sequences" file, but do not replace existing ".mh_sequences"
file.
2024-01-10 15:31:55 +02:00
Serhiy Storchaka 89cee94b31
gh-89850: Add default C implementations of persistent_id() and persistent_load() (GH-113579)
Previously the C implementation of pickle.Pickler and pickle.Unpickler
classes did not have such methods and they could only be used if
they were overloaded in subclasses or set as instance attributes.

Fixed calling super().persistent_id() and super().persistent_load() in
subclasses of the C implementation of pickle.Pickler and pickle.Unpickler
classes. It no longer causes an infinite recursion.
2024-01-10 15:30:37 +02:00
Serhiy Storchaka b3d2427f22
gh-58032: Do not use argparse.FileType in module CLIs and scripts (GH-113649)
Open and close files manually. It prevents from leaking files,
preliminary creation of output files, and accidental closing of stdin
and stdout.
2024-01-10 15:07:19 +02:00
Serhiy Storchaka a8629816c6
gh-113664: Improve style of Big O notation (GH-113695)
Use cursive to make it looking like mathematic formulas.
2024-01-10 15:01:18 +02:00
Serhiy Storchaka e9d5b6ea2d
gh-113594: Fix UnicodeEncodeError in TokenList.fold() (GH-113730)
It occurred when try to re-encode an unknown-8bit part combined with non-unknown-8bit part.
2024-01-10 14:54:36 +02:00
Serhiy Storchaka 568d220993
gh-70835: Clarify error message for CSV file opened with wrong newline (GH-113786)
Based on patch by SilentGhost.
2024-01-10 14:52:29 +02:00
Serhiy Storchaka aef4a1203c
gh-96037: Always insert TimeoutError when exit an expired asyncio.timeout() block (GH-113819)
If other exception was raised during exiting an expired
asyncio.timeout() block, insert TimeoutError in the exception context
just above the CancelledError.
2024-01-10 12:50:31 +02:00
Serhiy Storchaka ab0ad62038
gh-113879: Fix ResourceWarning in test_asyncio.test_server (GH-113881) 2024-01-10 12:38:36 +02:00
Serhiy Storchaka 1b7e0024a1
gh-113877: Fix Tkinter method winfo_pathname() on 64-bit Windows (GH-113900)
winfo_id() converts the result of "winfo id" command to integer, but
"winfo pathname" command requires an argument to be a hexadecimal number
on Win64.
2024-01-10 12:36:03 +02:00
Petr Viktorin 5d384b0468
GH-113858: GitHub Actions config: Only save ccache on pushes (GH-113859) 2024-01-10 09:49:18 +01:00
Jamie Phan 4826d52338
gh-112182: Replace StopIteration with RuntimeError for future (#113220)
When an `StopIteration` raises into `asyncio.Future`, this will cause
a thread to hang. This commit address this by not raising an exception
and silently transforming the `StopIteration` with a `RuntimeError`,
which the caller can reconstruct from `fut.exception().__cause__`
2024-01-09 21:21:00 -08:00
Barney Gale 5d8a3e74b5
pathlib ABCs: Require one or more initialiser arguments (#113885)
Refuse to guess what a user means when they initialise a pathlib ABC
without any positional arguments. In mainline pathlib it's normalised to
`.`, but in the ABCs this guess isn't appropriate; for example, the path
type may not represent the current directory as `.`, or may have no concept
of a "current directory" at all.
2024-01-10 01:12:58 +00:00
Barney Gale beb80d11ec
GH-113528: Deoptimise `pathlib._abc.PurePathBase` (#113559)
Apply pathlib's normalization and performance tuning in `pathlib.PurePath`, but not `pathlib._abc.PurePathBase`.

With this change, the pathlib ABCs do not normalize away alternate path separators, empty segments, or dot segments. A single string given to the initialiser will round-trip by default, i.e. `str(PurePathBase(my_string)) == my_string`. Implementors can set their own path domain-specific normalization scheme by overriding `__str__()`

Eliminating path normalization makes maintaining and caching the path's parts and string representation both optional and not very useful, so this commit moves the `_drv`, `_root`, `_tail_cached` and `_str` slots from `PurePathBase` to `PurePath`. Only `_raw_paths` and `_resolving` slots remain in `PurePathBase`. This frees the ABCs from the burden of some of pathlib's hardest-to-understand code.
2024-01-09 23:52:15 +00:00
Donghee Na 57bdc6c30d
gh-111968: Introduce _PyFreeListState and _PyFreeListState_GET API (gh-113584) 2024-01-10 08:04:41 +09:00
Barney Gale cdca0ce0ad
GH-113528: Deoptimise `pathlib._abc.PurePathBase.relative_to()` (again) (#113882)
Restore full battle-tested implementations of `PurePath.[is_]relative_to()`. These were recently split up in 3375dfe and a15a773.

In `PurePathBase`, add entirely new implementations based on `_stack`, which itself calls `pathmod.split()` repeatedly to disassemble a path. These new implementations preserve features like trailing slashes where possible, while still observing that a `..` segment cannot be added to traverse an empty or `.` segment in *walk_up* mode. They do not rely on `parents` nor `__eq__()`, nor do they spin up temporary path objects.

Unfortunately calling `pathmod.relpath()` isn't an option, as it calls `abspath()` and in turn `os.getcwd()`, which is impure.
2024-01-09 23:04:14 +00:00
Barney Gale 5c7bd0e398
GH-113528: Deoptimise `pathlib._abc.PurePathBase.parts` (#113883)
Implement `parts` using `_stack`, which itself calls `pathmod.split()`
repeatedly. This avoids use of `_tail`, which will be moved to `PurePath`
shortly.
2024-01-09 22:46:50 +00:00
AN Long 623b338adf
gh-66060: Use actual class name in _io type's __repr__ (#30824)
Use the object's actual class name in the following _io type's __repr__:
- FileIO
- TextIOWrapper
- _WindowsConsoleIO
2024-01-09 21:39:36 +01:00
Barney Gale 1092cfb201
GH-113528: Deoptimise `pathlib._abc.PathBase.resolve()` (#113782)
Replace use of `_from_parsed_parts()` with `with_segments()` in
`resolve()`.

No effect on `Path.resolve()`, which uses `os.path.realpath()`.
2024-01-09 19:50:23 +00:00
Stefano Rivera 3a9096c337
GH-113661: unittest runner: Don't exit 5 if tests were skipped (#113856)
The intention of exiting 5 was to detect issues where the test suite
wasn't discovered at all. If we skipped tests, it was correctly
discovered.
2024-01-09 19:50:01 +00:00
Serhiy Storchaka 0297418cac
gh-113781: Silence AttributeError in warning module during Python finalization (GH-113813)
The tracemalloc module can already be cleared.
2024-01-09 21:44:05 +02:00
Serhiy Storchaka a5db6a3351
gh-113848: Handle CancelledError subclasses in asyncio TaskGroup() and timeout() (GH-113850) 2024-01-09 21:41:31 +02:00
Serhiy Storchaka 5273655bea
gh-113848: Use PyErr_GivenExceptionMatches() for check for CancelledError (GH-113849) 2024-01-09 21:41:02 +02:00
Barney Gale 9100fc407e
GH-113528: Deoptimise `pathlib._abc.PathBase._make_child_relpath()` (#113532)
Call straight through to `joinpath()` in `PathBase._make_child_relpath()`.
Move optimised/caching code to `pathlib.Path._make_child_relpath()`
2024-01-09 19:11:17 +00:00
Raymond Hettinger 2fd2e74793
Simplify binomial approximation example with random.binomialvariate() (gh-113871) 2024-01-09 13:02:07 -06:00
Guido van Rossum 65f8eb7119
Fix opcode name printing in debug mode (#113870)
Fix a few places where the lltrace debug output printed ``(null)`` instead of an opcode name, because it was calling ``_PyUOpName()`` on a Tier-1 opcode.
2024-01-09 18:18:11 +00:00
Steve Dower ad849b4ba0
gh-113650: Add workaround option for MSVC ARM64 bug affecting string encoding (GH-113836) 2024-01-09 17:32:22 +00:00
AN Long be89ee5649
gh-103092: Test _ctypes type hierarchy and features (#113727)
Test the following features for _ctypes types:
- disallow instantiation
- inheritance (MRO)
- immutability
- type name

The following _ctypes types are tested:
- Array
- CField
- COMError
- PyCArrayType
- PyCFuncPtrType
- PyCPointerType
- PyCSimpleType
- PyCStructType
- Structure
- Union
- UnionType
- _CFuncPtr
- _Pointer
- _SimpleCData

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2024-01-09 18:28:43 +01:00
AN Long c31be58da8
gh-87868: Sort and remove duplicates in getenvironment() (GH-102731)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2024-01-09 15:58:26 +00:00
Yan Yanchii fda901a1ff
gh-113842: Add missing error check for PyIter_Next() in Python/symtable.c (GH-113843) 2024-01-09 12:43:58 +02:00
Hugo van Kemenade 2e17cad2b8
gh-101100: Fix Sphinx warnings for 2.6 port-specific deprecations (#113752) 2024-01-09 10:18:15 +02:00
Vinay Sajip 842b738129
gh-113692: skip a test if multiprocessing isn't available. (GH-113704) 2024-01-09 07:47:42 +00:00
William Andrea f3d5d4aa8f
Docs: Link tokens in the format string grammars (#108184)
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2024-01-09 02:47:59 +00:00
Donghee Na a023bc252d
gh-112087: Update list.{pop,clear,reverse,remove} to use CS (gh-113764) 2024-01-09 09:00:55 +09:00
Jakub Kulík 10d3f04aec
gh-112808: Fix mimalloc build on Solaris (#112809) 2024-01-08 15:50:56 -08:00
Jakub Kulík ae968d1032
gh-112806: Remove unused function warnings during mimalloc build on Solaris (#112807) 2024-01-08 15:49:33 -08:00