Commit Graph

29326 Commits

Author SHA1 Message Date
Mark Dickinson f79ffc879b
gh-119740: Remove deprecated trunc delegation (#119743)
Remove the delegation of `int` to the `__trunc__` special method: `int` will now only delegate to `__int__` and `__index__` (in that order). `__trunc__` continues to exist, but its sole purpose is to support `math.trunc`.

---------

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-06-02 10:16:49 +01:00
Nikita Sobolev 4aed319a8e
gh-119775: Remove ability to create immutable types with mutable bases (#119776) 2024-06-02 07:27:20 +00:00
Barney Gale 53b1981fb0
GH-89727: Fix `shutil.rmtree()` recursion error on deep trees (#119808)
Implement `shutil._rmtree_safe_fd()` using a list as a stack to avoid emitting recursion errors on deeply nested trees.

`shutil._rmtree_unsafe()` was fixed in a150679f90.
2024-06-01 19:49:12 +01:00
Kirill Podoprigora cf3bba3f06
gh-113892: Add a extra check to `ProactorEventLoop.sock_connect` to ensure that the given socket is in non-blocking mode (#119519) 2024-06-01 09:05:19 -07:00
Jelle Zijlstra d28afd3fa0
gh-119180: Lazily wrap annotations on classmethod and staticmethod (#119864) 2024-05-31 14:05:51 -07:00
Jelle Zijlstra 80a4e38994
gh-119821: Support non-dict globals in LOAD_FROM_DICT_OR_GLOBALS (#119822)
Support non-dict globals in LOAD_FROM_DICT_OR_GLOBALS

The implementation basically copies LOAD_GLOBAL. Possibly it could be deduplicated,
but that seems like it may get hairy since the two operations have different operands.

This is important to fix in 3.14 for PEP 649, but it's a bug in earlier versions too,
and we should backport to 3.13 and 3.12 if possible.
2024-05-31 14:05:24 -07:00
Łukasz Langa 2237946af0
gh-118894: Make asyncio REPL use pyrepl (GH-119433) 2024-05-31 22:26:02 +02:00
Sam Gross 078b8c8cf2
gh-119369: Fix deadlock during thread exit in free-threaded build (#119528)
Release the GIL before calling `_Py_qsbr_unregister`.

The deadlock could occur when the GIL was enabled at runtime. The
`_Py_qsbr_unregister` call might block while holding the GIL because the
thread state was not active, but the GIL was still held.
2024-05-31 13:04:59 -04:00
Victor Stinner 64ff1e217d
gh-119770: Make termios ioctl() constants positive (#119840) 2024-05-31 17:18:40 +02:00
Sam Gross bcc1be39cb
gh-119585: Fix crash involving `PyGILState_Release()` and `PyThreadState_Clear()` (#119753)
Make sure that `gilstate_counter` is not zero in when calling
`PyThreadState_Clear()`. A destructor called from `PyThreadState_Clear()` may
call back into `PyGILState_Ensure()` and `PyGILState_Release()`. If
`gilstate_counter` is zero, it will try to create a new thread state before
the current active thread state is destroyed, leading to an assertion failure
or crash.
2024-05-31 10:50:52 -04:00
Steve Dower 0e8d35b931
gh-116145: Updated bundled Tcl/Tk on Windows to 8.6.14 (GH-117030) 2024-05-31 13:07:19 +01:00
Joshua Herman b9965ef282
gh-119189: Fix the power operator for Fraction (GH-119242)
When using the ** operator or pow() with Fraction as the base
and an exponent that is not rational, a float, or a complex, the
fraction is no longer converted to a float.
2024-05-31 10:05:09 +00:00
Christopher Chavez 94e9585e99
gh-103194: Fix Tkinter’s Tcl value type handling for Tcl 8.7/9.0 (GH-103846)
Some of standard Tcl types were renamed, removed, or no longer
registered in Tcl 8.7/9.0. This change fixes automatic conversion of Tcl
values to Python values to avoid returning a Tcl_Obj where the primary
Python types (int, bool, str, bytes) were returned in older Tcl.
2024-05-31 11:23:53 +03:00
Dino Viehland 0d07182821
gh-111201: Support pyrepl on Windows (#119559)
Co-authored-by: Anthony Shaw <anthony.p.shaw@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-31 09:49:03 +02:00
Serhiy Storchaka ef01e95ae3
gh-109218: Deprecate weird cases in the complex() constructor (GH-119620)
* Passing a string as the "real" keyword argument is now an error;
  it should only be passed as a single positional argument.
* Passing a complex number as the "real" or "imag" argument is now deprecated;
  it should only be passed as a single positional argument.
2024-05-30 23:30:57 +03:00
Sam Gross 1c04c63ced
gh-119729: Use 't' in pkg-config file name for free-threaded build (#119738)
For example, the free-threaded build now generates
`lib/pkgconfig/python-3.13t.pc` and the debug build generates
`lib/pkgconfig/python-3.13d.pc`.
2024-05-30 13:48:28 -04:00
Ethan Smith e50fac96e8
gh-119336: Restore removed _PyLong_NumBits() function (#119418)
It is used by the pywin32 project.
2024-05-30 14:48:18 +00:00
Barney Gale 3c890b503c
GH-89727: Fix `os.fwalk()` recursion error on deep trees (#119638)
Implement `os.fwalk()` using a list as a stack to avoid emitting recursion
errors on deeply nested trees.
2024-05-30 03:05:36 +00:00
Barney Gale a150679f90
GH-89727: Partially fix `shutil.rmtree()` recursion error on deep trees (#119634)
Make `shutil._rmtree_unsafe()` call `os.walk()`, which is implemented
without recursion.

`shutil._rmtree_safe_fd()` is not affected and can still raise a recursion
error.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-05-29 20:11:30 +00:00
Sam Gross c22323cd1c
gh-119525: Fix deadlock with `_PyType_Lookup` and the GIL (#119527)
The deadlock only affected the free-threaded build and only occurred
when the GIL was enabled at runtime. The `Py_DECREF(old_name)` call
might temporarily release the GIL while holding the type seqlock.
Another thread may spin trying to acquire the seqlock while holding the
GIL.

The deadlock occurred roughly 1 in ~1,000 runs of `pool_in_threads.py`
from `test_multiprocessing_pool_circular_import`.
2024-05-29 15:26:04 -04:00
Steve Dower df93f5d4bf
gh-119070: Fix py.exe handling of /usr/bin/env commands missing extension (GH-119426) 2024-05-29 18:51:13 +01:00
Wim Jeantine-Glenn fcca08ec2f
gh-119594: Improve pow(fraction.Fraction(), b, modulo) error message (#119593)
If one calls pow(fractions.Fraction, x, module) with modulo not None, the error message now says that the types are incompatible rather than saying pow only takes 2 arguments.  Implemented by having fractions.Fraction __pow__ accept optional modulo argument and return NotImplemented if not None.  pow() then raises with appropriate message.
---------

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2024-05-29 13:46:20 -04:00
Hugo van Kemenade 0751511d24
gh-93963: Remove deprecated names from importlib.abc (#119720)
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
2024-05-29 11:08:27 -06:00
Jason R. Coombs c8b45a385a
gh-118673: Remove shebang and executable bits from stdlib modules. (#119658)
* gh-118673: Remove shebang and executable bits from stdlib modules.

* Removed shebangs and exe bits on turtledemo scripts.

The setting was inappropriate for '__main__' and inconsistent across the other modules. The scripts can still be executed directly by invoking with the desired interpreter.
2024-05-29 12:43:19 -04:00
Steve Dower 78d697b7d5
gh-119690: Adds Unicode support for named pipes in _winapi (GH-119717) 2024-05-29 16:51:09 +01:00
Victor Stinner 1f481fd327
gh-119273: Don't run test_ioctl in a process group (#119275)
Python test runner no longer runs tests using TTY (ex: test_ioctl) in
a process group (using setsid()). Previously, tests using TTY were
skipped.
2024-05-29 12:44:09 +00:00
Sergey B Kirpichev 0cdc5c8d54
gh-119613: Soft deprecate Py_IS_NAN/INFINITY/FINITE (#119701)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-05-29 10:45:14 +00:00
Matthias Görgens 18c1a8d3a8
gh-97588: Align ctypes struct layout to GCC/MSVC (GH-97702)
Structure layout, and especially bitfields, sometimes resulted in clearly
wrong behaviour like overlapping fields. This fixes

Co-authored-by: Gregory P. Smith <gps@python.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-05-29 12:02:53 +02:00
Irit Katriel c1e9647107
gh-119689: generate stack effect metadata for pseudo instructions (#119691) 2024-05-29 09:47:56 +00:00
Sergey B Kirpichev 86d1a1aa88
gh-119555: catch SyntaxError from compile() in the InteractiveColoredConsole (#119557) 2024-05-29 07:57:50 +01:00
Jelle Zijlstra a8e35e8eba
gh-119443: Turn off from __future__ import annotations in REPL (#119493) 2024-05-28 17:05:18 -07:00
Lysandros Nikolaou d87b015106
gh-119118: Fix performance regression in tokenize module (#119615)
* gh-119118: Fix performance regression in tokenize module

- Cache line object to avoid creating a Unicode object
  for all of the tokens in the same line.
- Speed up byte offset to column offset conversion by using the
  smallest buffer possible to measure the difference.

Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
2024-05-28 19:17:49 +00:00
Nikita Sobolev 6b240c2308
gh-119011: `type.__type_params__` now return an empty tuple (#119296) 2024-05-28 18:12:58 +00:00
Jelle Zijlstra ae11d68ab9
gh-117865: Defer import of re in ast (#119546)
This is used only by ast.get_source_segment(), so it seems sensible to avoid importing it.

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-05-28 11:04:08 -07:00
Nikita Sobolev f912e5a2f6
gh-118824: Remove deprecated `master_open` and `slave_open` from `pty` (#118826)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2024-05-28 16:42:35 +03:00
Serhiy Storchaka b313cc68d5
gh-117557: Improve error messages when a string, bytes or bytearray of length 1 are expected (GH-117631) 2024-05-28 12:01:37 +03:00
Jelle Zijlstra a9a74da4a0
gh-119311: Fix name mangling with PEP 695 generic classes (#119464)
Fixes #119311. Fixes #119395.
2024-05-27 19:50:38 -07:00
Xie Yanbo 5ef5622543
Fix typos in HISTORY documentation (#119453) 2024-05-27 10:57:23 +03:00
Alex Waygood 008bc04dcb
gh-119562: Remove AST nodes deprecated since Python 3.8 (#119563) 2024-05-26 12:34:48 +00:00
Barney Gale e418fc3a6e
GH-82805: Fix handling of single-dot file extensions in pathlib (#118952)
pathlib now treats "`.`" as a valid file extension (suffix). This brings
it in line with `os.path.splitext()`.

In the (private) pathlib ABCs, we add a new `ParserBase.splitext()` method
that splits a path into a `(root, ext)` pair, like `os.path.splitext()`.
This method is called by `PurePathBase.stem`, `suffix`, etc. In a future
version of pathlib, we might make these base classes public, and so users
will be able to define their own `splitext()` method to control file
extension splitting.

In `pathlib.PurePath` we add optimised `stem`, `suffix` and `suffixes`
properties that don't use `splitext()`, which avoids computing the path
base name twice.
2024-05-25 21:01:36 +01:00
Eric Snow 0c5ebe13e9
gh-119560: Drop an Invalid Assert in PyState_FindModule() (gh-119561)
The assertion was added in gh-118532 but was based on the invalid assumption that PyState_FindModule() would only be called with an already-initialized module def.  I've added a test to make sure we don't make that assumption again.
2024-05-25 19:30:48 +00:00
Pablo Galindo Salgado e3bac04c37
gh-119548: Add a 'clear' command to the REPL (#119549) 2024-05-25 16:15:54 +00:00
Serhiy Storchaka 08e65430aa
gh-111999: Fix the signature of str.format_map() (#119540) 2024-05-25 06:21:11 -07:00
Tim Peters de19694cfb
gh-119105: Differ.compare is too slow [for degenerate cases] (#119492)
``_fancy_replace()`` is no longer recursive. and a single call does a worst-case linear number of ratio() computations instead of quadratic. This renders toothless a universe of pathological cases. Some inputs may produce different output, but that's rare, and I didn't find a case where the final diff appeared to be of materially worse quality. To the contrary, by refusing to even consider synching on lines "far apart", there was more easy-to-digest locality in the output.
2024-05-24 22:08:21 -05:00
Nice Zombies 96b392df30
gh-118263: Add additional arguments to path_t (Argument Clinic type) in posixmodule (GH-118355) 2024-05-24 19:04:17 +01:00
Victor Stinner 92fab3356f
gh-69214: Fix fcntl.ioctl() request type (#119498)
Use an 'unsigned long' instead of an 'unsigned int' for the request
parameter of fcntl.ioctl() to support requests larger than UINT_MAX.
2024-05-24 14:31:40 +02:00
Victor Stinner e94dbe4ed8
gh-119461: Fix ThreadedVSOCKSocketStreamTest (#119465)
Add socket.VMADDR_CID_LOCAL constant.

Fix ThreadedVSOCKSocketStreamTest: if get_cid() returns the host
address or the "any" address, use the local communication address
(loopback): VMADDR_CID_LOCAL.

On Linux 6.9, apparently, the /dev/vsock device is now available but
get_cid() returns VMADDR_CID_ANY (-1).
2024-05-23 23:26:09 +02:00
Eric Snow b30d30c747
gh-117398: Statically Allocate the Datetime C-API (GH-119472) 2024-05-23 21:15:52 +02:00
Mark Shannon 406ffb5293
GH-117195: Avoid assertion error in `object.__sizeof__` (GH-117220) 2024-05-23 11:06:10 +01:00
Xie Yanbo e3f5a44553
Fix typos in what's new documentation (#119448) 2024-05-23 06:41:33 +00:00