Skip to content
Merged
31 changes: 21 additions & 10 deletions Doc/c-api/marshal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ Numeric values are stored with the least significant byte first.
The module supports several versions of the data format; see
the :py:mod:`Python module documentation <marshal>` for details.

The following exceptions can be raised by these functions:
:exc:`ValueError` if the value cannot be marshalled,
:exc:`ValueError` or :exc:`TypeError` if the data is malformed,
:exc:`EOFError` if the end of the data is reached before the value is complete,
:exc:`OSError` if reading from or writing to a :c:expr:`FILE*` fails,
:exc:`KeyboardInterrupt` if reading or writing is interrupted by a signal,
and :exc:`MemoryError` if memory allocation fails.

.. versionchanged:: next
Previously, in functions taking a :c:expr:`FILE*`,
the reading functions raised :exc:`EOFError`
instead of :exc:`OSError` and :exc:`KeyboardInterrupt`,
and the writing functions ignored I/O errors and interruptions.

.. c:macro:: Py_MARSHAL_VERSION

The current format version. See :py:data:`marshal.version`.
Expand All @@ -42,6 +56,8 @@ the :py:mod:`Python module documentation <marshal>` for details.
Return a bytes object containing the marshalled representation of *value*.
*version* indicates the file format.

On error, raises an exception and returns ``NULL``.


The following functions allow marshalled values to be read back in.

Expand All @@ -52,8 +68,7 @@ The following functions allow marshalled values to be read back in.
for reading. Only a 32-bit value can be read in using this function,
regardless of the native size of :c:expr:`long`.

On error, sets the appropriate exception (:exc:`EOFError`) and returns
``-1``.
On error, raises an exception and returns ``-1``.


.. c:function:: int PyMarshal_ReadShortFromFile(FILE *file)
Expand All @@ -62,17 +77,15 @@ The following functions allow marshalled values to be read back in.
for reading. Only a 16-bit value can be read in using this function,
regardless of the native size of :c:expr:`short`.

On error, sets the appropriate exception (:exc:`EOFError`) and returns
``-1``.
On error, raises an exception and returns ``-1``.


.. c:function:: PyObject* PyMarshal_ReadObjectFromFile(FILE *file)

Return a Python object from the data stream in a :c:expr:`FILE*` opened for
reading.

On error, sets the appropriate exception (:exc:`EOFError`, :exc:`ValueError`
or :exc:`TypeError`) and returns ``NULL``.
On error, raises an exception and returns ``NULL``.


.. c:function:: PyObject* PyMarshal_ReadLastObjectFromFile(FILE *file)
Expand All @@ -85,15 +98,13 @@ The following functions allow marshalled values to be read back in.
file. Only use this variant if you are certain that you won't be reading
anything else from the file.

On error, sets the appropriate exception (:exc:`EOFError`, :exc:`ValueError`
or :exc:`TypeError`) and returns ``NULL``.
On error, raises an exception and returns ``NULL``.


.. c:function:: PyObject* PyMarshal_ReadObjectFromString(const char *data, Py_ssize_t len)

Return a Python object from the data stream in a byte buffer
containing *len* bytes pointed to by *data*.

On error, sets the appropriate exception (:exc:`EOFError`, :exc:`ValueError`
or :exc:`TypeError`) and returns ``NULL``.
On error, raises an exception and returns ``NULL``.

59 changes: 51 additions & 8 deletions Doc/library/difflib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Diff generation

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

.. method:: __init__(linejunk=None, charjunk=None)
.. method:: __init__(linejunk=None, charjunk=None, autojunk=True)

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

Setting the optional *autojunk* argument to ``False`` will turn
:ref:`automatic junk heuristic <difflib-junk>` off.

.. versionchanged:: 3.16
Added keyword-only *autojunk* parameter.



:class:`Differ` objects are used (deltas generated) via a single method:


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



.. class:: HtmlDiff

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


.. method:: __init__(tabsize=8, wrapcolumn=None, linejunk=None, charjunk=IS_CHARACTER_JUNK)
.. method:: __init__(tabsize=8, wrapcolumn=None, linejunk=None, charjunk=IS_CHARACTER_JUNK, *, autojunk=True)

Initializes instance of :class:`HtmlDiff`.

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

*linejunk* and *charjunk* are optional keyword arguments passed into :func:`ndiff`
(used by :class:`HtmlDiff` to generate the side by side HTML differences). See
:func:`ndiff` documentation for argument default values and descriptions.
(used by :class:`HtmlDiff` to generate the side by side HTML differences).
See :func:`ndiff` documentation for argument default values and descriptions.

Setting the optional *autojunk* argument to ``False`` will turn
:ref:`automatic junk heuristic <difflib-junk>` off.

.. versionchanged:: 3.16
Added keyword-only *autojunk* parameter.


The following methods are public:

Expand Down Expand Up @@ -231,7 +248,7 @@ Diff generation



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

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

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

Setting the optional *autojunk* argument to ``False`` will turn
:ref:`automatic junk heuristic <difflib-junk>` off.

.. versionchanged:: 3.16
Added keyword-only *autojunk* parameter.

.. function:: get_close_matches(word, possibilities, n=3, cutoff=0.6)

.. function:: get_close_matches(word, possibilities, n=3, cutoff=0.6, *, autojunk=True)

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

Setting the optional *autojunk* argument to ``False`` will turn
:ref:`automatic junk heuristic <difflib-junk>` off.

The best (no more than *n*) matches among the possibilities are returned in a
list, sorted by similarity score, most similar first.

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

.. versionchanged:: 3.16
Added keyword-only *autojunk* parameter.


.. function:: ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK)
.. function:: ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK, *, autojunk=True)

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

Setting the optional *autojunk* argument to ``False`` will turn
:ref:`automatic junk heuristic <difflib-junk>` off.

Example:

>>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True),
... 'ore\ntree\nemu\n'.splitlines(keepends=True))
>>> print(''.join(diff), end="")
Expand All @@ -338,6 +372,9 @@ Diff generation
+ tree
+ emu

.. versionchanged:: 3.16
Added keyword-only *autojunk* parameter.


.. function:: restore(sequence, which)

Expand All @@ -362,7 +399,7 @@ Diff generation
emu


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

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

Setting the optional *autojunk* argument to ``False`` will turn
:ref:`automatic junk heuristic <difflib-junk>` off.

.. versionchanged:: 3.16
Added keyword-only *autojunk* parameter.


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

Expand Down
21 changes: 17 additions & 4 deletions Doc/library/sys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1488,11 +1488,24 @@ always available. Unless explicitly noted otherwise, all variables are read-only
.. data:: lazy_modules

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

This attribute is intended for debugging and introspection.
The set may contain some additional strings.
It is intended for debugging and introspection, and consumers are expected
to verify each entry's status.

.. impl-detail::

Currently, :data:`!lazy_modules` may also contain:

* names of *attributes* (non-modules), such as ``"pathlib.Path"`` after
running ``lazy from pathlib import Path``, and
* names of items than have already been accessed.

In future versions of Python, these may be removed, and/or additional
extras may be added.

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

Expand Down
18 changes: 18 additions & 0 deletions Doc/whatsnew/3.15.rst
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,13 @@ Default interactive shell
<using-on-controlling-color>`.
(Contributed by Antonio Cuni and Pablo Galindo in :gh:`130472`.)

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


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


importlib
---------

* The ``load_module()`` methods of :class:`~importlib.abc.Loader` and its
subclasses is removed.
The import system will no longer call it when defined on custom subclasses.
The method has been deprecated in favor of
:meth:`~importlib.abc.Loader.exec_module` since Python 3.4.
(Contributed by Brett Cannon in :gh:`97850`.)


importlib.resources
-------------------

Expand Down
45 changes: 45 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,37 @@ curses
(Contributed by Serhiy Storchaka in :gh:`133031`.)


ctypes
------

* Add :func:`ctypes.util.struct` for generating :class:`~ctypes.Structure` types
from an annotation-based syntax, similar to how the :mod:`dataclasses` module
is used.
(Contributed by Peter Bierma in :gh:`104533`.)
* Add :func:`ctypes.util.wrap_dll_function` for generating function pointers
through a function signature.
(Contributed by Peter Bierma in :gh:`153903`.)


concurrent.futures
------------------

* The iterator returned by :meth:`concurrent.futures.Executor.map` is no longer
automatically closed if a function call raises an exception.
Use method :meth:`!close` to explicitly close the iterator.
(Contributed by xzmeng and Serhiy Storchaka in :gh:`108518`.)


difflib
-------

* Expose optional ``autojunk`` parameter from :class:`difflib.SequenceMatcher`
to public functions and class methods in :mod:`difflib`,
allowing to modify behavior of automatic junk heuristic in this module
in higher public class methods and functions.
(Contributed by Tomasz Kazimierczak in :gh:`118150`)


encodings
---------

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

* Functions reading marshalled data from a :c:expr:`FILE*`,
such as :c:func:`PyMarshal_ReadObjectFromFile`,
now raise :exc:`OSError` for I/O errors
and :exc:`KeyboardInterrupt` for interrupted reading,
instead of :exc:`EOFError`.
(Contributed by Serhiy Storchaka in :gh:`155907`.)

* :c:func:`PyMarshal_WriteLongToFile` and :c:func:`PyMarshal_WriteObjectToFile`
now set the error indicator for I/O errors and interrupted writing,
instead of ignoring them.
:c:func:`PyMarshal_WriteObjectToFile` now also sets the error indicator
if the value cannot be marshalled.
(Contributed by Serhiy Storchaka in :gh:`155907`.)

Deprecated C APIs
-----------------

Expand Down
Loading
Loading