Skip to content

Commit 2e3aa8a

Browse files
authored
Merge branch 'main' into 3.14-zstd-python-code
2 parents ac89532 + bb5ec6e commit 2e3aa8a

Some content is hidden

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

53 files changed

+560
-411
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/deprecations/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Deprecations
77

88
.. include:: pending-removal-in-3.17.rst
99

10+
.. include:: pending-removal-in-3.19.rst
11+
1012
.. include:: pending-removal-in-future.rst
1113

1214
C API deprecations
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Pending removal in Python 3.19
2+
------------------------------
3+
4+
* :mod:`ctypes`:
5+
6+
* Implicitly switching to the MSVC-compatible struct layout by setting
7+
:attr:`~ctypes.Structure._pack_` but not :attr:`~ctypes.Structure._layout_`
8+
on non-Windows platforms.

Doc/library/ctypes.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2754,6 +2754,16 @@ fields, or any other data types containing pointer type fields.
27542754
when :attr:`_fields_` is assigned, otherwise it will have no effect.
27552755
Setting this attribute to 0 is the same as not setting it at all.
27562756

2757+
This is only implemented for the MSVC-compatible memory layout.
2758+
2759+
.. deprecated-removed:: next 3.19
2760+
2761+
For historical reasons, if :attr:`!_pack_` is non-zero,
2762+
the MSVC-compatible layout will be used by default.
2763+
On non-Windows platforms, this default is deprecated and is slated to
2764+
become an error in Python 3.19.
2765+
If it is intended, set :attr:`~Structure._layout_` to ``'ms'``
2766+
explicitly.
27572767

27582768
.. attribute:: _align_
27592769

@@ -2782,12 +2792,15 @@ fields, or any other data types containing pointer type fields.
27822792
Currently the default will be:
27832793

27842794
- On Windows: ``"ms"``
2785-
- When :attr:`~Structure._pack_` is specified: ``"ms"``
2795+
- When :attr:`~Structure._pack_` is specified: ``"ms"``.
2796+
(This is deprecated; see :attr:`~Structure._pack_` documentation.)
27862797
- Otherwise: ``"gcc-sysv"``
27872798

27882799
:attr:`!_layout_` must already be defined when
27892800
:attr:`~Structure._fields_` is assigned, otherwise it will have no effect.
27902801

2802+
.. versionadded:: next
2803+
27912804
.. attribute:: _anonymous_
27922805

27932806
An optional sequence that lists the names of unnamed (anonymous) fields.

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/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/using/cmdline.rst

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,13 @@ Miscellaneous options
670670
.. versionchanged:: 3.10
671671
Removed the ``-X oldparser`` option.
672672

673+
.. versionremoved:: next
674+
675+
:option:`!-J` is no longer reserved for use by Jython_,
676+
and now has no special meaning.
677+
678+
.. _Jython: https://www.jython.org/
679+
673680
.. _using-on-controlling-color:
674681

675682
Controlling color
@@ -694,15 +701,6 @@ output. To control the color output only in the Python interpreter, the
694701
precedence over ``NO_COLOR``, which in turn takes precedence over
695702
``FORCE_COLOR``.
696703

697-
Options you shouldn't use
698-
~~~~~~~~~~~~~~~~~~~~~~~~~
699-
700-
.. option:: -J
701-
702-
Reserved for use by Jython_.
703-
704-
.. _Jython: https://www.jython.org/
705-
706704

707705
.. _using-on-envvars:
708706

Doc/whatsnew/2.6.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ Interpreter Changes
17471747
-------------------------------
17481748

17491749
Two command-line options have been reserved for use by other Python
1750-
implementations. The :option:`-J` switch has been reserved for use by
1750+
implementations. The :option:`!-J` switch has been reserved for use by
17511751
Jython for Jython-specific options, such as switches that are passed to
17521752
the underlying JVM. :option:`-X` has been reserved for options
17531753
specific to a particular implementation of Python such as CPython,

Doc/whatsnew/3.14.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,11 @@ Other language changes
805805
:keyword:`async with`).
806806
(Contributed by Bénédikt Tran in :gh:`128398`.)
807807

808+
* :option:`!-J` is no longer a reserved flag for Jython_,
809+
and now has no special meaning.
810+
(Contributed by Adam Turner in :gh:`133336`.)
811+
812+
.. _Jython: https://www.jython.org/
808813

809814
.. _whatsnew314-pep765:
810815

@@ -1436,6 +1441,11 @@ pdb
14361441
function.
14371442
(Contributed by Tian Gao in :gh:`132576`.)
14381443

1444+
* Source code displayed in :mod:`pdb` will be syntax-highlighted. This feature
1445+
can be controlled using the same methods as PyREPL, in addition to the newly
1446+
added ``colorize`` argument of :class:`pdb.Pdb`.
1447+
(Contributed by Tian Gao in :gh:`133355`.)
1448+
14391449

14401450
pickle
14411451
------
@@ -1869,6 +1879,12 @@ Deprecated
18691879
:func:`codecs.open` is now deprecated. Use :func:`open` instead.
18701880
(Contributed by Inada Naoki in :gh:`133036`.)
18711881

1882+
* :mod:`ctypes`:
1883+
On non-Windows platforms, setting :attr:`.Structure._pack_` to use a
1884+
MSVC-compatible default memory layout is deprecated in favor of setting
1885+
:attr:`.Structure._layout_` to ``'ms'``.
1886+
(Contributed by Petr Viktorin in :gh:`131747`.)
1887+
18721888
* :mod:`ctypes`:
18731889
Calling :func:`ctypes.POINTER` on a string is deprecated.
18741890
Use :ref:`ctypes-incomplete-types` for self-referential structures.
@@ -1943,6 +1959,8 @@ Deprecated
19431959

19441960
.. include:: ../deprecations/pending-removal-in-3.17.rst
19451961

1962+
.. include:: ../deprecations/pending-removal-in-3.19.rst
1963+
19461964
.. include:: ../deprecations/pending-removal-in-future.rst
19471965

19481966
Removed

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)