Skip to content

Commit e7afd4e

Browse files
authored
Merge branch 'main' into fix-ctypes-Zf_set_sw
2 parents bb3fd9e + e56f86f commit e7afd4e

23 files changed

Lines changed: 574 additions & 211 deletions

Doc/c-api/marshal.rst

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ Numeric values are stored with the least significant byte first.
1616
The module supports several versions of the data format; see
1717
the :py:mod:`Python module documentation <marshal>` for details.
1818

19+
The following exceptions can be raised by these functions:
20+
:exc:`ValueError` if the value cannot be marshalled,
21+
:exc:`ValueError` or :exc:`TypeError` if the data is malformed,
22+
:exc:`EOFError` if the end of the data is reached before the value is complete,
23+
:exc:`OSError` if reading from or writing to a :c:expr:`FILE*` fails,
24+
:exc:`KeyboardInterrupt` if reading or writing is interrupted by a signal,
25+
and :exc:`MemoryError` if memory allocation fails.
26+
27+
.. versionchanged:: next
28+
Previously, in functions taking a :c:expr:`FILE*`,
29+
the reading functions raised :exc:`EOFError`
30+
instead of :exc:`OSError` and :exc:`KeyboardInterrupt`,
31+
and the writing functions ignored I/O errors and interruptions.
32+
1933
.. c:macro:: Py_MARSHAL_VERSION
2034
2135
The current format version. See :py:data:`marshal.version`.
@@ -42,6 +56,8 @@ the :py:mod:`Python module documentation <marshal>` for details.
4256
Return a bytes object containing the marshalled representation of *value*.
4357
*version* indicates the file format.
4458
59+
On error, raises an exception and returns ``NULL``.
60+
4561
4662
The following functions allow marshalled values to be read back in.
4763
@@ -52,8 +68,7 @@ The following functions allow marshalled values to be read back in.
5268
for reading. Only a 32-bit value can be read in using this function,
5369
regardless of the native size of :c:expr:`long`.
5470
55-
On error, sets the appropriate exception (:exc:`EOFError`) and returns
56-
``-1``.
71+
On error, raises an exception and returns ``-1``.
5772
5873
5974
.. c:function:: int PyMarshal_ReadShortFromFile(FILE *file)
@@ -62,17 +77,15 @@ The following functions allow marshalled values to be read back in.
6277
for reading. Only a 16-bit value can be read in using this function,
6378
regardless of the native size of :c:expr:`short`.
6479
65-
On error, sets the appropriate exception (:exc:`EOFError`) and returns
66-
``-1``.
80+
On error, raises an exception and returns ``-1``.
6781
6882
6983
.. c:function:: PyObject* PyMarshal_ReadObjectFromFile(FILE *file)
7084
7185
Return a Python object from the data stream in a :c:expr:`FILE*` opened for
7286
reading.
7387
74-
On error, sets the appropriate exception (:exc:`EOFError`, :exc:`ValueError`
75-
or :exc:`TypeError`) and returns ``NULL``.
88+
On error, raises an exception and returns ``NULL``.
7689
7790
7891
.. c:function:: PyObject* PyMarshal_ReadLastObjectFromFile(FILE *file)
@@ -85,15 +98,13 @@ The following functions allow marshalled values to be read back in.
8598
file. Only use this variant if you are certain that you won't be reading
8699
anything else from the file.
87100
88-
On error, sets the appropriate exception (:exc:`EOFError`, :exc:`ValueError`
89-
or :exc:`TypeError`) and returns ``NULL``.
101+
On error, raises an exception and returns ``NULL``.
90102
91103
92104
.. c:function:: PyObject* PyMarshal_ReadObjectFromString(const char *data, Py_ssize_t len)
93105
94106
Return a Python object from the data stream in a byte buffer
95107
containing *len* bytes pointed to by *data*.
96108
97-
On error, sets the appropriate exception (:exc:`EOFError`, :exc:`ValueError`
98-
or :exc:`TypeError`) and returns ``NULL``.
109+
On error, raises an exception and returns ``NULL``.
99110

Doc/library/difflib.rst

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Diff generation
128128

129129
The :class:`Differ` class has this constructor:
130130

131-
.. method:: __init__(linejunk=None, charjunk=None)
131+
.. method:: __init__(linejunk=None, charjunk=None, autojunk=True)
132132

133133
Optional keyword parameters *linejunk* and *charjunk* are for filter functions
134134
(or ``None``):
@@ -147,6 +147,14 @@ Diff generation
147147
:meth:`~SequenceMatcher.find_longest_match` method's *isjunk*
148148
parameter for an explanation.
149149

150+
Setting the optional *autojunk* argument to ``False`` will turn
151+
:ref:`automatic junk heuristic <difflib-junk>` off.
152+
153+
.. versionchanged:: 3.16
154+
Added keyword-only *autojunk* parameter.
155+
156+
157+
150158
:class:`Differ` objects are used (deltas generated) via a single method:
151159

152160

@@ -161,6 +169,8 @@ Diff generation
161169
printed as-is via the :meth:`~io.IOBase.writelines` method of a
162170
file-like object.
163171

172+
173+
164174
.. class:: HtmlDiff
165175

166176
This class can be used to create an HTML table (or a complete HTML file
@@ -176,7 +186,7 @@ Diff generation
176186
The constructor for this class is:
177187

178188

179-
.. method:: __init__(tabsize=8, wrapcolumn=None, linejunk=None, charjunk=IS_CHARACTER_JUNK)
189+
.. method:: __init__(tabsize=8, wrapcolumn=None, linejunk=None, charjunk=IS_CHARACTER_JUNK, *, autojunk=True)
180190

181191
Initializes instance of :class:`HtmlDiff`.
182192

@@ -187,8 +197,15 @@ Diff generation
187197
broken and wrapped, defaults to ``None`` where lines are not wrapped.
188198

189199
*linejunk* and *charjunk* are optional keyword arguments passed into :func:`ndiff`
190-
(used by :class:`HtmlDiff` to generate the side by side HTML differences). See
191-
:func:`ndiff` documentation for argument default values and descriptions.
200+
(used by :class:`HtmlDiff` to generate the side by side HTML differences).
201+
See :func:`ndiff` documentation for argument default values and descriptions.
202+
203+
Setting the optional *autojunk* argument to ``False`` will turn
204+
:ref:`automatic junk heuristic <difflib-junk>` off.
205+
206+
.. versionchanged:: 3.16
207+
Added keyword-only *autojunk* parameter.
208+
192209

193210
The following methods are public:
194211

@@ -231,7 +248,7 @@ Diff generation
231248

232249

233250

234-
.. function:: context_diff(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n')
251+
.. function:: context_diff(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n', *, autojunk=True)
235252

236253
Compare *a* and *b* (lists of strings); return a delta (a :term:`generator`
237254
generating the delta lines) in context diff format.
@@ -277,8 +294,14 @@ Diff generation
277294

278295
See :ref:`difflib-interface` for a more detailed example.
279296

297+
Setting the optional *autojunk* argument to ``False`` will turn
298+
:ref:`automatic junk heuristic <difflib-junk>` off.
299+
300+
.. versionchanged:: 3.16
301+
Added keyword-only *autojunk* parameter.
280302

281-
.. function:: get_close_matches(word, possibilities, n=3, cutoff=0.6)
303+
304+
.. function:: get_close_matches(word, possibilities, n=3, cutoff=0.6, *, autojunk=True)
282305

283306
Return a list of the best "good enough" matches. *word* is a sequence for which
284307
close matches are desired (typically a string), and *possibilities* is a list of
@@ -290,6 +313,9 @@ Diff generation
290313
Optional argument *cutoff* (default ``0.6``) is a float in the range [0, 1].
291314
Possibilities that don't score at least that similar to *word* are ignored.
292315

316+
Setting the optional *autojunk* argument to ``False`` will turn
317+
:ref:`automatic junk heuristic <difflib-junk>` off.
318+
293319
The best (no more than *n*) matches among the possibilities are returned in a
294320
list, sorted by similarity score, most similar first.
295321

@@ -303,8 +329,11 @@ Diff generation
303329
>>> get_close_matches('accept', keyword.kwlist)
304330
['except']
305331

332+
.. versionchanged:: 3.16
333+
Added keyword-only *autojunk* parameter.
334+
306335

307-
.. function:: ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK)
336+
.. function:: ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK, *, autojunk=True)
308337

309338
Compare *a* and *b* (lists of strings); return a :class:`Differ`\ -style
310339
delta (a :term:`generator` generating the delta lines).
@@ -325,6 +354,11 @@ Diff generation
325354
function :func:`IS_CHARACTER_JUNK`, which filters out whitespace characters (a
326355
blank or tab; it's a bad idea to include newline in this!).
327356

357+
Setting the optional *autojunk* argument to ``False`` will turn
358+
:ref:`automatic junk heuristic <difflib-junk>` off.
359+
360+
Example:
361+
328362
>>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True),
329363
... 'ore\ntree\nemu\n'.splitlines(keepends=True))
330364
>>> print(''.join(diff), end="")
@@ -338,6 +372,9 @@ Diff generation
338372
+ tree
339373
+ emu
340374

375+
.. versionchanged:: 3.16
376+
Added keyword-only *autojunk* parameter.
377+
341378

342379
.. function:: restore(sequence, which)
343380

@@ -362,7 +399,7 @@ Diff generation
362399
emu
363400

364401

365-
.. function:: unified_diff(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n', *, color=False)
402+
.. function:: unified_diff(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n', *, autojunk=True, color=False)
366403

367404
Compare *a* and *b* (lists of strings); return a delta (a :term:`generator`
368405
generating the delta lines) in unified diff format.
@@ -410,6 +447,12 @@ Diff generation
410447
.. versionchanged:: 3.15
411448
Added the *color* parameter.
412449

450+
Setting the optional *autojunk* argument to ``False`` will turn
451+
:ref:`automatic junk heuristic <difflib-junk>` off.
452+
453+
.. versionchanged:: 3.16
454+
Added keyword-only *autojunk* parameter.
455+
413456

414457
.. function:: diff_bytes(dfunc, a, b, fromfile=b'', tofile=b'', fromfiledate=b'', tofiledate=b'', n=3, lineterm=b'\n')
415458

Doc/library/sys.rst

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,11 +1488,24 @@ always available. Unless explicitly noted otherwise, all variables are read-only
14881488
.. data:: lazy_modules
14891489

14901490
A :class:`set` of fully qualified module name strings that have been lazily
1491-
imported in the current interpreter but not yet loaded. When a
1492-
lazily imported module is accessed for the first time, its name is removed
1493-
from this set.
1491+
imported in the current interpreter but not yet loaded.
1492+
When a lazily imported module is accessed for the first time, its name is
1493+
typically removed from this set.
14941494

1495-
This attribute is intended for debugging and introspection.
1495+
The set may contain some additional strings.
1496+
It is intended for debugging and introspection, and consumers are expected
1497+
to verify each entry's status.
1498+
1499+
.. impl-detail::
1500+
1501+
Currently, :data:`!lazy_modules` may also contain:
1502+
1503+
* names of *attributes* (non-modules), such as ``"pathlib.Path"`` after
1504+
running ``lazy from pathlib import Path``, and
1505+
* names of items than have already been accessed.
1506+
1507+
In future versions of Python, these may be removed, and/or additional
1508+
extras may be added.
14961509

14971510
See also :func:`set_lazy_imports` and :pep:`810`.
14981511

Doc/whatsnew/3.15.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,13 @@ Default interactive shell
902902
<using-on-controlling-color>`.
903903
(Contributed by Antonio Cuni and Pablo Galindo in :gh:`130472`.)
904904

905+
* Tab completion now suggests module attributes in ``from ... import`` statements.
906+
Attributes can only be suggested once the module is imported, so
907+
:term:`stdlib` modules are imported automatically, while for
908+
other modules the completer offers to import them when :kbd:`Tab`
909+
is pressed a second time.
910+
(Contributed by Loïc Simon and Pablo Galindo in :gh:`140870`.)
911+
905912

906913
New modules
907914
===========
@@ -2114,6 +2121,17 @@ http.server
21142121
(Contributed by Bénédikt Tran in :gh:`133810`.)
21152122

21162123

2124+
importlib
2125+
---------
2126+
2127+
* The ``load_module()`` methods of :class:`~importlib.abc.Loader` and its
2128+
subclasses is removed.
2129+
The import system will no longer call it when defined on custom subclasses.
2130+
The method has been deprecated in favor of
2131+
:meth:`~importlib.abc.Loader.exec_module` since Python 3.4.
2132+
(Contributed by Brett Cannon in :gh:`97850`.)
2133+
2134+
21172135
importlib.resources
21182136
-------------------
21192137

Doc/whatsnew/3.16.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,37 @@ curses
304304
(Contributed by Serhiy Storchaka in :gh:`133031`.)
305305

306306

307+
ctypes
308+
------
309+
310+
* Add :func:`ctypes.util.struct` for generating :class:`~ctypes.Structure` types
311+
from an annotation-based syntax, similar to how the :mod:`dataclasses` module
312+
is used.
313+
(Contributed by Peter Bierma in :gh:`104533`.)
314+
* Add :func:`ctypes.util.wrap_dll_function` for generating function pointers
315+
through a function signature.
316+
(Contributed by Peter Bierma in :gh:`153903`.)
317+
318+
319+
concurrent.futures
320+
------------------
321+
322+
* The iterator returned by :meth:`concurrent.futures.Executor.map` is no longer
323+
automatically closed if a function call raises an exception.
324+
Use method :meth:`!close` to explicitly close the iterator.
325+
(Contributed by xzmeng and Serhiy Storchaka in :gh:`108518`.)
326+
327+
328+
difflib
329+
-------
330+
331+
* Expose optional ``autojunk`` parameter from :class:`difflib.SequenceMatcher`
332+
to public functions and class methods in :mod:`difflib`,
333+
allowing to modify behavior of automatic junk heuristic in this module
334+
in higher public class methods and functions.
335+
(Contributed by Tomasz Kazimierczak in :gh:`118150`)
336+
337+
307338
encodings
308339
---------
309340

@@ -956,6 +987,20 @@ Porting to Python 3.16
956987
* :c:func:`PyType_ClearCache` is now a no-op as the type cache is now
957988
implemented per-type. It still returns the current version tag.
958989

990+
* Functions reading marshalled data from a :c:expr:`FILE*`,
991+
such as :c:func:`PyMarshal_ReadObjectFromFile`,
992+
now raise :exc:`OSError` for I/O errors
993+
and :exc:`KeyboardInterrupt` for interrupted reading,
994+
instead of :exc:`EOFError`.
995+
(Contributed by Serhiy Storchaka in :gh:`155907`.)
996+
997+
* :c:func:`PyMarshal_WriteLongToFile` and :c:func:`PyMarshal_WriteObjectToFile`
998+
now set the error indicator for I/O errors and interrupted writing,
999+
instead of ignoring them.
1000+
:c:func:`PyMarshal_WriteObjectToFile` now also sets the error indicator
1001+
if the value cannot be marshalled.
1002+
(Contributed by Serhiy Storchaka in :gh:`155907`.)
1003+
9591004
Deprecated C APIs
9601005
-----------------
9611006

0 commit comments

Comments
 (0)