8000 Merge branch 'main' into array_subscr · python/cpython@d8b5848 · GitHub
[go: up one dir, main page]

Skip to content

Commit d8b5848

Browse files
authored
Merge branch 'main' into array_subscr
2 parents 0190ecf + f554237 commit d8b5848

Some content is hidden

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

65 files changed

+1569
-643
lines changed

.github/workflows/reusable-context.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ jobs:
9797
run: python Tools/build/compute-changes.py
9898
env:
9999
GITHUB_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
100+
CCF_TARGET_REF: ${{ github.base_ref || github.event.repository.default_branch }}
101+
CCF_HEAD_REF: ${{ github.event.pull_request.head.sha || github.sha }}
100102

101103
- name: Compute hash for config cache key
102104
id: config-hash

Doc/library/annotationlib.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Classes
132132

133133
Values are real annotation values (as per :attr:`Format.VALUE` format)
134134
for defined values, and :class:`ForwardRef` proxies for undefined
135-
values. Real objects may contain references to, :class:`ForwardRef`
135+
values. Real objects may contain references to :class:`ForwardRef`
136136
proxy objects.
137137

138138
.. attribute:: STRING
@@ -172,14 +172,21 @@ Classes
172172
:class:`~ForwardRef`. The string may not be exactly equivalent
173173
to the original source.
174174

175-
.. method:: evaluate(*, owner=None, globals=None, locals=None, type_params=None)
175+
.. method:: evaluate(*, owner=None, globals=None, locals=None, type_params=None, format=Format.VALUE)
176176

177177
Evaluate the forward reference, returning its value.
178178

179-
This may throw an exception, such as :exc:`NameError`, if the forward
179+
If the *format* argument is :attr:`~Format.VALUE` (the default),
180+
this method may throw an exception, such as :exc:`NameError`, if the forward
180181
reference refers to a name that cannot be resolved. The arguments to this
181182
method can be used to provide bindings for names that would otherwise
182-
be undefined.
183+
be undefined. If the *format* argument is :attr:`~Format.FORWARDREF`,
184+
the method will never throw an exception, but may return a :class:`~ForwardRef`
185+
instance. For example, if the forward reference object contains the code
186+
``list[undefined]``, where ``undefined`` is a name that is not defined,
187+
evaluating it with the :attr:`~Format.FORWARDREF` format will return
188+
``list[ForwardRef('undefined')]``. If the *format* argument is
189+
:attr:`~Format.STRING`, the method will return :attr:`~ForwardRef.__forward_arg__`.
183190

184191
The *owner* parameter provides the preferred mechanism for passing scope
185192
information to this method. The owner of a :class:`~ForwardRef` is the

Doc/library/asyncio-eventloop.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ Creating Futures and Tasks
361361

362362
.. versionadded:: 3.5.2
363363

364-
.. method:: loop.create_task(coro, *, name=None, context=None)
364+
.. method:: loop.create_task(coro, *, name=None, context=None, eager_start=None)
365365

366366
Schedule the execution of :ref:`coroutine <coroutine>` *coro*.
367367
Return a :class:`Task` object.
@@ -377,12 +377,20 @@ Creating Futures and Tasks
377377
custom :class:`contextvars.Context` for the *coro* to run in.
378378
The current context copy is created when no *context* is provided.
379379

380+
An optional keyword-only *eager_start* argument allows specifying
381+
if the task should execute eagerly during the call to create_task,
382+
or be scheduled later. If *eager_start* is not passed the mode set
383+
by :meth:`loop.set_task_factory` will be used.
384+
380385
.. versionchanged:: 3.8
381386
Added the *name* parameter.
382387

383388
.. versionchanged:: 3.11
384389
Added the *context* parameter.
385390

391+
.. versionchanged:: next
392+
Added the *eager_start* parameter.
393+
386394
.. method:: loop.set_task_factory(factory)
387395

388396
Set a task factory that will be used by

Doc/library/pdb.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ The ``run*`` functions and :func:`set_trace` are aliases for instantiating the
243243
access further features, you have to do this yourself:
244244

245245
.. class:: Pdb(completekey='tab', stdin=None, stdout=None, skip=None, \
246-
nosigint=False, readrc=True, mode=None, backend=None)
246+
nosigint=False, readrc=True, mode=None, backend=None, colorize=False)
247247

248248
:class:`Pdb` is the debugger class.
249249

@@ -273,6 +273,9 @@ access further features, you have to do this yourself:
273273
is passed, the default backend will be used. See :func:`set_default_backend`.
274274
Otherwise the supported backends are ``'settrace'`` and ``'monitoring'``.
275275

276+
The *colorize* argument, if set to ``True``, will enable colorized output in the
277+
debugger, if color is supported. This will highlight source code displayed in pdb.
278+
276279
Example call to enable tracing with *skip*::
277280

278281
import pdb; pdb.Pdb(skip=['django.*']).set_trace()
@@ -295,6 +298,9 @@ access further features, you have to do this yourself:
295298
.. versionadded:: 3.14
296299
Added the *backend* argument.
297300

301+
.. versionadded:: 3.14
302+
Added the *colorize* argument.
303+
298304
.. versionchanged:: 3.14
299305
Inline breakpoints like :func:`breakpoint` or :func:`pdb.set_trace` will
300306
always stop the program at calling frame, ignoring the *skip* pattern (if any).

Doc/library/subprocess.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,24 @@ handling consistency are valid for these functions.
15251525
Notes
15261526
-----
15271527

1528+
.. _subprocess-timeout-behavior:
1529+
1530+
Timeout Behavior
1531+
^^^^^^^^^^^^^^^^
1532+
1533+
When using the ``timeout`` parameter in functions like :func:`run`,
1534+
:meth:`Popen.wait`, or :meth:`Popen.communicate`,
1535+
users should be aware of the following behaviors:
1536+
1537+
1. **Process Creation Delay**: The initial process creation itself cannot be interrupted
1538+
on many platform APIs. This means that even when specifying a timeout, you are not
1539+
guaranteed to see a timeout exception until at least after however long process
1540+
creation takes.
1541+
1542+
2. **Extremely Small Timeout Values**: Setting very small timeout values (such as a few
1543+
milliseconds) may result in almost immediate :exc:`TimeoutExpired` exceptions because
1544+
process creation and system scheduling inherently require time.
1545+
15281546
.. _converting-argument-sequence:
15291547

15301548
Converting an argument sequence to a string on Windows

Doc/library/threading.rst

Lines changed: 118 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,23 +260,132 @@ All of the methods described below are executed atomically.
260260
Thread-Local Data
261261
-----------------
262262

263-
Thread-local data is data whose values are thread specific. To manage
264-
thread-local data, just create an instance of :class:`local` (or a
265-
subclass) and store attributes on it::
263+
Thread-local data is data whose values are thread specific. If you
264+
have data that you want to be local to a thread, create a
265+
:class:`local` object and use its attributes::
266266

267-
mydata = threading.local()
268-
mydata.x = 1
267+
>>> mydata = local()
268+
>>> mydata.number = 42
269+
>>> mydata.number
270+
42
269271

270-
The instance's values will be different for separate threads.
272+
You can also access the :class:`local`-object's dictionary::
273+
274+
>>> mydata.__dict__
275+
{'number': 42}
276+
>>> mydata.__dict__.setdefault('widgets', [])
277+
[]
278+
>>> mydata.widgets
279+
[]
280+
281+
If we access the data in a different thread::
282+
283+
>>> log = []
284+
>>> def f():
285+
... items = sorted(mydata.__dict__.items())
286+
... log.append(items)
287+
... mydata.number = 11
288+
... log.append(mydata.number)
289+
290+
>>> import threading
291+
>>> thread = threading.Thread(target=f)
292+
>>> thread.start()
293+
>>> thread.join()
294+
>>> log
295+
[[], 11]
296+
297+
we get different data. Furthermore, changes made in the other thread
298+
don't affect data seen in this thread::
299+
300+
>>> mydata.number
301+
42
302+
303+
Of course, values you get from a :class:`local` object, including their
304+
:attr:`~object.__dict__` attribute, are for whatever thread was current
305+
at the time the attribute was read. For that reason, you generally
306+
don't want to save these values across threads, as they apply only to
307+
the thread they came from.
308+
309+
You can create custom :class:`local` objects by subclassing the
310+
:class:`local` class::
311+
312+
>>> class MyLocal(local):
313+
... number = 2
314+
... def __init__(self, /, **kw):
315+
... self.__dict__.update(kw)
316+
... def squared(self):
317+
... return self.number ** 2
318+
319+
This can be useful to support default values, methods and
320+
initialization. Note that if you define an :py:meth:`~object.__init__`
321+
method, it will be called each time the :class:`local` object is used
322+
in a separate thread. This is necessary to initialize each thread's
323+
dictionary.
324+
325+
Now if we create a :class:`local` object::
326+
327+
>>> mydata = MyLocal(color='red')
328+
329+
we have a default number::
330+
331+
>>> mydata.number
332+
2
333+
334+
an initial color::
335+
336+
>>> mydata.color
337+
'red'
338+
>>> del mydata.color
339+
340+
And a method that operates on the data::
341+
342+
>>> mydata.squared()
343+
4
344+
345+
As before, we can access the data in a separate thread::
346+
347+
>>> log = []
348+
>>> thread = threading.Thread(target=f)
349+
>>> thread.start()
350+
>>> thread.join()
351+
>>> log
352+
[[('color', 'red')], 11]
353+
354+
without affecting this thread's data::
355+
356+
>>> mydata.number
357+
2
358+
>>> mydata.color
359+
Traceback (most recent call last):
360+
...
361+
AttributeError: 'MyLocal' object has no attribute 'color'
362+
363+
Note that subclasses can define :term:`__slots__`, but they are not
364+
thread local. They are shared across threads::
365+
366+
>>> class MyLocal(local):
367+
... __slots__ = 'number'
368+
369+
>>> mydata = MyLocal()
370+
>>> mydata.number = 42
371+
>>> mydata.color = 'red'
372+
373+
So, the separate thread::
374+
375+
>>> thread = threading.Thread(target=f)
376+
>>> thread.start()
377+
>>> thread.join()
378+
379+
affects what we see::
380+
381+
>>> mydata.number
382+
11
271383

272384

273385
.. class:: local()
274386

275387
A class that represents thread-local data.
276388

277-
For more details and extensive examples, see the documentation string of the
278-
:mod:`!_threading_local` module: :source:`Lib/_threading_local.py`.
279-
280389

281390
.. _thread-objects:
282391

Doc/whatsnew/3.14.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,11 @@ pdb
14361436
function.
14371437
(Contributed by Tian Gao in :gh:`132576`.)
14381438

1439+
* Source code displayed in :mod:`pdb` will be syntax-highlighted. This feature
1440+
can be controlled using the same methods as PyREPL, in addition to the newly
1441+
added ``colorize`` argument of :class:`pdb.Pdb`.
1442+
(Contributed by Tian Gao in :gh:`133355`.)
1443+
14391444

14401445
pickle
14411446
------

Include/internal/pycore_magic_number.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ Known values:
276276
Python 3.14a7 3621 (Optimize LOAD_FAST opcodes into LOAD_FAST_BORROW)
277277
Python 3.14a7 3622 (Store annotations in different class dict keys)
278278
Python 3.14a7 3623 (Add BUILD_INTERPOLATION & BUILD_TEMPLATE opcodes)
279+
Python 3.14b1 3624 (Don't optimize LOAD_FAST when local is killed by DELETE_FAST)
279280
280281
Python 3.15 will start with 3650
281282
@@ -288,7 +289,7 @@ PC/launcher.c must also be updated.
288289
289290
*/
290291

291-
#define PYC_MAGIC_NUMBER 3623
292+
#define PYC_MAGIC_NUMBER 3624
292293
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
293294
(little-endian) and then appending b'\r\n'. */
294295
#define PYC_MAGIC_NUMBER_TOKEN \

Lib/_pyrepl/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def do(self) -> None:
439439
import _sitebuiltins
440440

441441
with self.reader.suspend():
442-
self.reader.msg = _sitebuiltins._Helper()() # type: ignore[assignment, call-arg]
442+
self.reader.msg = _sitebuiltins._Helper()() # type: ignore[assignment]
443443

444444

445445
class invalid_key(Command):

0 commit comments

Comments
 (0)
0