Commit Graph

3785 Commits

Author SHA1 Message Date
Jelle Zijlstra 4038869423
gh-112509: Fix keys being present in both required_keys and optional_keys in TypedDict (#112512)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-11-29 09:36:48 -08:00
Irit Katriel 2c68011780
gh-112332: Deprecate TracebackException.exc_type, add exc_type_str. (#112333) 2023-11-28 08:03:25 +00:00
Tian Gao 2df26d8348
gh-112105: Make completer delims work on libedit (gh-112106) 2023-11-28 06:23:23 +00:00
Anthony Shaw 154f099e61
gh-112292 : Catch import error conditions with readline hooks (gh-112313)
Prevents a segmentation fault in registered hooks for the readline library, but only when the readline module is loaded inside an isolated sub interpreter.  The module is single-phase init so loading it fails, but not until the module init function has already run, where the readline hooks get registered.

The readlinestate_global macro was error-prone to PyImport_FindModule returning NULL and crashing in about 18 places.  I could reproduce 1 easily, but this PR replaces the macro with a function and adds error conditions to the other functions.
2023-11-27 18:58:53 -07:00
Tian Gao b90a5cf11c
gh-99367: Do not mangle sys.path[0] in pdb if safe_path is set (#111762)
Co-authored-by: Christian Walther <cwalther@users.noreply.github.com>
2023-11-27 23:11:40 +00:00
Serhiy Storchaka 4dcfd02bed
gh-68166: Add support of "vsapi" in ttk.Style.element_create() (GH-111393) 2023-11-27 20:57:33 +02:00
kale-smoothie 967f2a3052
bpo-41422: Visit the Pickler's and Unpickler's memo in tp_traverse (GH-21664)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-11-27 18:09:41 +00:00
Jacob Walls 99a73c3465
gh-76912: Raise OSError from any failure in getpass.getuser() (#29739)
* bpo-32731: Raise OSError from any failure in getpass.getuser()
Previously, if the username was not set in certain environment variables, ImportError escaped on Windows systems, and it was possible for KeyError to escape on other systems if getpwuid() failed.
2023-11-27 10:05:55 -08:00
Zackery Spytz 812360fddd
gh-84443: SSLSocket.recv_into() now support buffer protocol with itemsize != 1 (GH-20310)
It is also no longer use __len__().

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-11-27 19:15:39 +02:00
Alex Waygood 22e411e1d1
gh-111874: Call `__set_name__` on objects that define the method inside a `typing.NamedTuple` class dictionary as part of the creation of that class (#111876)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-11-27 16:34:44 +00:00
Alex Waygood 0622839cfe
gh-112414: Fix `AttributeError` when calling `repr()` on a namespace package imported with a custom loader (#112425) 2023-11-27 08:19:29 +00:00
Grant Ramsay e954ac7205
gh-63284: Add support for TLS-PSK (pre-shared key) to the ssl module (#103181)
Add support for TLS-PSK (pre-shared key) to the ssl module.

---------

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-11-27 04:01:44 +00:00
Alex Waygood 418d585feb
gh-112405: Optimise `pathlib.Path.relative_to` (#112406) 2023-11-26 15:56:03 +00:00
Mark Dickinson 9fe60340d7
gh-112358: Fix Python 3.12 regression with subclassing struct.Struct. (#112424)
Revert commit c8c0afc713 (PR #94532),
which moved `struct.Struct` initialisation from `Struct.__init__` to `Struct.__new__`.
This caused issues with code in the wild that subclasses `struct.Struct`.
2023-11-26 14:29:52 +00:00
Barney Gale bbb4367b55
GH-77621: Delay some imports from pathlib (#112244)
Import `contextlib`, `glob` and `re` only as required.

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-11-25 17:41:05 +00:00
Irit Katriel fbb9027a03
gh-94722: fix DocTest.__eq__ for case of no line number on one side (#112385) 2023-11-25 17:23:43 +00:00
Barney Gale 19a1fc1b3d
GH-112361: Speed up pathlib by removing some temporary objects. (#112362)
Construct only one new list object (using `list.copy()`) when creating a
new path object with a modified tail. This slightly speeds up
`with_name()` and `with_suffix()`
2023-11-25 17:19:38 +00:00
Randolf Scholz e9d1360c9a
gh-112345: `typing.Protocol`: Let failed subclasscheck show non-method members (#112344)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-11-24 09:46:08 +00:00
Tian Gao dc0adb44d8
Add extra tests for `random.binomialvariate` (gh-112325) 2023-11-23 12:31:03 -06:00
Irit Katriel 89ddea4886
gh-112137: change dis output to show no-lineno as -- instead of None (#112335) 2023-11-23 14:34:27 +00:00
Irit Katriel 10e1a0c916
gh-112137: change dis output to display labels instead of offsets (#112138) 2023-11-22 22:36:55 +00:00
Thomas Wouters 9c4347ef8b Python 3.13.0a2 2023-11-22 12:20:24 +01:00
Junya Okabe 9d70831cb7
gh-110745: add a newline argument to pathlib.Path.read_text (#110880)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Barney Gale <barney.gale@gmail.com>
2023-11-21 22:32:38 +00:00
Michael ce1096f974
gh-73561: Omit interface scope from IPv6 when used as Host header (#93324)
Omit the `@interface_scope` from an IPv6 address when used as Host header by `http.client`.

---------

Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google LLC]
2023-11-19 22:37:13 +00:00
DPR e0f5127975
gh-109538: Avoid RuntimeError when StreamWriter is deleted with closed loop (#111983)
Issue a ResourceWarning instead.

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2023-11-15 01:17:51 +00:00
adder32 fe9db901b2
gh-111995: Add getnameinfo extension flag (#111994)
Add getnameinfo extension NI_IDN flag.
2023-11-15 01:00:24 +00:00
Serhiy Storchaka 9302f05f9a
gh-111942: Fix SystemError in the TextIOWrapper constructor (#112061)
In non-debug more the check for the "errors" argument is skipped,
and then PyUnicode_AsUTF8() can fail, but its result was not checked.

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-11-14 20:02:28 +00:00
Serhiy Storchaka ee06fffd38
gh-111942: Fix crashes in TextIOWrapper.reconfigure() (GH-111976)
* Fix crash when encoding is not string or None.
* Fix crash when both line_buffering and write_through raise exception
  when converted ti int.
* Add a number of tests for constructor and reconfigure() method
  with invalid arguments.
2023-11-14 17:37:56 +02:00
Tian Gao f44d6ff6e0
gh-110944: Make pdb completion work for alias and convenience vars (GH-110945) 2023-11-14 13:22:25 +01:00
Barney Gale cf67ebfb31
GH-72904: Add `glob.translate()` function (#106703)
Add `glob.translate()` function that converts a pathname with shell wildcards to a regular expression. The regular expression is used by pathlib to implement `match()` and `glob()`.

This function differs from `fnmatch.translate()` in that wildcards do not match path separators by default, and that a `*` pattern segment matches precisely one path segment. When *recursive* is set to true, `**` pattern segments match any number of path segments, and `**` cannot appear outside its own segment.

In pathlib, this change speeds up directory walking (because `_make_child_relpath()` does less work), makes path objects smaller (they don't need a `_lines` slot), and removes the need for some gnarly code.

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2023-11-13 17:15:56 +00:00
Davide Rizzo d2f305dfd1
gh-111460: Restore ncurses widechar support on macOS (#111878) 2023-11-13 22:36:50 +09:00
Barney Gale d7cef7bc7e
GH-111429: Speed up `pathlib.PurePath.[is_]relative_to()` (#111431) 2023-11-12 22:59:17 +00:00
Stephen Gildea 38035fed9b
gh-90890: New methods to access mailbox.Maildir message info and flags (#103905)
New methods to access mailbox.Maildir message info and flags:
get_info, set_info, get_flags, set_flags, add_flag, remove_flag.

These methods speed up accessing a message's info and/or flags and are
useful when it is not necessary to access the message's contents,
as when iterating over a Maildir to find messages with specific flags.

---------

* Add more str type checking
* modernize to f-strings instead of %

Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-11-11 17:41:33 +00:00
Nikita Sobolev ae8116cfa9
gh-107431: Make `multiprocessing.managers.{DictProxy,ListProxy}` generic (#107433)
Make `multiprocessing.managers.{DictProxy,ListProxy}` generic for type annotation use.  `ListProxy[str]` for example.

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-11-10 23:23:27 +00:00
Tian Gao 148af38cd0
gh-80731: Avoid executing code in except block in cmd (GH-111740) 2023-11-10 21:13:29 +00:00
Serhiy Storchaka 0b06d2482d
gh-111841: Fix os.putenv() and os.unsetenv() with embedded NUL on Windows (GH-111842) 2023-11-10 18:42:14 +02:00
Zac Hatfield-Dodds d61313bdb1
gh-103791: handle `BaseExceptionGroup` in `contextlib.suppress()` (#111910) 2023-11-10 13:32:36 +00:00
Nicolas Tessore baeb7718f8
gh-111356: io: Add missing documented objects to io.__all__ (#111370)
Add DEFAULT_BUFFER_SIZE, text_encoding, and IncrementalNewlineDecoder.
2023-11-10 16:18:52 +09:00
Donghee Na 6046aec377
gh-111835: Add seekable method to mmap.mmap (gh-111852) 2023-11-09 20:13:35 +09:00
Brett Cannon 97c4c06d0d
GH-111804: Drop posix.fallocate() under WASI (GH-111869)
Drop posix.fallocate() under WASI.

The underlying POSIX function, posix_fallocate(), was found to vary too
much between implementations to remain in WASI. As such, while it was
available in WASI preview1, it's been dropped in preview2.
2023-11-08 17:20:35 -08:00
Serhiy Storchaka 005d1e8fc8
gh-68166: Tkinter: Add tests and examples for element_create() (GH-111453)
* Remove mention of "vsapi" element type from the documentation.
* Add tests for element_create() and other ttk.Style methods.
* Add examples for element_create() in the documentation.
2023-11-08 18:25:58 +02:00
Pierre Ossman (ThinLinc team) 74b868f636
gh-111246: Remove listening Unix socket on close (#111483)
Try to clean up the socket file we create so we don't add unused noise to the file system.
2023-11-08 08:10:10 -08:00
Stefan f88caab467
gh-111768: Add `wsgiref.util.is_hop_by_hop` to `__all__` (#111770) 2023-11-08 15:29:47 +00:00
Serhiy Storchaka 70afb8d732
gh-85098: Implement functional CLI of symtable (#109112)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2023-11-07 16:32:16 +00:00
Charles Machalow ba8aa1fd37
gh-109466: Add ipv6_mapped property to IPv4Address (#109467)
Adds the `IPv4Address.ipv6_mapped` property.

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2023-11-05 16:50:31 +00:00
Tian Gao 853b4b549d
gh-111719: Add extra check for alias command (#111720) 2023-11-04 23:05:22 +00:00
Davide Rizzo a6c1c04d4d
gh-110395: invalidate open kqueues after fork (#110517)
Invalidate open select.kqueue instances after fork as the fd will be invalid in the child.
2023-11-04 21:45:24 +00:00
Tian Gao cd6b2ced75
gh-80675: Set `f_trace_lines = True` on all frames upon `pdb.set_trace()` (#110881) 2023-11-04 19:59:36 +00:00
CF Bolz-Tereick 9573d14215
gh-96954: use a directed acyclic word graph for storing the unicodedata codepoint names (#97906)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
2023-11-04 15:56:58 +01:00
Nikita Sobolev 18c954849b
gh-111159: Fix `SyntaxError` doctests for non-builtin exception classes (#111541) 2023-11-04 09:54:10 +00:00
Philippe Cerfon 7810b6981a
gh-90026: support XATTRs on Cygwin (GH-105075) 2023-11-03 10:37:46 +01:00
Victor Stinner 4fe22c7377
gh-111482: Use Argument Clinic for clock_gettime() (#111641)
Use Argument Clinic for time.clock_gettime() and
time.clock_gettime_ns() functions.

Benchmark on time.clock_gettime_ns():

    import time
    import pyperf
    runner = pyperf.Runner()
    runner.timeit(
        'clock_gettime_ns(CLOCK_MONOTONIC_COARSE)',
        setup='import time; clock_gettime_ns=time.clock_gettime_ns; CLOCK_MONOTONIC_COARSE=6',
        stmt='clock_gettime_ns(CLOCK_MONOTONIC_COARSE)')

Result on Linux with CPU isolation:

Mean +- std dev: [ref] 134 ns +- 1 ns -> [change] 55.7 ns +- 1.4 ns: 2.41x faster
2023-11-02 14:29:05 +01:00
Kumar Aditya 229f44d353
GH-110894: Call loop exception handler for exceptions in client_connected_cb (#111601)
Call loop exception handler for exceptions in `client_connected_cb` of `asyncio.start_server` so that applications can handle it.
2023-11-02 07:38:18 +00:00
Thomas Grainger 770530679e
gh-110774: allow setting the Runner(loop_factory=...) from IsolatedAsyncioTestCase (#110776)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
2023-10-31 15:03:54 -07:00
Serhiy Storchaka e3353c498d
gh-111531: Tkinter: fix reference leaks in bind_class() and bind_all() (GH-111533) 2023-10-31 08:48:52 +02:00
c-bata 8c47ada2de
gh-66425: Remove the unreachable code to set `REMOTE_HOST` header (gh-111441) 2023-10-29 13:56:15 +09:00
Guido van Rossum 2655369559
gh-79033: Try to fix asyncio.Server.wait_closed() again (GH-111336)
* Try to fix asyncio.Server.wait_closed() again

I identified the condition that `wait_closed()` is intended
to wait for: the server is closed *and* there are no more
active connections.

When this condition first becomes true, `_wakeup()` is called
(either from `close()` or from `_detach()`) and it sets `_waiters`
to `None`. So we just check for `self._waiters is None`; if it's
not `None`, we know we have to wait, and do so.

A problem was that the new test introduced in 3.12 explicitly
tested that `wait_closed()` returns immediately when the server
is *not* closed but there are currently no active connections.
This was a mistake (probably a misunderstanding of the intended
semantics). I've fixed the test, and added a separate test that
checks exactly for this scenario.

I also fixed an oddity where in `_wakeup()` the result of the
waiter was set to the waiter itself. This result is not used
anywhere and I changed this to `None`, to avoid a GC cycle.

* Update Lib/asyncio/base_events.py

---------

Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
2023-10-28 18:04:29 +00:00
Sergey B Kirpichev 9dc4fb8204
gh-111342: fix typo in math.sumprod (GH-111416) 2023-10-27 23:52:04 -05:00
Tian Gao 1c9a0c4079
gh-59013: Make line number of function breakpoint more precise (#110582) 2023-10-27 22:01:31 +01:00
Nikita Sobolev aa732459c5
gh-111388: Add `show_group` parameter to `traceback.format_exception_only` (#111390) 2023-10-27 11:11:26 +01:00
Serhiy Storchaka 309efb39dc
gh-111259: Optimize recursive wildcards in pathlib (GH-111303)
Regular expression pattern `(?s:.)` is much faster than `[\s\S]`.
2023-10-26 18:07:06 +03:00
Hugo van Kemenade 81ed80d843
gh-111187: Postpone removal version for locale.getdefaultlocale() to 3.15 (#111188) 2023-10-25 16:47:41 +03:00
Nikita Sobolev f6304949bb
gh-111230: Fix errors checking in _ssl module init (#111232)
Introduce ADD_INT_CONST macro wrapper for PyModule_AddIntConstant()
2023-10-25 15:42:18 +02:00
Serhiy Storchaka 9da98c0d9a
gh-111174: Fix crash in getbuffer() called repeatedly for empty BytesIO (GH-111210) 2023-10-25 13:50:16 +03:00
Nikita Sobolev 81b03e7810
gh-111295: Fix error checking in time extension module init (#111296)
Introduce ADD_INT macro wrapper for PyModule_AddIntConstant()
2023-10-25 07:19:40 +00:00
Nikita Sobolev 2838c550f7
gh-111233: Fix error checking in select extension module init (#111234)
Introduce ADD_INT macro wrapper for PyModule_AddIntConstant()
2023-10-25 07:18:21 +00:00
Nikita Sobolev 3052c098ca
gh-111253: Fix error checking in _socket module init (#111254) 2023-10-25 07:11:04 +00:00
Nikita Sobolev 86887a2084
gh-111251: Fix error checking in _blake2 module init (#111252)
Introduce ADD_INT_CONST macro wrapper for PyModule_AddIntConstant()
2023-10-25 08:32:46 +02:00
Jokimax c73b0f3560
gh-102956: Fix returning of empty byte strings after seek in zipfile … (#103565)
gh-102956: Fix returning of empty byte strings after seek in zipfile module. This was a regression in 3.12.0 due to a performance enhancement.
2023-10-24 21:15:42 +00:00
Serhiy Storchaka b8c20f9049
gh-97928: Change the behavior of tkinter.Text.count() (GH-98484)
It now always returns an integer if one or less counting options are specified.
Previously it could return a single count as a 1-tuple, an integer (only if
option "update" was specified) or None if no items found.
The result is now the same if wantobjects is set to 0.
2023-10-24 12:59:19 +03:00
hetmankp 3726cb0f14
gh-105931: Fix surprising compileall stripdir behaviour (GH-108671)
Before, the '-s STRIPDIR' option on
compileall lead to some surprising results as it only strips away
path components that match, but leaves alone the non-matching ones
interspersed in between.

For example, with: python -m compileall -s/path/to/another/src
/path/to/build/src/file.py

The resulting written path will be: build/file.py

This fix only strips directories that are a fully matching prefix of the
source path. If a stripdir is provided that is not a valid prefix, a
warning will be displayed (which can be silenced with '-qq').
2023-10-23 13:55:39 +00:00
Tian Gao 767f416feb
gh-110196: Fix ipaddress.IPv6Address.__reduce__ (GH-110198) 2023-10-22 21:50:51 +03:00
Serhiy Storchaka 6c23635f2b
gh-111085: Fix invalid state handling in TaskGroup and Timeout (#111111)
asyncio.TaskGroup and asyncio.Timeout classes now raise proper RuntimeError
if they are improperly used.

* When they are used without entering the context manager.
* When they are used after finishing.
* When the context manager is entered more than once (simultaneously or
  sequentially).
* If there is no current task when entering the context manager.

They now remain in a consistent state after an exception is thrown,
so subsequent operations can be performed correctly (if they are allowed).

Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
2023-10-21 22:18:34 +03:00
Nikita Sobolev fd60549c0a
gh-111159: Fix `doctest` output comparison for exceptions with notes (#111160) 2023-10-21 19:02:00 +01:00
Terry Jan Reedy b802882fb2
gh-111092: Make turtledemo run without default root enabled (#111093)
Add missing 'root' argument to PanedWindow call.
Other root children already have it.
2023-10-19 23:58:41 -04:00
Tian Gao e6eb8cafca
GH-102895 Add an option local_exit in code.interact to block exit() from terminating the whole process (GH-102896) 2023-10-18 11:36:43 -07:00
Radislav Chugunov 162213f2db
gh-108791: Fix `pdb` CLI invalid argument handling (#108816) 2023-10-16 10:38:07 +01:00
Tian Gao fa18b0afe4
gh-84583: Make pdb enter post-mortem mode even for SyntaxError (#110883) 2023-10-15 11:55:00 +01:00
Serhiy Storchaka ab08ff7882
bpo-42663: Fix parsing TZ strings in zoneinfo module (GH-23825)
zipinfo now supports the full range of values in the TZ string
determined by RFC 8536 and detects all invalid formats.
Both Python and C implementations now raise exceptions of the same
type on invalid data.
2023-10-14 23:24:33 +03:00
Serhiy Storchaka e2b3d831fd
gh-109747: Improve errors for unsupported look-behind patterns (GH-109859)
Now re.error is raised instead of OverflowError or RuntimeError for
too large width of look-behind pattern.

The limit is increased to 2**32-1 (was 2**31-1).
2023-10-14 09:13:02 +03:00
Serhiy Storchaka 38bd2c520a
gh-88434: Emit deprecation warnings for non-integer numbers in gettext if translation not found (GH-110574) 2023-10-14 09:07:02 +03:00
Serhiy Storchaka 84e2096fbd
gh-110392: Fix tty functions (GH-110642)
* tty.setraw() and tty.setcbreak() previously returned partially modified
  list of the original tty attributes. Now they return the correct list of
  the original tty attributes

* tty.cfmakeraw() and tty.cfmakecbreak() now make a copy of the list of
  special characters before modifying it.
2023-10-14 08:50:41 +03:00
Russell Keith-Magee a7e2a10a85
gh-110771: Decompose run_forever() into parts (#110773)
Effectively introduce an unstable, private (really: protected) API for subclasses that want to override `run_forever()`.
2023-10-13 14:12:32 +00:00
Thomas Wouters ad056f03ae Python 3.13.0a1 2023-10-13 10:52:10 +02:00
Filipe Laíns 6478dea3c8
GH-110786: suppress BrokenPipeError on the sysconfig CLI (#110791) 2023-10-13 06:49:55 +01:00
Filipe Laíns 4a53a397c3
GH-103480: make sysconfig a package (GH-110785) 2023-10-12 23:41:34 +00:00
Alex Waygood aa3f419acb
gh-109653: Improve the import time of `email.utils` (#109824) 2023-10-12 15:03:20 -07:00
Thomas Grainger 8c6c14b91b
gh-94597: Add asyncio.EventLoop (#110723)
This is needed to pave the way for deprecating and eventually killing the event loop policy system (which is over-engineered and rarely used).
2023-10-12 07:13:57 -07:00
Nikita Sobolev b6000d2874
gh-109409: Fix inheritance of frozen dataclass from non-frozen dataclass mixins (gh-109437)
Fix inheritance of frozen dataclass from non-frozen dataclass mixins
2023-10-12 09:05:23 -04:00
Nikita Sobolev 5257ade0bc
gh-110682: Ignore `__match_args__` from `__instancecheck__` in protocols (#110683)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-10-11 19:20:20 -07:00
J. Nick Koston 3ac8e6955f
gh-110733: Micro-optimization in BaseEventLoop._run_once (#110735) 2023-10-11 20:59:27 +00:00
Tian Gao c523ce0f43
gh-65052: Prevent pdb from crashing when trying to display objects (#110578) 2023-10-11 19:52:14 +02:00
Barney Gale b5f7777cb3
GH-110488: Fix two small issues in `pathlib.PurePath.with_name()` (#110651)
Ensure that `PurePath('foo/a').with_name('.')` raises `ValueError`

Ensure that `PureWindowsPath('foo/a').with_name('a:b')` does not raise
`ValueError`.
2023-10-11 04:45:11 +01:00
Nikita Sobolev 344d3a222a
gh-110590: Fix a bug where _sre.compile would overwrite exceptions (#110591)
TypeError would be overwritten by OverflowError
if 'code' param contained non-ints.
2023-10-10 10:15:12 +00:00
Serhiy Storchaka 96fed66a65
gh-110378: Close invalid generators in contextmanager and asynccontextmanager (GH-110499)
contextmanager and asynccontextmanager context managers now close an invalid
underlying generator object that yields more then one value.
2023-10-10 09:43:04 +02:00
Serhiy Storchaka 326c6c4e07
gh-110519: Improve deprecation warning in the gettext module (#110520)
Deprecation warning about non-integer numbers in gettext now always refers
to the line in the user code where gettext function or method is used.
Previously, it could refer to a line in gettext code.

Also, increase test coverage for NullTranslations and domain-aware functions
like dngettext().
2023-10-09 15:45:22 +02:00
Tian Gao 9f8282de6b
gh-106670: Set convenience variable for post mortem debugging (#110493) 2023-10-09 08:17:24 +00:00
Serhiy Storchaka d96a8cdfe2
gh-89902: Deprecate non-standard format specifier "N" for Decimal (GH-110508)
It was not documented and only supported in the C implementation.
2023-10-08 10:01:39 +03:00
Masaru Tsuchiyama de2a4036cb
gh-108277: Add os.timerfd_create() function (#108382)
Add wrapper for timerfd_create, timerfd_settime, and timerfd_gettime to os module.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2023-10-07 19:33:22 +02:00
Nikita Sobolev 2bbbab212f
gh-110365: Fix error overwrite in `termios.tcsetattr` (#110366)
Co-authored-by: Erlend E. Aasland <erlend@python.org>
2023-10-05 11:02:52 +00:00
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
Serhiy Storchaka 254e30c487
gh-109151: Enable readline in the sqlite3 CLI (GH-109152) 2023-10-04 14:16:44 +03: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
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
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
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
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 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
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 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
Jelle Zijlstra 7dc2c5093e
gh-110045: Update symtable module for PEP 695 (#110066) 2023-09-29 02:08:04 +00:00
Victor Stinner bd4518c60c
gh-110036: multiprocessing Popen.terminate() catches PermissionError (#110037)
On Windows, multiprocessing Popen.terminate() now catchs
PermissionError and get the process exit code. If the process is
still running, raise again the PermissionError. Otherwise, the
process terminated as expected: store its exit code.
2023-09-29 02:41:12 +02:00
Davide Rizzo b14f0ab51c
gh-110038: KqueueSelector must count all read/write events (#110039) 2023-09-28 17:25:10 +00:00
Amin Alaee 7df8b16d28
gh-109782: Ensure `os.path.isdir` has the same signature on all platforms (GH-109790) 2023-09-28 16:17:30 +01:00
Nikita Sobolev f65f9e80fe
gh-109818: `reprlib.recursive_repr` copies `__type_params__` (#109819) 2023-09-27 19:26:42 -07:00
Dale Collison 74723e1110
gh-109461: Update logging module lock to use context manager (#109462)
Co-authored-by: Victor Stinner <vstinner@python.org>
2023-09-27 18:26:41 +02:00
Barney Gale ecd813f054
GH-109187: Improve symlink loop handling in `pathlib.Path.resolve()` (GH-109192)
Treat symlink loops like other errors: in strict mode, raise `OSError`, and
in non-strict mode, do not raise any exception.
2023-09-26 17:57:17 +01:00
Antoine Pitrou 0eb98837b6
gh-109593: Fix reentrancy issue in multiprocessing resource_tracker (#109629)
---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2023-09-26 13:57:25 +02:00
Serhiy Storchaka 8ac2085b80
gh-109631: Allow interruption of short repeated regex matches (GH-109867)
Counting for signal checking now continues in new match from the point where
it ended in the previous match instead of starting from 0.
2023-09-26 10:56:33 +03:00
Jason R. Coombs e9791ba351
gh-88233: zipfile: refactor _strip_extra (#102084)
* Refactor zipfile._strip_extra to use higher level abstractions for extras instead of a heavy-state loop.

* Add blurb

* Remove _strip_extra and use _Extra.strip directly.

* Use memoryview to avoid unnecessary copies while splitting Extras.
2023-09-25 19:46:58 -04:00
Antoine Pitrou 88a6137cdb
gh-109599: Add types.CapsuleType (#109600)
---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2023-09-25 19:50:39 +02:00
Alex Waygood 40d1de7581
gh-109653: Avoid a top-level import of `types` in `functools` (#109804) 2023-09-24 17:18:27 +01:00
Alex Waygood 51863b7d6e
gh-109653: Improve `enum` import time by avoiding import of `functools` (GH-109789) 2023-09-23 11:31:17 -07:00
Alex Waygood e8be0c9c5a
gh-109653: `typing.py`: improve import time by creating soft-deprecated members on demand (#109651)
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
2023-09-23 08:46:35 +01:00
Hugo van Kemenade 8a82bff12c
Docs: Update Donghee Na's name (#109743) 2023-09-22 12:52:57 -06:00
Tian Gao 73ccfa28c5
gh-109164: Replace `getopt` with `argparse` in pdb (#109165)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2023-09-22 16:55:48 +00:00
elfstrom 405b06375a
gh-105829: Fix concurrent.futures.ProcessPoolExecutor deadlock (#108513)
This fixes issue #105829, https://github.com/python/cpython/issues/105829

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Antoine Pitrou <antoine@python.org>
Co-authored-by: Chris Withers <chris@withers.org>
Co-authored-by: Thomas Moreau <thomas.moreau.2010@gmail.com>
2023-09-22 13:55:56 +01:00
EliseevEgor 8fc071345b
gh-106584: Fix exit code for unittest in Python 3.12 (#106588)
Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-09-22 14:26:27 +02:00
AN Long 869f177b5c
gh-74481: Add missing debug function docs and constants to msvcrt (GH-109650) 2023-09-21 16:44:24 +01:00
Victor Stinner d4cea794a7
gh-109613: _pystat_fromstructstat() checks for exceptions (#109618)
Fix os.stat() and os.DirEntry.stat(): check for exceptions.
Previously, on Python built in debug mode, these functions could
trigger a fatal Python error (and abort the process) when a function
succeeded with an exception set.

_pystat_fromstructstat() now exits immediately if an exception is
raised, rather only checking for exceptions at the end. It fix
following fatal error in fill_time():

    Fatal Python error: _Py_CheckSlotResult:
    Slot * of type int succeeded with an exception set
2023-09-21 09:55:06 +02:00
James Gerity def828995a
fixes gh-109559: Update `unicodedata` for Unicode 15.1.0 (GH-109560)
---------

Co-authored-by: Benjamin Peterson <benjamin@python.org>
2023-09-19 22:07:47 -07:00
Jelle Zijlstra 1293fcc3c6
gh-109543: Remove unnecessary hasattr check (#109544)
Also added a new test case covering the scenario I thought this
might be about.
2023-09-19 20:15:52 -07:00
Mateusz Nowak 5a740cd06e
gh-109109: Expose retrieving certificate chains in SSL module (#109113)
Adds APIs to get the TLS certificate chains, verified or full unverified, from SSLSocket and SSLObject.

Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
2023-09-20 01:20:54 +00:00
Ronan Pigott ddf2e953c2
gh-109033: Return filename with os.utime errors (#109034)
The filename was previously intentionally omitted from exception because
"it might confuse the user". Uncaught exceptions are not generally a
replacement for user-facing error messages, so obscuring this
information only has the effect of making the programmer's life more
difficult.
2023-09-20 01:18:23 +02:00
Shantanu 23f9f6f464
gh-108843: fix ast.unparse for f-string with many quotes (#108981) 2023-09-18 14:56:19 +01:00
Brett Cannon e218e5022e
GH-83417: Allow `venv` to add a `.gitignore` file to environments via a new `scm_ignore_file` parameter (GH-108125)
This feature is off by default via code but on by default via the CLI. The `.gitignore` file contains `*` which causes the entire directory to be ignored.

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2023-09-15 22:38:08 +00:00
Gregory P. Smith 59073c9ab8
gh-109096: Deprecate `http.server.CGIHTTPRequestHandler` (#109387)
Deprecate `http.server.CGIHTTPRequestHandler`.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-09-15 14:26:45 -07:00
buermarc 68a6f21f47
gh-109375: Fix bug where pdb registers an alias without an associated command (#109376) 2023-09-14 22:31:30 +01:00
Irit Katriel b303d3ad3e
gh-109319: deprecate dis.HAVE_ARGUMENT (#109320) 2023-09-12 16:45:35 +01:00
Nikita Sobolev 66d1d7eb06
gh-84867: Do not load tests from TestCase and FunctionTestCase (GH-100497) 2023-09-12 16:33:30 +03:00
Tian Gao 391f3e3ca9
GH-106734: Disable tab completion in pdb's multiline mode (GH-106735) 2023-09-11 18:28:43 -07:00
Victor Stinner 517cd82ea7
gh-108987: Fix _thread.start_new_thread() race condition (#109135)
Fix _thread.start_new_thread() race condition. If a thread is created
during Python finalization, the newly spawned thread now exits
immediately instead of trying to access freed memory and lead to a
crash.

thread_run() calls PyEval_AcquireThread() which checks if the thread
must exit. The problem was that tstate was dereferenced earlier in
_PyThreadState_Bind() which leads to a crash most of the time.

Move _PyThreadState_CheckConsistency() from thread_run() to
_PyThreadState_Bind().
2023-09-11 17:27:03 +02:00
Victor Stinner a9b1f84790
gh-107219: Fix concurrent.futures terminate_broken() (#109244)
Fix a race condition in concurrent.futures. When a process in the
process pool was terminated abruptly (while the future was running or
pending), close the connection write end. If the call queue is
blocked on sending bytes to a worker process, closing the connection
write end interrupts the send, so the queue can be closed.

Changes:

* _ExecutorManagerThread.terminate_broken() now closes
  call_queue._writer.
* multiprocessing PipeConnection.close() now interrupts
  WaitForMultipleObjects() in _send_bytes() by cancelling the
  overlapped operation.
2023-09-11 08:11:31 +00:00
Serhiy Storchaka d6892c2b92
gh-50644: Forbid pickling of codecs streams (GH-109180)
Attempts to pickle or create a shallow or deep copy of codecs streams
now raise a TypeError.

Previously, copying failed with a RecursionError, while pickling
produced wrong results that eventually caused unpickling to fail with
a RecursionError.
2023-09-10 20:06:09 +03:00