Skip to content

Commit c3a2dfa

Browse files
Merge remote-tracking branch 'upstream/main' into fix-nonstring-kwargs-155733
2 parents c127844 + 948fd7e commit c3a2dfa

43 files changed

Lines changed: 695 additions & 244 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ Include/internal/pycore_ast_state.h generated
8080
Include/internal/pycore_opcode.h generated
8181
Include/internal/pycore_opcode_metadata.h generated
8282
Include/internal/pycore_*_generated.h generated
83+
Include/internal/pycore_token.h generated
8384
Include/internal/pycore_uop_ids.h generated
8485
Include/internal/pycore_uop_metadata.h generated
8586
Include/opcode.h generated
8687
Include/opcode_ids.h generated
8788
Include/slots_generated.h generated
88-
Include/token.h generated
8989
Lib/_opcode_metadata.py generated
9090
Lib/idlelib/help.html generated
9191
Lib/keyword.py generated

Doc/library/annotationlib.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ Functions
235235
annotate functions that support the :attr:`~Format.STRING` format but
236236
do not have access to the code creating the annotations.
237237

238-
For example, this is used to implement the :attr:`~Format.STRING` for
239-
:class:`typing.TypedDict` classes created through the functional syntax:
238+
For example, this is used to implement the :attr:`~Format.STRING` format
239+
for :class:`typing.TypedDict` classes created through the functional syntax:
240240

241241
.. doctest::
242242

Doc/library/time.rst

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -122,23 +122,24 @@ An explanation of some terminology and conventions is in order.
122122
Functions
123123
---------
124124

125-
.. function:: asctime([t])
125+
.. function:: asctime([time_tuple])
126126

127127
Convert a tuple or :class:`struct_time` representing a time as returned by
128128
:func:`gmtime` or :func:`localtime` to a string of the following
129129
form: ``'Sun Jun 20 23:21:05 1993'``. The day field is two characters long
130130
and is space padded if the day is a single digit,
131-
e.g.: ``'Wed Jun 9 04:26:40 1993'``.
131+
for example: ``'Wed Jun 9 04:26:40 1993'``.
132132

133-
If *t* is not provided, the current time as returned by :func:`localtime`
134-
is used. Locale information is not used by :func:`asctime`.
133+
If *time_tuple* is not provided,
134+
the current time as returned by :func:`localtime` is used.
135+
Locale information is not used by :func:`asctime`.
135136

136137
.. note::
137138

138139
Unlike the C function of the same name, :func:`asctime` does not add a
139140
trailing newline.
140141

141-
.. function:: pthread_getcpuclockid(thread_id)
142+
.. function:: pthread_getcpuclockid(thread_id, /)
142143

143144
Return the *clk_id* of the thread-specific CPU-time clock for the specified *thread_id*.
144145

@@ -157,7 +158,7 @@ Functions
157158

158159
.. versionadded:: 3.7
159160

160-
.. function:: clock_getres(clk_id)
161+
.. function:: clock_getres(clk_id, /)
161162

162163
Return the resolution (precision) of the specified clock *clk_id*. Refer to
163164
:ref:`time-clock-id-constants` for a list of accepted values for *clk_id*.
@@ -167,7 +168,7 @@ Functions
167168
.. versionadded:: 3.3
168169

169170

170-
.. function:: clock_gettime(clk_id) -> float
171+
.. function:: clock_gettime(clk_id, /) -> float
171172

172173
Return the time of the specified clock *clk_id*. Refer to
173174
:ref:`time-clock-id-constants` for a list of accepted values for *clk_id*.
@@ -180,7 +181,7 @@ Functions
180181
.. versionadded:: 3.3
181182

182183

183-
.. function:: clock_gettime_ns(clk_id) -> int
184+
.. function:: clock_gettime_ns(clk_id, /) -> int
184185

185186
Similar to :func:`clock_gettime` but return time as nanoseconds.
186187

@@ -189,7 +190,7 @@ Functions
189190
.. versionadded:: 3.7
190191

191192

192-
.. function:: clock_settime(clk_id, time)
193+
.. function:: clock_settime(clk_id, time, /)
193194

194195
Set the time of the specified clock *clk_id*. Currently,
195196
:data:`CLOCK_REALTIME` is the only accepted value for *clk_id*.
@@ -205,7 +206,7 @@ Functions
205206
Accepts any real number as *time*, not only integer or float.
206207

207208

208-
.. function:: clock_settime_ns(clk_id, time: int)
209+
.. function:: clock_settime_ns(clk_id, time: int, /)
209210

210211
Similar to :func:`clock_settime` but set time with nanoseconds.
211212

@@ -214,23 +215,23 @@ Functions
214215
.. versionadded:: 3.7
215216

216217

217-
.. function:: ctime([secs])
218+
.. function:: ctime(seconds=None, /)
218219

219220
Convert a time expressed in seconds since the epoch_ to a string of a form:
220221
``'Sun Jun 20 23:21:05 1993'`` representing local time. The day field
221222
is two characters long and is space padded if the day is a single digit,
222-
e.g.: ``'Wed Jun 9 04:26:40 1993'``.
223+
for example: ``'Wed Jun 9 04:26:40 1993'``.
223224

224-
If *secs* is not provided or :const:`None`, the current time as
225-
returned by :func:`.time` is used. ``ctime(secs)`` is equivalent to
226-
``asctime(localtime(secs))``. Locale information is not used by
225+
If *seconds* is not provided or :const:`None`, the current time as
226+
returned by :func:`.time` is used. ``ctime(seconds)`` is equivalent to
227+
``asctime(localtime(seconds))``. Locale information is not used by
227228
:func:`ctime`.
228229

229230
.. versionchanged:: 3.15
230231
Accepts any real number, not only integer or float.
231232

232233

233-
.. function:: get_clock_info(name)
234+
.. function:: get_clock_info(name, /)
234235

235236
Get information on the specified clock as a namespace object.
236237
Supported clock names and the corresponding functions to read their value
@@ -255,10 +256,10 @@ Functions
255256
.. versionadded:: 3.3
256257

257258

258-
.. function:: gmtime([secs])
259+
.. function:: gmtime(seconds=None, /)
259260

260261
Convert a time expressed in seconds since the epoch_ to a :class:`struct_time` in
261-
UTC in which the dst flag is always zero. If *secs* is not provided or
262+
UTC in which the dst flag is always zero. If *seconds* is not provided or
262263
:const:`None`, the current time as returned by :func:`.time` is used. Fractions
263264
of a second are ignored. See above for a description of the
264265
:class:`struct_time` object. See :func:`calendar.timegm` for the inverse of this
@@ -268,11 +269,12 @@ Functions
268269
Accepts any real number, not only integer or float.
269270

270271

271-
.. function:: localtime([secs])
272+
.. function:: localtime(seconds=None, /)
272273

273-
Like :func:`gmtime` but converts to local time. If *secs* is not provided or
274-
:const:`None`, the current time as returned by :func:`.time` is used. The dst
275-
flag is set to ``1`` when DST applies to the given time.
274+
Like :func:`gmtime` but converts to local time.
275+
If *seconds* is not provided or :const:`None`,
276+
the current time as returned by :func:`.time` is used.
277+
The dst flag is set to ``1`` when DST applies to the given time.
276278

277279
:func:`localtime` may raise :exc:`OverflowError`, if the timestamp is
278280
outside the range of values supported by the platform C :c:func:`localtime`
@@ -284,7 +286,7 @@ Functions
284286
Accepts any real number, not only integer or float.
285287

286288

287-
.. function:: mktime(t)
289+
.. function:: mktime(time_tuple, /)
288290

289291
This is the inverse function of :func:`localtime`. Its argument is the
290292
:class:`struct_time` or full 9-tuple (since the dst flag is needed; use ``-1``
@@ -391,7 +393,7 @@ Functions
391393

392394
.. versionadded:: 3.7
393395

394-
.. function:: sleep(secs)
396+
.. function:: sleep(seconds, /)
395397

396398
Suspend execution of the calling thread for the given number of seconds.
397399
The argument may be a non-integer to indicate a more precise sleep time.
@@ -404,13 +406,16 @@ Functions
404406

405407
.. rubric:: Windows implementation
406408

407-
On Windows, if *secs* is zero, the thread relinquishes the remainder of its
408-
time slice to any other thread that is ready to run. If there are no other
409-
threads ready to run, the function returns immediately, and the thread
410-
continues execution. On Windows 10 and newer the implementation uses
409+
On Windows, if *seconds* is zero,
410+
the thread relinquishes the remainder of its time slice
411+
to any other thread that is ready to run.
412+
If there are no other threads ready to run,
413+
the function returns immediately, and the thread continues execution.
414+
On Windows 10 and newer the implementation uses
411415
a `high-resolution timer
412416
<https://learn.microsoft.com/windows/win32/api/synchapi/nf-synchapi-createwaitabletimerexw>`_
413-
which provides resolution of 100 nanoseconds. If *secs* is zero, ``Sleep(0)`` is used.
417+
which provides resolution of 100 nanoseconds.
418+
If *seconds* is zero, ``Sleep(0)`` is used.
414419

415420
.. rubric:: Unix implementation
416421

@@ -425,12 +430,13 @@ Functions
425430
To voluntarily relinquish the CPU, specify a real-time :ref:`scheduling
426431
policy <os-scheduling-policy>` and use :func:`os.sched_yield` instead.
427432

428-
.. audit-event:: time.sleep secs
433+
.. audit-event:: time.sleep seconds
429434

430435
.. versionchanged:: 3.5
431-
The function now sleeps at least *secs* even if the sleep is interrupted
432-
by a signal, except if the signal handler raises an exception (see
433-
:pep:`475` for the rationale).
436+
The function now sleeps at least *seconds*
437+
even if the sleep is interrupted by a signal,
438+
except if the signal handler raises an exception
439+
(see :pep:`475` for the rationale).
434440

435441
.. versionchanged:: 3.11
436442
On Unix, the ``clock_nanosleep()`` and ``nanosleep()`` functions are now
@@ -445,13 +451,13 @@ Functions
445451
.. index::
446452
single: % (percent); datetime format
447453

448-
.. function:: strftime(format[, t])
454+
.. function:: strftime(format[, time_tuple])
449455

450456
Convert a tuple or :class:`struct_time` representing a time as returned by
451457
:func:`gmtime` or :func:`localtime` to a string as specified by the *format*
452-
argument. If *t* is not provided, the current time as returned by
458+
argument. If *time_tuple* is not provided, the current time as returned by
453459
:func:`localtime` is used. *format* must be a string. :exc:`ValueError` is
454-
raised if any field in *t* is outside of the allowed range.
460+
raised if any field in *time_tuple* is outside of the allowed range.
455461

456462
0 is a legal argument for any position in the time tuple; if it is normally
457463
illegal the value is forced to a correct one.

Include/internal/pycore_code.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ _PyLocals_GetKind(PyObject *kinds, int i)
205205
{
206206
assert(PyBytes_Check(kinds));
207207
assert(0 <= i && i < PyBytes_GET_SIZE(kinds));
208-
char *ptr = PyBytes_AS_STRING(kinds);
208+
const char *ptr = PyBytes_AS_STRING(kinds);
209209
return (_PyLocals_Kind)(ptr[i]);
210210
}
211211

Lib/asyncio/taskgroups.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ async def _aexit(self, et, exc):
140140
assert not self._tasks
141141

142142
if self._base_error is not None:
143+
# self._base_error (SystemExit or KeyboardInterrupt) is about
144+
# to propagate out of this method, which discards any other
145+
# collected task errors silently. Report them instead of
146+
# losing them. See gh-135736.
147+
for suppressed_exc in self._errors:
148+
self._loop.call_exception_handler({
149+
'message': 'TaskGroup task exception was not '
150+
'propagated because the TaskGroup body '
151+
'is being closed with a BaseException',
152+
'exception': suppressed_exc,
153+
'task_group': self,
154+
})
143155
try:
144156
raise self._base_error
145157
finally:

Lib/asyncio/tasks.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,9 @@ def _outer_done_callback(outer):
997997
# Keep only one callback to log on cancel
998998
inner.remove_done_callback(_log_on_exception)
999999
inner.add_done_callback(_log_on_exception)
1000+
if cur_task is not None:
1001+
inner.remove_done_callback(_clear_awaited_by_callback)
1002+
futures.future_discard_from_awaited_by(inner, cur_task)
10001003

10011004
if cur_task is not None:
10021005
inner.add_done_callback(_clear_awaited_by_callback)

Lib/imaplib.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ def _seq_range(item):
168168

169169

170170
def _format_sequence_set(arg):
171+
if isinstance(arg, (bytes, bytearray)):
172+
return str(arg, 'ascii')
171173
if isinstance(arg, (int, str)):
172174
return str(arg)
173175
# A sequence of message numbers and ranges.

Lib/test/test_asyncio/test_taskgroups.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,39 @@ async def runner():
608608
get_error_types(cm.exception), {MyBaseExc, ZeroDivisionError}
609609
)
610610

611+
async def test_taskgroup_20b(self):
612+
# Same setup as test_taskgroup_20 (a KeyboardInterrupt from the
613+
# "async with" body itself, alongside a sibling task's exception):
614+
# raising self._base_error out of _aexit() discards self._errors
615+
# silently. The sibling's exception can't be raised alongside
616+
# the KeyboardInterrupt (only one exception can propagate), but
617+
# it must be reported via the loop's exception handler instead
618+
# of being discarded silently. See gh-135736.
619+
async def crash_soon():
620+
await asyncio.sleep(0.1)
621+
1 / 0
622+
623+
async def nested():
624+
try:
625+
await asyncio.sleep(10)
626+
finally:
627+
raise KeyboardInterrupt
628+
629+
async def runner():
630+
async with taskgroups.TaskGroup() as g:
631+
g.create_task(crash_soon())
632+
await nested()
633+
634+
contexts = []
635+
loop = asyncio.get_running_loop()
636+
loop.set_exception_handler(lambda loop, context: contexts.append(context))
637+
638+
with self.assertRaises(KeyboardInterrupt):
639+
await runner()
640+
641+
self.assertEqual(len(contexts), 1)
642+
self.assertIsInstance(contexts[0]['exception'], ZeroDivisionError)
643+
611644
async def _test_taskgroup_21(self):
612645
# This test doesn't work as asyncio, currently, doesn't
613646
# correctly propagate KeyboardInterrupt (or SystemExit) --

Lib/test/test_asyncio/test_tasks.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,6 +2109,8 @@ def test_shield_cancel_outer(self):
21092109
test_utils.run_briefly(self.loop)
21102110
self.assertTrue(outer.cancelled())
21112111
self.assertEqual(0, 0 if outer._callbacks is None else len(outer._callbacks))
2112+
self.assertFalse(inner._asyncio_awaited_by)
2113+
self.assertTrue({f for f, _ctx in inner._callbacks or []} <= {asyncio.tasks._log_on_exception})
21122114

21132115
def test_shield_cancel_outer_result(self):
21142116
mock_handler = mock.Mock()
@@ -2134,6 +2136,21 @@ def test_shield_cancel_outer_exception(self):
21342136
test_utils.run_briefly(self.loop)
21352137
mock_handler.assert_called_once()
21362138

2139+
def test_shield_cancel_outer_in_task(self):
2140+
inner = self.new_future(self.loop)
2141+
2142+
async def coro():
2143+
outer = asyncio.shield(inner)
2144+
self.assertNotEqual(0, len(inner._callbacks))
2145+
outer.cancel()
2146+
await asyncio.sleep(0)
2147+
self.assertTrue(outer.cancelled())
2148+
2149+
task = self.new_task(self.loop, coro())
2150+
self.loop.run_until_complete(task)
2151+
self.assertFalse(inner._asyncio_awaited_by)
2152+
self.assertTrue({f for f, _ctx in inner._callbacks or []} <= {asyncio.tasks._log_on_exception})
2153+
21372154
def test_shield_duplicate_log_once(self):
21382155
mock_handler = mock.Mock()
21392156
self.loop.set_exception_handler(mock_handler)

Lib/test/test_capi/test_bytes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,16 @@ def test_create(self):
315315
self.assertEqual(writer.get_size(), 3)
316316
self.assertEqual(writer.finish(), self.result_type(b'abc'))
317317

318+
def test_finish_with_size(self):
319+
# Test PyBytesWriter_FinishWithSize()
318320
writer = self.create_writer(10, b'abc')
319321
self.assertEqual(writer.get_size(), 10)
320322
self.assertEqual(writer.finish_with_size(3), self.result_type(b'abc'))
321323

324+
writer = self.create_writer(3, b'abc')
325+
with self.assertRaises(SystemError):
326+
writer.finish_with_size(-3)
327+
322328
def test_write_bytes(self):
323329
# Test PyBytesWriter_WriteBytes()
324330
writer = self.create_writer()

0 commit comments

Comments
 (0)