now accept exception instances for ``exc_info`` parameter, in addition
:meth:`~logging.Logger.debug`, etc.), now accept exception instances
to boolean values and exception tuples.
in ``exc_info`` parameter, in addition to boolean values and exception
(Contributed by Yury Selivanov in :issue:`20537`.)
tuples. (Contributed by Yury Selivanov in :issue:`20537`.)
:class:`~logging.handlers.HTTPHandler` now accepts an optional
:class:`ssl.SSLContext` instance to configure the SSL settings used
in an HTTP connection. (Contributed by Alex Gaynor in :issue:`22788`.)
* :class:`~logging.handlers.HTTPHandler` now accepts optional
:class:`~logging.handlers.QueueListener` now takes a *respect_handler_level*
:class:`ssl.SSLContext` instance to configure the SSL settings used
keyword argument which, if set to ``True``, will pass messages to handlers
for HTTP connection.
taking handler levels into account. (Contributed by Vinay Sajip.)
(Contributed by Alex Gaynor in :issue:`22788`.)
* :class:`~logging.handlers.QueueListener` now takes a *respect_handler_level*
keyword argument which, if set to ``True``, will pass messages to handlers
taking handler levels into account. (Contributed by Vinay Sajip.)
lzma
lzma
----
----
* New option *max_length* for :meth:`~lzma.LZMADecompressor.decompress`
:meth:`~lzma.LZMADecompressor.decompress` now accepts an optional *max_length*
to limit the maximum size of decompressed data.
argument to limit the maximum size of decompressed data.
(Contributed by Martin Panter in :issue:`15955`.)
(Contributed by Martin Panter in :issue:`15955`.)
math
math
----
----
* :data:`math.inf` and :data:`math.nan` constants added. (Contributed by Mark
Two new constants have been added to :mod:`math`: :data:`math.inf`
Dickinson in :issue:`23185`.)
and :data:`math.nan`. (Contributed by Mark Dickinson in :issue:`23185`.)
* New :func:`~math.isclose` function.
A new function :func:`math.isclose` provides a way to test for approximate
(Contributed by Chris Barker and Tal Einat in :issue:`24270`.)
equality. (Contributed by Chris Barker and Tal Einat in :issue:`24270`.)
A new :func:`~math.gcd` function has been added. The :func:`fractions.gcd`
function is now deprecated. (Contributed by Mark Dickinson and Serhiy
Storchaka in :issue:`22486`.)
* New :func:`~math.gcd` function. The :func:`fractions.gcd` function now is
deprecated.
(Contributed by Mark Dickinson and Serhiy Storchaka in :issue:`22486`.)
operator
operator
--------
--------
* :func:`~operator.attrgetter`, :func:`~operator.itemgetter`, and
:func:`~operator.attrgetter`, :func:`~operator.itemgetter`, and
:func:`~operator.methodcaller` objects now support pickling.
:func:`~operator.methodcaller` objects now support pickling.
(Contributed by Josh Rosenberg and Serhiy Storchaka in :issue:`22955`.)
(Contributed by Josh Rosenberg and Serhiy Storchaka in :issue:`22955`.)
os
os
--
--
* New :func:`os.scandir` function that exposes file information from
The new :func:`os.scandir` returning an iterator of :class:`os.DirEntry`
the operating system when listing a directory. :func:`os.scandir`
objects has been added. If possible, :func:`os.scandir` extracts file
returns an iterator of :class:`os.DirEntry` objects corresponding to
attributes while scanning a directory, removing the need to perform
the entries in the directory given by *path*. (Contributed by Ben
subsequent system calls to determine file type or attributes, which may
Hoyt with the help of Victor Stinner in :issue:`22524`.)
significantly improve performance. (Contributed by Ben Hoyt with the help
of Victor Stinner in :issue:`22524`.)
On Windows, a new :attr:`~os.stat_result.st_file_attributes` attribute is
now available. It corresponds to ``dwFileAttributes`` member of the
``BY_HANDLE_FILE_INFORMATION`` structure returned by
``GetFileInformationByHandle()``. (Contributed by Ben Hoyt in :issue:`21719`.)
* :class:`os.stat_result` now has a :attr:`~os.stat_result.st_file_attributes`
:func:`os.urandom` now uses ``getrandom()`` syscall on Linux 3.17 or newer,
attribute on Windows. (Contributed by Ben Hoyt in :issue:`21719`.)
and ``getentropy()`` on OpenBSD 5.6 and newer, removing the need to use
``/dev/urandom`` and avoiding failures due to potential file descriptor
exhaustion. (Contributed by Victor Stinner in :issue:`22181`.)
* :func:`os.urandom`: On Linux 3.17 and newer, the ``getrandom()`` syscall is
New :func:`os.get_blocking` and :func:`os.set_blocking` functions allow to
now used when available. On OpenBSD 5.6 and newer, the C ``getentropy()``
get and set the file descriptor blocking mode (:data:`~os.O_NONBLOCK`.)
function is now used. These functions avoid the usage of an internal file
(Contributed by Victor Stinner in :issue:`22054`.)
descriptor.
(Contributed by Victor Stinner in :issue:`22181`.)
* New :func:`os.get_blocking` and :func:`os.set_blocking` functions to
:func:`~os.truncate` and :func:`~os.ftruncate` are now supported on
get and set the blocking mode of file descriptors.
Windows. (Contributed by Steve Dower in :issue:`23668`.)
(Contributed by Victor Stinner in :issue:`22054`.)
* :func:`~os.truncate` and :func:`~os.ftruncate` are now supported on
Windows. (Contributed by Steve Dower in :issue:`23668`.)
os.path
os.path
-------
-------
* New :func:`~os.path.commonpath` function that extracts common path prefix.
There is a new :func:`~os.path.commonpath` function returning the longest
Unlike the :func:`~os.path.commonprefix` function, it always returns a valid
common sub-path of each passed pathname. Unlike the
path. (Contributed by Rafik Draoui and Serhiy Storchaka in :issue:`10395`.)
:func:`~os.path.commonprefix` function, it always returns a valid
path. (Contributed by Rafik Draoui and Serhiy Storchaka in :issue:`10395`.)
pathlib
pathlib
-------
-------
* New :meth:`~pathlib.Path.samefile` method to check if other path object
The new :meth:`~pathlib.Path.samefile` method can be used to check if the
points to the same file. (Contributed by Vajrasky Kok and Antoine Pitrou
passed :class:`~pathlib.Path` object, or a string, point to the same file as
in :issue:`19775`.)
the :class:`~pathlib.Path` on which :meth:`~pathlib.Path.samefile` is called.
(Contributed by Vajrasky Kok and Antoine Pitrou in :issue:`19775`.)
:meth:`~pathlib.Path.mkdir` how accepts a new optional ``exist_ok`` argument
to match ``mkdir -p`` and :func:`os.makrdirs` functionality.
(Contributed by Berker Peksag in :issue:`21539`.)
* :meth:`~pathlib.Path.mkdir` has a new optional parameter ``exist_ok``
There is a new :meth:`~pathlib.Path.expanduser` method to expand ``~``
to mimic ``mkdir -p`` and :func:`os.makrdirs` functionality.
and ``~user`` prefixes. (Contributed by Serhiy Storchaka and Claudiu
(Contributed by Berker Peksag in :issue:`21539`.)
Popa in :issue:`19776`.)
* New :meth:`~pathlib.Path.expanduser` to expand ``~`` and ``~user``
A new :meth:`~pathlib.Path.home` class method can be used to get an instance
constructs.
of :class:`~pathlib.Path` object representing the user’s home directory.
(Contributed by Serhiy Storchaka and Claudiu Popa in :issue:`19776`.)
(Contributed by Victor Salgado and Mayank Tripathi in :issue:`19777`.)
* New class method :meth:`~pathlib.Path.home` to get an instance of
:class:`~pathlib.Path` object representing the user’s home directory.
(Contributed by Victor Salgado and Mayank Tripathi in :issue:`19777`.)
pickle
pickle
------
------
* Serializing more "lookupable" objects (such as unbound methods or nested
Nested objects, such as unbound methods or nested classes, can now be pickled using :ref:`pickle protocols <pickle-protocols>` older than protocol version 4,
classes) now are supported with pickle protocols < 4.
which already supported these cases. (Contributed by Serhiy Storchaka in
(Contributed by Serhiy Storchaka in :issue:`23611`.)
:issue:`23611`.)
poplib
poplib
------
------
* A new command :meth:`~poplib.POP3.utf8` enables :rfc:`6856`
A new command :meth:`~poplib.POP3.utf8` enables :rfc:`6856`
(internationalized email) support if the POP server supports it. (Contributed
(internationalized email) support, if the POP server supports it.
by Milan OberKirch in :issue:`21804`.)
(Contributed by Milan OberKirch in :issue:`21804`.)
re
re
--
--
* Number of capturing groups in regular expression is no longer limited by 100.
The number of capturing groups in regular expression is no longer limited by
(Contributed by Serhiy Storchaka in :issue:`22437`.)
100. (Contributed by Serhiy Storchaka in :issue:`22437`.)
:func:`re.sub` and :func:`re.subn` now replace unmatched groups with empty
strings instead of rising an exception. (Contributed by Serhiy Storchaka
in :issue:`1519638`.)
* Now unmatched groups are replaced with empty strings in :func:`re.sub`
and :func:`re.subn`. (Contributed by Serhiy Storchaka in :issue:`1519638`.)
readline
readline
--------
--------
* New :func:`~readline.append_history_file` function.
The new :func:`~readline.append_history_file` function can be used to append
(Contributed by Bruno Cauet in :issue:`22940`.)
the specified number of trailing elements in history to a given file.
(Contributed by Bruno Cauet in :issue:`22940`.)
shutil
shutil
------
------
* :func:`~shutil.move` now accepts a *copy_function* argument, allowing,
:func:`~shutil.move` now accepts a *copy_function* argument, allowing,
for example, :func:`~shutil.copy` to be used instead of the default
for example, :func:`~shutil.copy` to be used instead of the default
:func:`~shutil.copy2` if there is a need to ignore metadata. (Contributed by
:func:`~shutil.copy2` there is a need to ignore file metadata when moving.
Claudiu Popa in :issue:`19840`.)
(Contributed by Claudiu Popa in :issue:`19840`.)
:func:`~shutil.make_archive` now supports *xztar* format.
(Contributed by Serhiy Storchaka in :issue:`5411`.)
* :func:`~shutil.make_archive` now supports *xztar* format.
(Contributed by Serhiy Storchaka in :issue:`5411`.)
signal
signal
------
------
* On Windows, :func:`signal.set_wakeup_fd` now also supports socket handles.
On Windows, :func:`signal.set_wakeup_fd` now also supports socket handles.
(Contributed by Victor Stinner in :issue:`22018`.)
(Contributed by Victor Stinner in :issue:`22018`.)
Various ``SIG*`` constants in :mod:`signal` module have been converted into
:mod:`Enums <enum>`. This allows meaningful names to be printed
during debugging, instead of integer "magic numbers".
(Contributed by Giampaolo Rodola'in:issue:`21076`.)
* Different constants of :mod:`signal` module are now enumeration values using
the :mod:`enum` module. This allows meaningful names to be printed during
debugging, instead of integer “magic numbers”. (Contributed by Giampaolo
Rodola' in :issue:`21076`.)
smtpd
smtpd
-----
-----
* Both :class:`~smtpd.SMTPServer` and :class:`smtpd.SMTPChannel` now accept a