2012-09-30 04:11:58 -03:00
|
|
|
****************************
|
|
|
|
What's New In Python 3.4
|
|
|
|
****************************
|
|
|
|
|
2012-10-28 09:37:54 -03:00
|
|
|
.. :Author: Someone <email>
|
|
|
|
(uncomment if there is a principal author)
|
2012-09-30 04:11:58 -03:00
|
|
|
|
|
|
|
.. Rules for maintenance:
|
|
|
|
|
2012-09-30 10:21:53 -03:00
|
|
|
* Anyone can add text to this document, but the maintainer reserves the
|
|
|
|
right to rewrite any additions. In particular, for obscure or esoteric
|
|
|
|
features, the maintainer may reduce any addition to a simple reference to
|
|
|
|
the new documentation rather than explaining the feature inline.
|
|
|
|
|
|
|
|
* While the maintainer will periodically go through Misc/NEWS
|
|
|
|
and add changes, it's best not to rely on this. We know from experience
|
|
|
|
that any changes that aren't in the What's New documentation around the
|
|
|
|
time of the original release will remain largely unknown to the community
|
|
|
|
for years, even if they're added later. We also know from experience that
|
|
|
|
other priorities can arise, and the maintainer will run out of time to do
|
|
|
|
updates - in such cases, end users will be much better served by partial
|
|
|
|
notifications that at least give a hint about new features to
|
|
|
|
investigate.
|
2012-09-30 04:11:58 -03:00
|
|
|
|
|
|
|
* This is not a complete list of every single change; completeness
|
2012-09-30 10:21:53 -03:00
|
|
|
is the purpose of Misc/NEWS. The What's New should focus on changes that
|
|
|
|
are visible to Python *users* and that *require* a feature release (i.e.
|
|
|
|
most bug fixes should only be recorded in Misc/NEWS)
|
|
|
|
|
|
|
|
* PEPs should not be marked Final until they have an entry in What's New.
|
|
|
|
A placeholder entry that is just a section header and a link to the PEP
|
|
|
|
(e.g ":pep:`397` has been implemented") is acceptable. If a PEP has been
|
|
|
|
implemented and noted in What's New, don't forget to mark it as Final!
|
2012-09-30 04:11:58 -03:00
|
|
|
|
|
|
|
* If you want to draw your new text to the attention of the
|
|
|
|
maintainer, add 'XXX' to the beginning of the paragraph or
|
|
|
|
section.
|
|
|
|
|
2012-09-30 10:21:53 -03:00
|
|
|
* It's OK to add just a very brief note about a change. For
|
|
|
|
example: "The :ref:`~socket.transmogrify()` function was added to the
|
|
|
|
:mod:`socket` module." The maintainer will research the change and
|
|
|
|
write the necessary text (if appropriate). The advantage of doing this
|
|
|
|
is that even if no more descriptive text is ever added, readers will at
|
|
|
|
least have a notification that the new feature exists and a link to the
|
|
|
|
relevant documentation.
|
2012-09-30 04:11:58 -03:00
|
|
|
|
|
|
|
* You can comment out your additions if you like, but it's not
|
|
|
|
necessary (especially when a final release is some months away).
|
|
|
|
|
|
|
|
* Credit the author of a patch or bugfix. Just the name is
|
|
|
|
sufficient; the e-mail address isn't necessary.
|
|
|
|
|
|
|
|
* It's helpful to add the bug/patch number as a comment:
|
|
|
|
|
2012-09-30 10:21:53 -03:00
|
|
|
The :ref:`~socket.transmogrify()` function was added to the
|
|
|
|
:mod:`socket` module. (Contributed by P.Y. Developer in :issue:`12345`.)
|
2012-09-30 04:11:58 -03:00
|
|
|
|
|
|
|
This saves the maintainer the effort of going through the Mercurial log
|
|
|
|
when researching a change.
|
|
|
|
|
2012-09-30 10:21:53 -03:00
|
|
|
* Cross referencing tip: :ref:`mod.attr` will display as ``mod.attr``,
|
|
|
|
while :ref:`~mod.attr` will display as ``attr``.
|
|
|
|
|
2012-09-30 04:11:58 -03:00
|
|
|
This article explains the new features in Python 3.4, compared to 3.3.
|
|
|
|
|
2012-09-30 10:21:53 -03:00
|
|
|
.. Python 3.4 was released on TBD.
|
2012-09-30 04:11:58 -03:00
|
|
|
|
2012-11-17 13:30:48 -04:00
|
|
|
For full details, see the
|
|
|
|
`changelog <http://docs.python.org/3.4/whatsnew/changelog.html>`_.
|
2012-09-30 04:11:58 -03:00
|
|
|
|
|
|
|
.. note:: Prerelease users should be aware that this document is currently in
|
|
|
|
draft form. It will be updated substantially as Python 3.4 moves towards
|
|
|
|
release, so it's worth checking back even after reading earlier versions.
|
|
|
|
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
2013-10-26 12:57:34 -03:00
|
|
|
:pep:`429` - Python 3.4 Release Schedule
|
2012-09-30 04:11:58 -03:00
|
|
|
|
|
|
|
|
|
|
|
Summary -- Release highlights
|
|
|
|
=============================
|
|
|
|
|
2013-03-26 10:56:14 -03:00
|
|
|
.. This section singles out the most important changes in Python 3.4.
|
2012-09-30 04:11:58 -03:00
|
|
|
Brevity is key.
|
|
|
|
|
|
|
|
New syntax features:
|
|
|
|
|
2013-12-20 17:04:29 -04:00
|
|
|
* No new syntax features were added in Python 3.4.
|
2012-09-30 04:11:58 -03:00
|
|
|
|
|
|
|
New library modules:
|
|
|
|
|
2013-10-20 00:22:21 -03:00
|
|
|
* :mod:`asyncio`: New provisonal API for asynchronous IO (:pep:`3156`).
|
|
|
|
* :mod:`enum`: Support for enumeration types (:pep:`435`).
|
2013-11-11 08:11:55 -04:00
|
|
|
* :mod:`ensurepip`: Bootstrapping the pip installer (:pep:`453`).
|
2013-11-22 12:38:12 -04:00
|
|
|
* :mod:`pathlib`: Object-oriented filesystem paths (:pep:`428`).
|
2013-09-04 15:30:34 -03:00
|
|
|
* :mod:`selectors`: High-level and efficient I/O multiplexing, built upon the
|
|
|
|
:mod:`select` module primitives.
|
2013-10-20 00:22:21 -03:00
|
|
|
* :mod:`statistics`: A basic numerically stable statistics library (:pep:`450`).
|
2013-11-25 04:40:27 -04:00
|
|
|
* :mod:`tracemalloc`: Trace Python memory allocations (:pep:`454`).
|
2012-09-30 04:11:58 -03:00
|
|
|
|
2013-10-26 12:57:34 -03:00
|
|
|
New expected features for Python implementations:
|
2012-09-30 04:11:58 -03:00
|
|
|
|
2013-12-20 15:50:12 -04:00
|
|
|
* :pep:`446`: :ref:`Make newly created file descriptors non-inheritable <whatsnew-pep-446>`.
|
2013-10-26 12:57:34 -03:00
|
|
|
* command line option for :ref:`isolated mode <using-on-misc-options>`,
|
|
|
|
(:issue:`16499`).
|
2013-11-22 21:13:36 -04:00
|
|
|
* :ref:`improvements <codec-handling-improvements>` in the handling of
|
|
|
|
codecs that are not text encodings
|
2012-09-30 04:11:58 -03:00
|
|
|
|
|
|
|
Significantly Improved Library Modules:
|
|
|
|
|
2013-12-20 16:00:54 -04:00
|
|
|
* :ref:`Single-dispatch generic functions <whatsnew-singledispatch>` in
|
|
|
|
:mod:`functools` (:pep:`443`)
|
2013-12-20 17:38:09 -04:00
|
|
|
* New :mod:`pickle` :ref:`protocol 4 <whatsnew-protocol-4>` (:pep:`3154`)
|
2013-12-20 17:33:52 -04:00
|
|
|
* :ref:`SHA-3 (Keccak) support <whatsnew-sha3>` for :mod:`hashlib`.
|
2013-12-20 18:08:39 -04:00
|
|
|
* :ref:`TLSv1.1 and TLSv1.2 support <whatsnew-tls-11-12>` for :mod:`ssl`.
|
2013-08-14 11:35:41 -03:00
|
|
|
* :mod:`multiprocessing` now has option to avoid using :func:`os.fork`
|
|
|
|
on Unix (:issue:`8713`).
|
2013-12-20 14:10:43 -04:00
|
|
|
* :mod:`email` has a new submodule, :mod:`~email.contentmanager`, and
|
|
|
|
a new :mod:`~email.message.Message` subclass
|
|
|
|
(:class:`~email.contentmanager.EmailMessage`) that simplify MIME handling.
|
2013-08-12 15:46:47 -03:00
|
|
|
|
2013-10-26 12:57:34 -03:00
|
|
|
CPython implementation improvements:
|
2012-09-30 04:11:58 -03:00
|
|
|
|
2013-10-26 12:57:34 -03:00
|
|
|
* :ref:`PEP 442: Safe object finalization <pep-442>`
|
|
|
|
* :ref:`PEP 445: Configurable memory allocators <pep-445>`
|
2013-11-20 06:46:18 -04:00
|
|
|
* :pep:`456` Secure and interchangeable hash algorithm
|
2013-10-26 12:57:34 -03:00
|
|
|
* Improve finalization of Python modules to avoid setting their globals
|
|
|
|
to None, in most cases (:issue:`18214`).
|
|
|
|
* A more efficient :mod:`marshal` format (:issue:`16475`).
|
|
|
|
* "Argument Clinic", an initial step towards providing improved introspection
|
|
|
|
support for builtin and standard library extension types implemented in C
|
|
|
|
(:pep:`436`)
|
2012-09-30 04:11:58 -03:00
|
|
|
|
|
|
|
Please read on for a comprehensive list of user-facing changes.
|
|
|
|
|
2013-11-11 08:11:55 -04:00
|
|
|
|
|
|
|
PEP 453: Explicit bootstrapping of pip in Python installations
|
|
|
|
==============================================================
|
|
|
|
|
|
|
|
The new :mod:`ensurepip` module (defined in :pep:`453`) provides a standard
|
|
|
|
cross-platform mechanism to boostrap the pip installer into Python
|
|
|
|
installations and virtual environments.
|
|
|
|
|
2013-11-22 21:59:40 -04:00
|
|
|
The :mod:`venv` module and the :command:`pyvenv` utility make use of this
|
|
|
|
module to make ``pip`` readily available in virtual environments. When
|
|
|
|
using the command line interface, ``pip`` is installed by default, while
|
|
|
|
for the module API installation of ``pip`` must be requested explicitly.
|
|
|
|
|
|
|
|
For CPython source builds on POSIX systems, the ``make install`` and
|
|
|
|
``make altinstall`` commands bootstrap ``pip`` by default. This behaviour
|
|
|
|
can be controlled through configure options, and overridden through
|
|
|
|
Makefile options.
|
2013-11-11 08:11:55 -04:00
|
|
|
|
2013-11-23 02:39:09 -04:00
|
|
|
On Windows and Mac OS X, the CPython installers now offer the option to
|
|
|
|
install ``pip`` along with CPython itself.
|
2013-11-22 21:59:40 -04:00
|
|
|
|
|
|
|
.. note::
|
2013-11-11 08:11:55 -04:00
|
|
|
|
2013-11-22 21:59:40 -04:00
|
|
|
The implementation of PEP 453 is still a work in progress. Refer to
|
|
|
|
:issue:`19347` for the progress on additional steps:
|
2013-11-11 08:11:55 -04:00
|
|
|
|
2013-11-22 21:59:40 -04:00
|
|
|
* Having the binary installers install ``pip`` by default
|
|
|
|
* Recommending the use of ``pip`` in the "Installing Python Module"
|
|
|
|
documentation.
|
2013-11-11 08:11:55 -04:00
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
:pep:`453` - Explicit bootstrapping of pip in Python installations
|
|
|
|
PEP written by Donald Stufft and Nick Coghlan, implemented by
|
2013-11-22 21:59:40 -04:00
|
|
|
Donald Stufft, Nick Coghlan, Martin von Löwis and Ned Deily.
|
2013-11-11 08:11:55 -04:00
|
|
|
|
|
|
|
|
2013-12-20 15:50:12 -04:00
|
|
|
.. _whatsnew-pep-446:
|
2013-08-27 19:53:59 -03:00
|
|
|
|
|
|
|
PEP 446: Make newly created file descriptors non-inheritable
|
|
|
|
============================================================
|
|
|
|
|
2013-10-26 12:57:34 -03:00
|
|
|
:pep:`446` makes newly created file descriptors :ref:`non-inheritable
|
2013-09-15 05:37:57 -03:00
|
|
|
<fd_inheritance>`. New functions and methods:
|
2013-08-27 19:53:59 -03:00
|
|
|
|
|
|
|
* :func:`os.get_inheritable`, :func:`os.set_inheritable`
|
|
|
|
* :func:`os.get_handle_inheritable`, :func:`os.set_handle_inheritable`
|
|
|
|
* :meth:`socket.socket.get_inheritable`, :meth:`socket.socket.set_inheritable`
|
|
|
|
|
2013-07-30 14:59:21 -03:00
|
|
|
.. seealso::
|
|
|
|
|
2013-10-26 12:57:34 -03:00
|
|
|
:pep:`446` - Make newly created file descriptors non-inheritable
|
|
|
|
PEP written and implemented by Victor Stinner.
|
2013-07-30 14:59:21 -03:00
|
|
|
|
2012-09-30 04:11:58 -03:00
|
|
|
|
2013-11-22 21:13:36 -04:00
|
|
|
.. _codec-handling-improvements:
|
|
|
|
|
|
|
|
Improvements to codec handling
|
|
|
|
==============================
|
2013-11-13 09:49:21 -04:00
|
|
|
|
|
|
|
Since it was first introduced, the :mod:`codecs` module has always been
|
|
|
|
intended to operate as a type-neutral dynamic encoding and decoding
|
|
|
|
system. However, its close coupling with the Python text model, especially
|
|
|
|
the type restricted convenience methods on the builtin :class:`str`,
|
|
|
|
:class:`bytes` and :class:`bytearray` types, has historically obscured that
|
|
|
|
fact.
|
|
|
|
|
|
|
|
As a key step in clarifying the situation, the :meth:`codecs.encode` and
|
|
|
|
:meth:`codecs.decode` convenience functions are now properly documented in
|
|
|
|
Python 2.7, 3.3 and 3.4. These functions have existed in the :mod:`codecs`
|
2013-11-22 21:13:36 -04:00
|
|
|
module (and have been covered by the regression test suite) since Python 2.4,
|
2013-11-13 09:49:21 -04:00
|
|
|
but were previously only discoverable through runtime introspection.
|
|
|
|
|
|
|
|
Unlike the convenience methods on :class:`str`, :class:`bytes` and
|
|
|
|
:class:`bytearray`, these convenience functions support arbitrary codecs
|
|
|
|
in both Python 2 and Python 3, rather than being limited to Unicode text
|
|
|
|
encodings (in Python 3) or ``basestring`` <-> ``basestring`` conversions
|
|
|
|
(in Python 2).
|
|
|
|
|
2013-11-22 09:00:22 -04:00
|
|
|
In Python 3.4, the interpreter is able to identify the known non-text
|
|
|
|
encodings provided in the standard library and direct users towards these
|
|
|
|
general purpose convenience functions when appropriate::
|
2013-11-13 09:49:21 -04:00
|
|
|
|
2013-11-22 21:13:36 -04:00
|
|
|
>>> b"abcdef".decode("hex")
|
2013-11-13 09:49:21 -04:00
|
|
|
Traceback (most recent call last):
|
|
|
|
File "<stdin>", line 1, in <module>
|
2013-11-22 21:13:36 -04:00
|
|
|
LookupError: 'hex' is not a text encoding; use codecs.decode() to handle arbitrary codecs
|
2013-11-13 09:49:21 -04:00
|
|
|
|
2013-11-22 21:13:36 -04:00
|
|
|
>>> "hello".encode("rot13")
|
2013-11-13 09:49:21 -04:00
|
|
|
Traceback (most recent call last):
|
|
|
|
File "<stdin>", line 1, in <module>
|
2013-11-22 21:13:36 -04:00
|
|
|
LookupError: 'rot13' is not a text encoding; use codecs.encode() to handle arbitrary codecs
|
2013-11-13 09:49:21 -04:00
|
|
|
|
|
|
|
In a related change, whenever it is feasible without breaking backwards
|
|
|
|
compatibility, exceptions raised during encoding and decoding operations
|
|
|
|
will be wrapped in a chained exception of the same type that mentions the
|
|
|
|
name of the codec responsible for producing the error::
|
|
|
|
|
2013-11-22 21:13:36 -04:00
|
|
|
>>> import codecs
|
|
|
|
|
|
|
|
>>> codecs.decode(b"abcdefgh", "hex")
|
2013-11-22 09:00:22 -04:00
|
|
|
binascii.Error: Non-hexadecimal digit found
|
2013-11-13 09:49:21 -04:00
|
|
|
|
|
|
|
The above exception was the direct cause of the following exception:
|
|
|
|
|
|
|
|
Traceback (most recent call last):
|
|
|
|
File "<stdin>", line 1, in <module>
|
2013-11-22 21:13:36 -04:00
|
|
|
binascii.Error: decoding with 'hex' codec failed (Error: Non-hexadecimal digit found)
|
2013-11-13 09:49:21 -04:00
|
|
|
|
2013-11-22 21:13:36 -04:00
|
|
|
>>> codecs.encode("hello", "bz2")
|
2013-11-13 09:49:21 -04:00
|
|
|
TypeError: 'str' does not support the buffer interface
|
|
|
|
|
|
|
|
The above exception was the direct cause of the following exception:
|
|
|
|
|
|
|
|
Traceback (most recent call last):
|
|
|
|
File "<stdin>", line 1, in <module>
|
2013-11-22 21:13:36 -04:00
|
|
|
TypeError: encoding with 'bz2' codec failed (TypeError: 'str' does not support the buffer interface)
|
|
|
|
|
|
|
|
Finally, as the examples above show, these improvements have permitted
|
|
|
|
the restoration of the convenience aliases for the non-Unicode codecs that
|
|
|
|
were themselves restored in Python 3.2. This means that encoding binary data
|
|
|
|
to and from its hexadecimal representation (for example) can now be written
|
|
|
|
as::
|
|
|
|
|
|
|
|
>>> from codecs import encode, decode
|
|
|
|
>>> encode(b"hello", "hex")
|
|
|
|
b'68656c6c6f'
|
|
|
|
>>> decode(b"68656c6c6f", "hex")
|
|
|
|
b'hello'
|
|
|
|
|
|
|
|
The binary and text transforms provided in the standard library are detailed
|
|
|
|
in :ref:`binary-transforms` and :ref:`text-transforms`.
|
2013-11-13 09:49:21 -04:00
|
|
|
|
2013-11-22 21:13:36 -04:00
|
|
|
(Contributed by Nick Coghlan in :issue:`7475`, , :issue:`17827`,
|
|
|
|
:issue:`17828` and :issue:`19619`)
|
2013-11-13 09:49:21 -04:00
|
|
|
|
2013-11-22 12:05:39 -04:00
|
|
|
.. _pep-451:
|
|
|
|
|
|
|
|
PEP 451: A ModuleSpec Type for the Import System
|
|
|
|
================================================
|
|
|
|
|
|
|
|
:pep:`451` provides an encapsulation of the information about a module
|
|
|
|
that the import machinery will use to load it, (i.e. a module spec).
|
|
|
|
This helps simplify both the import implementation and several
|
|
|
|
import-related APIs. The change is also a stepping stone for several
|
|
|
|
future import-related improvements.
|
|
|
|
|
|
|
|
https://mail.python.org/pipermail/python-dev/2013-November/130111.html
|
|
|
|
|
|
|
|
The public-facing changes from the PEP are entirely backward-compatible.
|
|
|
|
Furthermore, they should be transparent to everyone but importer
|
|
|
|
authors. Key finder and loader methods have been deprecated, but they
|
|
|
|
will continue working. New importers should use the new methods
|
|
|
|
described in the PEP. Existing importers should be updated to implement
|
|
|
|
the new methods.
|
|
|
|
|
2013-11-13 09:49:21 -04:00
|
|
|
|
2013-12-20 17:38:09 -04:00
|
|
|
.. _whatsnew-protocol-4:
|
|
|
|
|
2013-11-23 13:59:12 -04:00
|
|
|
Pickle protocol 4
|
|
|
|
=================
|
|
|
|
|
|
|
|
The new :mod:`pickle` protocol addresses a number of issues that were present
|
|
|
|
in previous protocols, such as the serialization of nested classes, very
|
|
|
|
large strings and containers, or classes whose :meth:`__new__` method takes
|
|
|
|
keyword-only arguments. It also brings a couple efficiency improvements.
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
:pep:`3154` - Pickle protocol 4
|
|
|
|
PEP written by Antoine Pitrou and implemented by Alexandre Vassalotti.
|
|
|
|
|
|
|
|
|
2012-09-30 04:11:58 -03:00
|
|
|
Other Language Changes
|
|
|
|
======================
|
|
|
|
|
|
|
|
Some smaller changes made to the core Python language are:
|
|
|
|
|
2013-10-12 10:36:13 -03:00
|
|
|
* Unicode database updated to UCD version 6.3.
|
2012-09-30 04:11:58 -03:00
|
|
|
|
2013-06-28 14:31:19 -03:00
|
|
|
* :func:`min` and :func:`max` now accept a *default* argument that can be used
|
|
|
|
to specify the value they return if the iterable they are evaluating has no
|
|
|
|
elements. Contributed by Julian Berman in :issue:`18111`.
|
2012-09-30 04:11:58 -03:00
|
|
|
|
2013-08-12 15:46:47 -03:00
|
|
|
* Module objects are now :mod:`weakref`'able.
|
|
|
|
|
2013-10-20 00:22:21 -03:00
|
|
|
* Module ``__file__`` attributes (and related values) should now always
|
|
|
|
contain absolute paths by default, with the sole exception of
|
|
|
|
``__main__.__file__`` when a script has been executed directly using
|
|
|
|
a relative path (Contributed by Brett Cannon in :issue:`18416`).
|
|
|
|
|
2013-11-19 05:32:41 -04:00
|
|
|
* Now all the UTF-\* codecs (except UTF-7) reject surrogates during both
|
|
|
|
encoding and decoding unless the ``surrogatepass`` error handler is used,
|
|
|
|
with the exception of the UTF-16 decoder that accepts valid surrogate pairs,
|
|
|
|
and the UTF-16 encoder that produces them while encoding non-BMP characters.
|
|
|
|
Contributed by Victor Stinner, Kang-Hao (Kenny) Lu and Serhiy Storchaka in
|
|
|
|
:issue:`12892`.
|
|
|
|
|
2012-09-30 04:11:58 -03:00
|
|
|
|
|
|
|
New Modules
|
|
|
|
===========
|
|
|
|
|
2013-10-20 00:22:21 -03:00
|
|
|
|
|
|
|
asyncio
|
|
|
|
-------
|
|
|
|
|
|
|
|
The new :mod:`asyncio` module (defined in :pep:`3156`) provides a standard
|
|
|
|
pluggable event loop model for Python, providing solid asynchronous IO
|
|
|
|
support in the standard library, and making it easier for other event loop
|
|
|
|
implementations to interoperate with the standard library and each other.
|
|
|
|
|
|
|
|
For Python 3.4, this module is considered a :term:`provisional API`.
|
|
|
|
|
2013-10-26 12:57:34 -03:00
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
:pep:`3156` - Asynchronous IO Support Rebooted: the "asyncio" Module
|
|
|
|
PEP written and implementation led by Guido van Rossum.
|
|
|
|
|
2013-10-20 00:22:21 -03:00
|
|
|
enum
|
|
|
|
----
|
|
|
|
|
2013-10-26 12:57:34 -03:00
|
|
|
The new :mod:`enum` module (defined in :pep:`435`) provides a standard
|
|
|
|
implementation of enumeration types, allowing other modules (such as
|
|
|
|
:mod:`socket`) to provide more informative error messages and better
|
|
|
|
debugging support by replacing opaque integer constants with backwards
|
|
|
|
compatible enumeration values.
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
:pep:`435` - Adding an Enum type to the Python standard library
|
|
|
|
PEP written by Barry Warsaw, Eli Bendersky and Ethan Furman,
|
|
|
|
implemented by Ethan Furman.
|
2013-10-20 00:22:21 -03:00
|
|
|
|
|
|
|
|
2013-11-22 12:38:12 -04:00
|
|
|
pathlib
|
|
|
|
-------
|
|
|
|
|
|
|
|
The new :mod:`pathlib` module offers classes representing filesystem paths
|
|
|
|
with semantics appropriate for different operating systems. Path classes are
|
|
|
|
divided between *pure paths*, which provide purely computational operations
|
|
|
|
without I/O, and *concrete paths*, which inherit from pure paths but also
|
|
|
|
provide I/O operations.
|
|
|
|
|
|
|
|
For Python 3.4, this module is considered a :term:`provisional API`.
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
:pep:`428` - The pathlib module -- object-oriented filesystem paths
|
|
|
|
PEP written and implemented by Antoine Pitrou.
|
|
|
|
|
|
|
|
|
2013-09-04 14:02:49 -03:00
|
|
|
selectors
|
|
|
|
---------
|
2012-09-30 04:11:58 -03:00
|
|
|
|
2013-10-20 00:22:21 -03:00
|
|
|
The new :mod:`selectors` module (created as part of implementing :pep:`3156`)
|
|
|
|
allows high-level and efficient I/O multiplexing, built upon the
|
|
|
|
:mod:`select` module primitives.
|
|
|
|
|
|
|
|
|
|
|
|
statistics
|
|
|
|
----------
|
|
|
|
|
|
|
|
The new :mod:`statistics` module (defined in :pep:`450`) offers some core
|
|
|
|
statistics functionality directly in the standard library. This module
|
|
|
|
supports calculation of the mean, median, mode, variance and standard
|
|
|
|
deviation of a data series.
|
2012-09-30 04:11:58 -03:00
|
|
|
|
2013-10-26 12:57:34 -03:00
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
:pep:`450` - Adding A Statistics Module To The Standard Library
|
|
|
|
PEP written and implemented by Steven D'Aprano
|
|
|
|
|
2012-09-30 04:11:58 -03:00
|
|
|
|
2013-11-25 04:40:27 -04:00
|
|
|
tracemalloc
|
|
|
|
-----------
|
|
|
|
|
|
|
|
The new :mod:`tracemalloc` module (defined in :pep:`454`) is a debug tool to
|
|
|
|
trace memory blocks allocated by Python. It provides the following information:
|
|
|
|
|
|
|
|
* Traceback where an object was allocated
|
|
|
|
* Statistics on allocated memory blocks per filename and per line number:
|
|
|
|
total size, number and average size of allocated memory blocks
|
|
|
|
* Compute the differences between two snapshots to detect memory leaks
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
:pep:`454` - Add a new tracemalloc module to trace Python memory allocations
|
|
|
|
PEP written and implemented by Victor Stinner
|
|
|
|
|
|
|
|
|
2012-09-30 04:11:58 -03:00
|
|
|
Improved Modules
|
|
|
|
================
|
|
|
|
|
2013-08-12 15:48:15 -03:00
|
|
|
aifc
|
|
|
|
----
|
|
|
|
|
|
|
|
The :meth:`~aifc.getparams` method now returns a namedtuple rather than a
|
|
|
|
plain tuple. (Contributed by Claudiu Popa in :issue:`17818`.)
|
|
|
|
|
|
|
|
|
2013-10-19 15:10:46 -03:00
|
|
|
audioop
|
|
|
|
-------
|
|
|
|
|
|
|
|
Added support for 24-bit samples (:issue:`12866`).
|
|
|
|
|
2013-11-23 16:26:01 -04:00
|
|
|
Added the :func:`~audioop.byteswap` function to convert big-endian samples
|
|
|
|
to little-endian and vice versa (:issue:`19641`).
|
|
|
|
|
2013-10-19 15:10:46 -03:00
|
|
|
|
2013-11-13 10:24:31 -04:00
|
|
|
base64
|
|
|
|
------
|
|
|
|
|
|
|
|
The encoding and decoding functions in :mod:`base64` now accept any
|
|
|
|
:term:`bytes-like object` in cases where it previously required a
|
2013-11-24 11:09:26 -04:00
|
|
|
:class:`bytes` or :class:`bytearray` instance (:issue:`17839`).
|
2013-11-13 10:24:31 -04:00
|
|
|
|
|
|
|
|
2013-08-12 15:48:15 -03:00
|
|
|
colorsys
|
|
|
|
--------
|
|
|
|
|
|
|
|
The number of digits in the coefficients for the RGB --- YIQ conversions have
|
|
|
|
been expanded so that they match the FCC NTSC versions. The change in
|
|
|
|
results should be less than 1% and may better match results found elsewhere.
|
|
|
|
|
2013-04-13 15:49:48 -03:00
|
|
|
|
2013-10-13 10:23:08 -03:00
|
|
|
contextlib
|
|
|
|
----------
|
|
|
|
|
2013-10-17 10:40:57 -03:00
|
|
|
The new :class:`contextlib.suppress` context manager helps to clarify the
|
|
|
|
intent of code that deliberately suppresses exceptions from a single
|
|
|
|
statement. (Contributed by Raymond Hettinger in :issue:`15806` and
|
|
|
|
Zero Piraeus in :issue:`19266`)
|
|
|
|
|
2013-10-21 08:27:11 -03:00
|
|
|
The new :func:`contextlib.redirect_stdout` context manager makes it easier
|
2013-10-13 10:23:08 -03:00
|
|
|
for utility scripts to handle inflexible APIs that don't provide any
|
|
|
|
options to retrieve their output as a string or direct it to somewhere
|
2013-10-20 00:22:21 -03:00
|
|
|
other than :data:`sys.stdout`. In conjunction with :class:`io.StringIO`,
|
|
|
|
this context manager is also useful for checking expected output from
|
|
|
|
command line utilities. (Contribute by Raymond Hettinger in :issue:`15805`)
|
|
|
|
|
|
|
|
The :mod:`contextlib` documentation has also been updated to include a
|
|
|
|
:ref:`discussion <single-use-reusable-and-reentrant-cms>` of the
|
|
|
|
differences between single use, reusable and reentrant context managers.
|
2013-10-13 10:23:08 -03:00
|
|
|
|
|
|
|
|
2013-05-06 10:59:20 -03:00
|
|
|
dis
|
|
|
|
---
|
|
|
|
|
2013-10-13 17:12:09 -03:00
|
|
|
The :mod:`dis` module is now built around an :class:`~dis.Instruction` class
|
|
|
|
that provides details of individual bytecode operations and a
|
|
|
|
:func:`~dis.get_instructions` iterator that emits the Instruction stream for a
|
2013-05-06 10:59:20 -03:00
|
|
|
given piece of Python code. The various display tools in the :mod:`dis`
|
|
|
|
module have been updated to be based on these new components.
|
|
|
|
|
|
|
|
The new :class:`dis.Bytecode` class provides an object-oriented API for
|
|
|
|
inspecting bytecode, both in human-readable form and for iterating over
|
|
|
|
instructions.
|
|
|
|
|
2013-11-22 10:57:00 -04:00
|
|
|
(Contributed by Nick Coghlan, Ryan Kelly and Thomas Kluyver in :issue:`11816`
|
|
|
|
and Claudiu Popa in :issue:`17916`)
|
2013-05-06 10:59:20 -03:00
|
|
|
|
2013-08-12 15:48:15 -03:00
|
|
|
|
2012-11-21 16:09:21 -04:00
|
|
|
doctest
|
|
|
|
-------
|
|
|
|
|
2013-06-23 15:24:13 -03:00
|
|
|
Added :data:`~doctest.FAIL_FAST` flag to halt test running as soon as the first
|
|
|
|
failure is detected. (Contributed by R. David Murray and Daniel Urban in
|
|
|
|
:issue:`16522`.)
|
|
|
|
|
|
|
|
Updated the doctest command line interface to use :mod:`argparse`, and added
|
|
|
|
``-o`` and ``-f`` options to the interface. ``-o`` allows doctest options to
|
|
|
|
be specified on the command line, and ``-f`` is a shorthand for ``-o
|
|
|
|
FAIL_FAST`` (to parallel the similar option supported by the :mod:`unittest`
|
|
|
|
CLI). (Contributed by R. David Murray in :issue:`11390`.)
|
2012-09-30 04:11:58 -03:00
|
|
|
|
2013-04-13 15:49:48 -03:00
|
|
|
|
2013-08-09 17:15:28 -03:00
|
|
|
email
|
|
|
|
-----
|
|
|
|
|
|
|
|
:meth:`~email.message.Message.as_string` now accepts a *policy* argument to
|
|
|
|
override the default policy of the message when generating a string
|
|
|
|
representation of it. This means that ``as_string`` can now be used in more
|
|
|
|
circumstances, instead of having to create and use a :mod:`~email.generator` in
|
|
|
|
order to pass formatting parameters to its ``flatten`` method.
|
|
|
|
|
|
|
|
New method :meth:`~email.message.Message.as_bytes` added to produce a bytes
|
|
|
|
representation of the message in a fashion similar to how ``as_string``
|
|
|
|
produces a string representation. It does not accept the *maxheaderlen*
|
|
|
|
argument, but does accept the *unixfrom* and *policy* arguments. The
|
|
|
|
:class:`~email.message.Message` :meth:`~email.message.Message.__bytes__` method
|
|
|
|
calls it, meaning that ``bytes(mymsg)`` will now produce the intuitive
|
|
|
|
result: a bytes object containing the fully formatted message.
|
|
|
|
|
|
|
|
(Contributed by R. David Murray in :issue:`18600`.)
|
|
|
|
|
2013-10-16 23:48:40 -03:00
|
|
|
A pair of new subclasses of :class:`~email.message.Message` have been added,
|
|
|
|
along with a new sub-module, :mod:`~email.contentmanager`. All documentation
|
|
|
|
is currently in the new module, which is being added as part of the new
|
2013-10-17 10:40:57 -03:00
|
|
|
:term:`provisional <provisional package>` email API. These classes provide a
|
2013-10-16 23:48:40 -03:00
|
|
|
number of new methods that make extracting content from and inserting content
|
|
|
|
into email messages much easier. See the :mod:`~email.contentmanager`
|
|
|
|
documentation for details.
|
|
|
|
|
|
|
|
These API additions complete the bulk of the work that was planned as part of
|
|
|
|
the email6 project. The currently provisional API is scheduled to become final
|
|
|
|
in Python 3.5 (possibly with a few minor additions in the area of error
|
|
|
|
handling).
|
|
|
|
|
|
|
|
(Contributed by R. David Murray in :issue:`18891`.)
|
|
|
|
|
2013-08-09 17:15:28 -03:00
|
|
|
|
2013-06-20 19:36:30 -03:00
|
|
|
functools
|
|
|
|
---------
|
|
|
|
|
2013-11-03 02:41:46 -04:00
|
|
|
The new :func:`~functools.partialmethod` descriptor bring partial argument
|
|
|
|
application to descriptors, just as :func:`~functools.partial` provides
|
|
|
|
for normal callables. The new descriptor also makes it easier to get
|
|
|
|
arbitrary callables (including :func:`~functools.partial` instances)
|
|
|
|
to behave like normal instance methods when included in a class definition.
|
|
|
|
|
|
|
|
(Contributed by Alon Horev and Nick Coghlan in :issue:`4331`)
|
|
|
|
|
2013-12-20 16:00:54 -04:00
|
|
|
.. _whatsnew-singledispatch:
|
|
|
|
|
2013-11-03 02:41:46 -04:00
|
|
|
The new :func:`~functools.singledispatch` decorator brings support for
|
|
|
|
single-dispatch generic functions to the Python standard library. Where
|
|
|
|
object oriented programming focuses on grouping multiple operations on a
|
|
|
|
common set of data into a class, a generic function focuses on grouping
|
|
|
|
multiple implementations of an operation that allows it to work with
|
|
|
|
*different* kinds of data.
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
:pep:`443` - Single-dispatch generic functions
|
|
|
|
PEP written and implemented by Łukasz Langa.
|
2013-06-20 19:36:30 -03:00
|
|
|
|
2013-07-28 07:00:01 -03:00
|
|
|
|
2013-10-12 19:52:43 -03:00
|
|
|
hashlib
|
|
|
|
-------
|
|
|
|
|
|
|
|
New :func:`hashlib.pbkdf2_hmac` function.
|
|
|
|
(Contributed by Christian Heimes in :issue:`18582`)
|
|
|
|
|
2013-12-20 17:33:52 -04:00
|
|
|
.. _whatsnew-sha3:
|
|
|
|
|
|
|
|
New :ref:`hash algorithms <hash-algorithms>` ``sah3_224()``, ``sha3_256()``,
|
|
|
|
``sha3_384()``, and ``sha3_512()``. (Contributed by Christian Heimes in
|
|
|
|
:issue:`16113`.)
|
|
|
|
|
2013-10-12 19:52:43 -03:00
|
|
|
|
2013-11-25 00:18:47 -04:00
|
|
|
html
|
|
|
|
----
|
|
|
|
|
|
|
|
Added a new :func:`html.unescape` function that converts HTML5 character
|
|
|
|
references to the corresponding Unicode characters.
|
|
|
|
(Contributed by Ezio Melotti in :issue:`2927`)
|
|
|
|
|
|
|
|
Added a new *convert_charrefs* keyword argument to
|
|
|
|
:class:`~html.parser.HTMLParser` that, when ``True``, automatically converts
|
|
|
|
all character references. For backward-compatibility, its value defaults
|
|
|
|
to ``False``, but it will change to ``True`` in future versions, so you
|
|
|
|
are invited to set it explicitly and update your code to use this new feature.
|
|
|
|
(Contributed by Ezio Melotti in :issue:`13633`)
|
|
|
|
|
|
|
|
The *strict* argument of :class:`~html.parser.HTMLParser` is now deprecated.
|
|
|
|
(Contributed by Ezio Melotti in :issue:`15114`)
|
|
|
|
|
|
|
|
|
2013-08-12 15:48:15 -03:00
|
|
|
inspect
|
|
|
|
-------
|
|
|
|
|
2013-09-22 09:46:49 -03:00
|
|
|
|
2013-10-26 12:57:34 -03:00
|
|
|
The inspect module now offers a basic :ref:`command line interface
|
|
|
|
<inspect-module-cli>` to quickly display source code and other
|
|
|
|
information for modules, classes and functions. (Contributed by Claudiu Popa
|
|
|
|
and Nick Coghlan in :issue:`18626`)
|
2013-09-22 09:46:49 -03:00
|
|
|
|
2013-08-12 15:48:15 -03:00
|
|
|
:func:`~inspect.unwrap` makes it easy to unravel wrapper function chains
|
|
|
|
created by :func:`functools.wraps` (and any other API that sets the
|
2013-10-26 12:57:34 -03:00
|
|
|
``__wrapped__`` attribute on a wrapper function). (Contributed by
|
|
|
|
Daniel Urban, Aaron Iles and Nick Coghlan in :issue:`13266`)
|
|
|
|
|
|
|
|
As part of the implementation of the new :mod:`enum` module, the
|
|
|
|
:mod:`inspect` module now has substantially better support for custom
|
|
|
|
``__dir__`` methods and dynamic class attributes provided through
|
|
|
|
metaclasses (Contributed by Ethan Furman in :issue:`18929` and
|
|
|
|
:issue:`19030`)
|
|
|
|
|
2013-08-12 15:48:15 -03:00
|
|
|
|
2013-08-12 15:46:47 -03:00
|
|
|
mmap
|
|
|
|
----
|
|
|
|
|
|
|
|
mmap objects can now be weakref'ed.
|
|
|
|
(Contributed by Valerie Lambert in :issue:`4885`.)
|
|
|
|
|
|
|
|
|
2013-08-14 11:35:41 -03:00
|
|
|
multiprocessing
|
|
|
|
---------------
|
|
|
|
|
2013-12-17 08:17:26 -04:00
|
|
|
On Unix, two new *start methods* (``spawn`` and ``forkserver``) have been
|
|
|
|
added for starting processes using :mod:`multiprocessing`. These make
|
|
|
|
the mixing of processes with threads more robust, and the ``spawn``
|
|
|
|
method matches the semantics that multiprocessing has always used on
|
|
|
|
Windows. (Contributed by Richard Oudkerk in :issue:`8713`).
|
2013-08-14 11:35:41 -03:00
|
|
|
|
|
|
|
Also, except when using the old *fork* start method, child processes
|
|
|
|
will no longer inherit unneeded handles/file descriptors from their parents.
|
|
|
|
|
2013-12-17 08:17:26 -04:00
|
|
|
:mod:`multiprocessing` now relies on :mod:`runpy` (which implements the
|
|
|
|
``-m`` switch) to initialise ``__main__`` appropriately in child processes
|
|
|
|
when using the ``spawn`` or ``forkserver`` start methods. This resolves some
|
|
|
|
edge cases where combining multiprocessing, the ``-m`` command line switch
|
|
|
|
and explicit relative imports could cause obscure failures in child
|
|
|
|
processes. (Contributed by Nick Coghlan in :issue:`19946`)
|
|
|
|
|
2013-08-14 11:35:41 -03:00
|
|
|
|
2013-08-27 19:53:59 -03:00
|
|
|
os
|
|
|
|
--
|
|
|
|
|
2013-09-15 23:03:12 -03:00
|
|
|
New functions to get and set the :ref:`inheritable flag <fd_inheritance>` of a file
|
2013-08-27 19:53:59 -03:00
|
|
|
descriptors or a Windows handle:
|
|
|
|
|
|
|
|
* :func:`os.get_inheritable`, :func:`os.set_inheritable`
|
|
|
|
* :func:`os.get_handle_inheritable`, :func:`os.set_handle_inheritable`
|
|
|
|
|
|
|
|
|
2013-10-10 18:23:26 -03:00
|
|
|
pdb
|
|
|
|
---
|
|
|
|
|
|
|
|
The ``print`` command has been removed from :mod:`pdb`, restoring access to the
|
|
|
|
``print`` function.
|
|
|
|
|
|
|
|
Rationale: Python2's ``pdb`` did not have a ``print`` command; instead,
|
|
|
|
entering ``print`` executed the ``print`` statement. In Python3 ``print`` was
|
|
|
|
mistakenly made an alias for the pdb :pdbcmd:`p` command. ``p``, however,
|
|
|
|
prints the ``repr`` of its argument, not the ``str`` like the Python2 ``print``
|
|
|
|
command did. Worse, the Python3 ``pdb print`` command shadowed the Python3
|
|
|
|
``print`` function, making it inaccessible at the ``pdb`` prompt.
|
|
|
|
|
|
|
|
(Contributed by Connor Osborn in :issue:`18764`.)
|
|
|
|
|
|
|
|
|
2013-08-12 15:46:47 -03:00
|
|
|
poplib
|
|
|
|
------
|
|
|
|
|
|
|
|
New :meth:`~poplib.POP3.stls` method to switch a clear-text POP3 session into
|
|
|
|
an encrypted POP3 session.
|
|
|
|
|
|
|
|
New :meth:`~poplib.POP3.capa` method to query the capabilities advertised by the
|
|
|
|
POP3 server.
|
|
|
|
|
|
|
|
(Contributed by Lorenzo Catucci in :issue:`4473`.)
|
|
|
|
|
|
|
|
|
2013-10-02 05:56:18 -03:00
|
|
|
pprint
|
|
|
|
------
|
|
|
|
|
2013-10-21 07:32:21 -03:00
|
|
|
The :mod:`pprint` module now supports *compact* mode for formatting long
|
2013-10-02 05:56:18 -03:00
|
|
|
sequences (:issue:`19132`).
|
|
|
|
|
|
|
|
|
2013-10-26 12:57:34 -03:00
|
|
|
pydoc
|
|
|
|
-----
|
|
|
|
|
|
|
|
While significant changes have not been made to :mod:`pydoc` directly,
|
|
|
|
its handling of custom ``__dir__`` methods and various descriptor
|
|
|
|
behaviours has been improved substantially by the underlying changes in
|
|
|
|
the :mod:`inspect` module.
|
|
|
|
|
|
|
|
|
2013-11-23 17:20:30 -04:00
|
|
|
re
|
|
|
|
--
|
|
|
|
|
|
|
|
Added :func:`re.fullmatch` function and :meth:`regex.fullmatch` method,
|
|
|
|
which anchor the pattern at both ends of the string to match.
|
|
|
|
(Contributed by Matthew Barnett in :issue:`16203`.)
|
|
|
|
|
2013-11-25 17:20:20 -04:00
|
|
|
The repr of :ref:`regex objects <re-objects>` now includes the pattern
|
|
|
|
and the flags; the repr of :ref:`match objects <match-objects>` now
|
|
|
|
includes the start, end, and the part of the string that matched.
|
|
|
|
(Contributed by Serhiy Storchaka in :issue:`13592` and :issue:`17087`.)
|
|
|
|
|
|
|
|
|
2013-10-22 06:21:54 -03:00
|
|
|
resource
|
|
|
|
--------
|
|
|
|
|
|
|
|
New :func:`resource.prlimit` function and Linux specific constants.
|
|
|
|
(Contributed by Christian Heimes in :issue:`16595` and :issue:`19324`.)
|
|
|
|
|
2013-04-13 15:49:48 -03:00
|
|
|
smtplib
|
|
|
|
-------
|
|
|
|
|
2013-04-14 07:46:35 -03:00
|
|
|
:exc:`~smtplib.SMTPException` is now a subclass of :exc:`OSError`, which allows
|
2013-04-13 15:49:48 -03:00
|
|
|
both socket level errors and SMTP protocol level errors to be caught in one
|
|
|
|
try/except statement by code that only cares whether or not an error occurred.
|
|
|
|
(:issue:`2118`).
|
|
|
|
|
2013-08-12 15:48:15 -03:00
|
|
|
|
2013-08-27 19:53:59 -03:00
|
|
|
socket
|
|
|
|
------
|
|
|
|
|
2013-09-15 05:37:57 -03:00
|
|
|
Socket objects have new methods to get or set their :ref:`inheritable flag
|
|
|
|
<fd_inheritance>`:
|
2013-08-27 19:53:59 -03:00
|
|
|
|
|
|
|
* :meth:`socket.socket.get_inheritable`, :meth:`socket.socket.set_inheritable`
|
|
|
|
|
2013-08-31 19:18:48 -03:00
|
|
|
The ``socket.AF_*`` and ``socket.SOCK_*`` constants are enumeration values,
|
|
|
|
using the new :mod:`enum` module. This allows descriptive reporting during
|
|
|
|
debugging, instead of seeing integer "magic numbers".
|
2013-08-27 19:53:59 -03:00
|
|
|
|
2013-06-22 14:31:58 -03:00
|
|
|
ssl
|
|
|
|
---
|
|
|
|
|
2013-12-20 18:08:39 -04:00
|
|
|
.. _whatsnew-tls-11-12:
|
2013-06-22 14:34:17 -03:00
|
|
|
|
2013-12-20 18:08:39 -04:00
|
|
|
:data:`~ssl.PROTOCOL_TLSv1_1` and :data:`~ssl.PROTOCOL_TLSv1_2` (TLSv1.1 and
|
|
|
|
TLSv1.2 support) have been added; support for these protocols is only available if
|
|
|
|
Python is linked with OpenSSL 1.0.1 or later. (Contributed by Michele Orrù and
|
|
|
|
Antoine Pitrou in :issue:`16692`)
|
2013-06-22 14:31:58 -03:00
|
|
|
|
2013-12-20 18:08:39 -04:00
|
|
|
New diagnostic functions :func:`~ssl.get_default_verify_paths`,
|
|
|
|
:meth:`~ssl.SSLContext.cert_store_stats` and
|
|
|
|
:meth:`~ssl.SSLContext.get_ca_certs` (Contributed by Christian Heimes
|
|
|
|
in :issue:`18143` and :issue:`18147`)
|
2013-06-22 14:31:58 -03:00
|
|
|
|
2013-12-20 18:08:39 -04:00
|
|
|
Add :func:`ssl.enum_cert_store` to retrieve certificates and CRL from Windows'
|
|
|
|
cert store. (Contributed by Christian Heimes in :issue:`17134`.)
|
2013-08-12 15:46:47 -03:00
|
|
|
|
|
|
|
Support for server-side SNI using the new
|
|
|
|
:meth:`ssl.SSLContext.set_servername_callback` method.
|
|
|
|
(Contributed by Daniel Black in :issue:`8109`.)
|
|
|
|
|
|
|
|
|
2013-08-12 15:48:15 -03:00
|
|
|
stat
|
|
|
|
----
|
|
|
|
|
|
|
|
The :mod:`stat` module is now backed by a C implementation in :mod:`_stat`. A C
|
|
|
|
implementation is required as most of the values aren't standardized and
|
|
|
|
platform-dependent. (Contributed by Christian Heimes in :issue:`11016`.)
|
|
|
|
|
|
|
|
The module supports new file types: door, event port and whiteout.
|
|
|
|
|
|
|
|
|
2013-08-12 15:46:47 -03:00
|
|
|
struct
|
|
|
|
------
|
|
|
|
|
|
|
|
Streaming struct unpacking using :func:`struct.iter_unpack`.
|
|
|
|
(Contributed by Antoine Pitrou in :issue:`17804`.)
|
|
|
|
|
|
|
|
|
2013-09-03 18:43:03 -03:00
|
|
|
sunau
|
|
|
|
-----
|
|
|
|
|
|
|
|
The :meth:`~sunau.getparams` method now returns a namedtuple rather than a
|
|
|
|
plain tuple. (Contributed by Claudiu Popa in :issue:`18901`.)
|
|
|
|
|
2013-09-05 11:01:53 -03:00
|
|
|
:meth:`sunau.open` now supports the context manager protocol (:issue:`18878`).
|
|
|
|
|
2013-09-03 18:43:03 -03:00
|
|
|
|
2013-09-15 19:15:56 -03:00
|
|
|
traceback
|
|
|
|
---------
|
|
|
|
|
|
|
|
A new :func:`traceback.clear_frames` function takes a traceback object
|
|
|
|
and clears the local variables in all of the frames it references,
|
|
|
|
reducing the amount of memory consumed (:issue:`1565525`).
|
|
|
|
|
|
|
|
|
2013-08-12 15:46:47 -03:00
|
|
|
urllib
|
|
|
|
------
|
|
|
|
|
|
|
|
Add support.for ``data:`` URLs in :mod:`urllib.request`.
|
|
|
|
(Contributed by Mathias Panzenböck in :issue:`16423`.)
|
|
|
|
|
|
|
|
|
|
|
|
unittest
|
|
|
|
--------
|
|
|
|
|
|
|
|
Support for easy dynamically-generated subtests using the
|
|
|
|
:meth:`~unittest.TestCase.subTest` context manager.
|
|
|
|
(Contributed by Antoine Pitrou in :issue:`16997`.)
|
|
|
|
|
2013-04-13 15:49:48 -03:00
|
|
|
|
2013-04-10 13:31:43 -03:00
|
|
|
wave
|
|
|
|
----
|
|
|
|
|
|
|
|
The :meth:`~wave.getparams` method now returns a namedtuple rather than a
|
|
|
|
plain tuple. (Contributed by Claudiu Popa in :issue:`17487`.)
|
|
|
|
|
2013-07-31 14:46:08 -03:00
|
|
|
:meth:`wave.open` now supports the context manager protocol. (Contributed
|
|
|
|
by Claudiu Popa in :issue:`17616`.)
|
|
|
|
|
2013-08-12 15:46:47 -03:00
|
|
|
|
|
|
|
weakref
|
|
|
|
-------
|
|
|
|
|
|
|
|
New :class:`~weakref.WeakMethod` class simulates weak references to bound
|
2013-09-22 08:26:30 -03:00
|
|
|
methods. (Contributed by Antoine Pitrou in :issue:`14631`.)
|
2013-08-12 15:46:47 -03:00
|
|
|
|
2013-09-22 08:26:30 -03:00
|
|
|
New :class:`~weakref.finalize` class makes it possible to register a callback
|
|
|
|
to be invoked when an object is garbage collected, without needing to
|
|
|
|
carefully manage the lifecycle of the weak reference itself. (Contributed by
|
|
|
|
Richard Oudkerk in :issue:`15528`)
|
2013-08-12 15:46:47 -03:00
|
|
|
|
|
|
|
|
|
|
|
xml.etree
|
|
|
|
---------
|
|
|
|
|
|
|
|
Add an event-driven parser for non-blocking applications,
|
2013-08-30 09:51:20 -03:00
|
|
|
:class:`~xml.etree.ElementTree.XMLPullParser`.
|
|
|
|
(Contributed by Antoine Pitrou in :issue:`17741`.)
|
2013-08-12 15:46:47 -03:00
|
|
|
|
2013-10-20 22:59:23 -03:00
|
|
|
|
|
|
|
zipfile.PyZipfile
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
Add a filter function to ignore some packages (tests for instance),
|
|
|
|
:meth:`~zipfile.PyZipFile.writepy`.
|
|
|
|
(Contributed by Christian Tismer in :issue:`19274`.)
|
|
|
|
|
|
|
|
|
2013-08-12 15:46:47 -03:00
|
|
|
Other improvements
|
|
|
|
==================
|
|
|
|
|
|
|
|
Tab-completion is now enabled by default in the interactive interpreter.
|
|
|
|
(Contributed by Antoine Pitrou and Éric Araujo in :issue:`5845`.)
|
|
|
|
|
2013-09-06 10:55:58 -03:00
|
|
|
Python invocation changes
|
|
|
|
=========================
|
|
|
|
|
|
|
|
Invoking the Python interpreter with ``--version`` now outputs the version to
|
|
|
|
standard output instead of standard error (:issue:`18338`). Similar changes
|
|
|
|
were made to :mod:`argparse` (:issue:`18920`) and other modules that have
|
|
|
|
script-like invocation capabilities (:issue:`18922`).
|
2013-08-12 15:46:47 -03:00
|
|
|
|
2012-09-30 04:11:58 -03:00
|
|
|
Optimizations
|
|
|
|
=============
|
|
|
|
|
|
|
|
Major performance enhancements have been added:
|
|
|
|
|
2012-10-30 19:12:47 -03:00
|
|
|
* The UTF-32 decoder is now 3x to 4x faster.
|
2012-09-30 04:11:58 -03:00
|
|
|
|
2013-08-19 13:12:20 -03:00
|
|
|
* The cost of hash collisions for sets is now reduced. Each hash table
|
2013-09-15 18:57:15 -03:00
|
|
|
probe now checks a series of consecutive, adjacent key/hash pairs before
|
|
|
|
continuing to make random probes through the hash table. This exploits
|
|
|
|
cache locality to make collision resolution less expensive.
|
|
|
|
|
|
|
|
The collision resolution scheme can be described as a hybrid of linear
|
|
|
|
probing and open addressing. The number of additional linear probes
|
|
|
|
defaults to nine. This can be changed at compile-time by defining
|
|
|
|
LINEAR_PROBES to be any value. Set LINEAR_PROBES=0 to turn-off
|
|
|
|
linear probing entirely.
|
2013-08-19 13:12:20 -03:00
|
|
|
|
2013-10-22 06:49:34 -03:00
|
|
|
(Contributed by Raymond Hettinger in :issue:`18771`.)
|
2013-08-19 13:12:20 -03:00
|
|
|
|
2013-10-12 22:10:06 -03:00
|
|
|
* The interpreter starts about 30% faster. A couple of measures lead to the
|
2013-10-13 01:36:08 -03:00
|
|
|
speedup. The interpreter loads fewer modules on startup, e.g. the :mod:`re`,
|
2013-10-12 22:10:06 -03:00
|
|
|
:mod:`collections` and :mod:`locale` modules and their dependencies are no
|
|
|
|
longer imported by default. The marshal module has been improved to load
|
|
|
|
compiled Python code faster.
|
|
|
|
|
|
|
|
(Contributed by Antoine Pitrou, Christian Heimes and Victor Stinner in
|
|
|
|
:issue:`19219`, :issue:`19218`, :issue:`19209`, :issue:`19205` and
|
|
|
|
:issue:`9548`)
|
|
|
|
|
|
|
|
|
2013-10-26 12:57:34 -03:00
|
|
|
CPython Implementation Changes
|
|
|
|
==============================
|
|
|
|
|
|
|
|
|
|
|
|
.. _pep-445:
|
|
|
|
|
|
|
|
PEP 445: Customization of CPython memory allocators
|
|
|
|
---------------------------------------------------
|
|
|
|
|
|
|
|
:pep:`445` adds new C level interfaces to customize memory allocation in
|
|
|
|
the CPython interpreter.
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
:pep:`445` - Add new APIs to customize Python memory allocators
|
|
|
|
PEP written and implemented by Victor Stinner.
|
|
|
|
|
|
|
|
|
|
|
|
.. _pep-442:
|
|
|
|
|
|
|
|
PEP 442: Safe object finalization
|
|
|
|
---------------------------------
|
|
|
|
|
|
|
|
:pep:`442` removes the current limitations and quirks of object finalization
|
|
|
|
in CPython. With it, objects with :meth:`__del__` methods, as well as
|
|
|
|
generators with :keyword:`finally` clauses, can be finalized when they are
|
|
|
|
part of a reference cycle.
|
|
|
|
|
|
|
|
As part of this change, module globals are no longer forcibly set to
|
|
|
|
:const:`None` during interpreter shutdown in most cases, instead relying
|
|
|
|
on the normal operation of the cyclic garbage collector.
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
:pep:`442` - Safe object finalization
|
|
|
|
PEP written and implemented by Antoine Pitrou.
|
|
|
|
|
|
|
|
|
|
|
|
Other build and C API changes
|
|
|
|
-----------------------------
|
2012-09-30 04:11:58 -03:00
|
|
|
|
|
|
|
Changes to Python's build process and to the C API include:
|
|
|
|
|
2013-10-17 09:35:35 -03:00
|
|
|
* The new :c:func:`Py_SetStandardStreamEncoding` pre-initialization API
|
|
|
|
allows applications embedding the CPython interpreter to reliably force
|
|
|
|
a particular encoding and error handler for the standard streams
|
|
|
|
(Contributed by Bastien Montagne and Nick Coghlan in :issue:`16129`)
|
2012-09-30 04:11:58 -03:00
|
|
|
|
2013-10-20 00:22:21 -03:00
|
|
|
* Most Python C APIs that don't mutate string arguments are now correctly
|
|
|
|
marked as accepting ``const char *`` rather than ``char *`` (Contributed
|
|
|
|
by Serhiy Storchaka in :issue:`1772673`).
|
|
|
|
|
|
|
|
* "Argument Clinic" (:pep:`436`) is now part of the CPython build process
|
|
|
|
and can be used to simplify the process of defining and maintaining
|
|
|
|
accurate signatures for builtins and standard library extension modules
|
|
|
|
implemented in C.
|
|
|
|
|
2013-10-26 12:57:34 -03:00
|
|
|
.. note::
|
|
|
|
The Argument Clinic PEP is not fully up to date with the state of the
|
|
|
|
implementation. This has been deemed acceptable by the release manager
|
|
|
|
and core development team in this case, as Argument Clinic will not
|
|
|
|
be made available as a public API for third party use in Python 3.4.
|
|
|
|
|
2012-09-30 04:11:58 -03:00
|
|
|
|
|
|
|
Deprecated
|
|
|
|
==========
|
|
|
|
|
|
|
|
Unsupported Operating Systems
|
|
|
|
-----------------------------
|
|
|
|
|
2013-08-04 05:30:57 -03:00
|
|
|
* OS/2
|
|
|
|
* Windows 2000
|
2012-09-30 04:11:58 -03:00
|
|
|
|
|
|
|
|
|
|
|
Deprecated Python modules, functions and methods
|
|
|
|
------------------------------------------------
|
|
|
|
|
2013-03-21 20:36:26 -03:00
|
|
|
* :meth:`difflib.SequenceMatcher.isbjunk` and
|
2013-06-15 14:29:09 -03:00
|
|
|
:meth:`difflib.SequenceMatcher.isbpopular` were removed: use ``x in sm.bjunk`` and
|
|
|
|
``x in sm.bpopular``, where *sm* is a :class:`~difflib.SequenceMatcher` object.
|
2012-09-30 04:11:58 -03:00
|
|
|
|
2013-06-14 23:37:11 -03:00
|
|
|
* :func:`importlib.util.module_for_loader` is pending deprecation. Using
|
|
|
|
:func:`importlib.util.module_to_load` and
|
|
|
|
:meth:`importlib.abc.Loader.init_module_attrs` allows subclasses of a loader
|
|
|
|
to more easily customize module loading.
|
|
|
|
|
2013-06-16 14:13:40 -03:00
|
|
|
* The :mod:`imp` module is pending deprecation. To keep compatibility with
|
|
|
|
Python 2/3 code bases, the module's removal is currently not scheduled.
|
|
|
|
|
2013-10-04 12:38:59 -03:00
|
|
|
* The :mod:`formatter` module is pending deprecation and is slated for removal
|
|
|
|
in Python 3.6.
|
|
|
|
|
2013-11-20 12:23:06 -04:00
|
|
|
* MD5 as default digestmod for :mod:`hmac` is deprecated. Python 3.6 will
|
|
|
|
require an explicit digest name or constructor as *digestmod* argument.
|
|
|
|
|
2012-09-30 04:11:58 -03:00
|
|
|
|
|
|
|
Deprecated functions and types of the C API
|
|
|
|
-------------------------------------------
|
|
|
|
|
2013-10-23 13:54:43 -03:00
|
|
|
* The ``PyThreadState.tick_counter`` field has been removed: its value was
|
|
|
|
meaningless since Python 3.2 ("new GIL").
|
2012-09-30 04:11:58 -03:00
|
|
|
|
|
|
|
|
|
|
|
Deprecated features
|
|
|
|
-------------------
|
|
|
|
|
2013-10-25 16:39:26 -03:00
|
|
|
* The site module adding a "site-python" directory to sys.path, if it
|
|
|
|
exists, is deprecated (:issue:`19375`).
|
2012-09-30 04:11:58 -03:00
|
|
|
|
|
|
|
|
2012-10-04 13:45:10 -03:00
|
|
|
Porting to Python 3.4
|
2012-09-30 04:11:58 -03:00
|
|
|
=====================
|
|
|
|
|
2013-12-13 09:33:01 -04:00
|
|
|
Changes in the Python API
|
|
|
|
-------------------------
|
|
|
|
|
2012-09-30 04:11:58 -03:00
|
|
|
This section lists previously described changes and other bugfixes
|
|
|
|
that may require changes to your code.
|
|
|
|
|
2013-04-09 18:03:10 -03:00
|
|
|
* The ABCs defined in :mod:`importlib.abc` now either raise the appropriate
|
|
|
|
exception or return a default value instead of raising
|
|
|
|
:exc:`NotImplementedError` blindly. This will only affect code calling
|
|
|
|
:func:`super` and falling through all the way to the ABCs. For compatibility,
|
|
|
|
catch both :exc:`NotImplementedError` or the appropriate exception as needed.
|
2013-05-04 14:56:58 -03:00
|
|
|
|
|
|
|
* The module type now initializes the :attr:`__package__` and :attr:`__loader__`
|
|
|
|
attributes to ``None`` by default. To determine if these attributes were set
|
|
|
|
in a backwards-compatible fashion, use e.g.
|
2013-05-28 19:35:54 -03:00
|
|
|
``getattr(module, '__loader__', None) is not None``.
|
|
|
|
|
|
|
|
* :meth:`importlib.util.module_for_loader` now sets ``__loader__`` and
|
|
|
|
``__package__`` unconditionally to properly support reloading. If this is not
|
|
|
|
desired then you will need to set these attributes manually. You can use
|
2013-05-31 19:02:11 -03:00
|
|
|
:func:`importlib.util.module_to_load` for module management.
|
2013-06-01 00:18:39 -03:00
|
|
|
|
|
|
|
* Import now resets relevant attributes (e.g. ``__name__``, ``__loader__``,
|
|
|
|
``__package__``, ``__file__``, ``__cached__``) unconditionally when reloading.
|
|
|
|
|
2013-10-04 12:38:59 -03:00
|
|
|
* Frozen packages no longer set ``__path__`` to a list containing the package
|
|
|
|
name but an empty list instead. Determing if a module is a package should be
|
|
|
|
done using ``hasattr(module, '__path__')``.
|
2013-06-13 00:29:18 -03:00
|
|
|
|
2013-06-14 19:33:00 -03:00
|
|
|
* :func:`py_compile.compile` now raises :exc:`FileExistsError` if the file path
|
|
|
|
it would write to is a symlink or a non-regular file. This is to act as a
|
|
|
|
warning that import will overwrite those files with a regular file regardless
|
|
|
|
of what type of file path they were originally.
|
2013-06-16 19:05:54 -03:00
|
|
|
|
|
|
|
* :meth:`importlib.abc.SourceLoader.get_source` no longer raises
|
|
|
|
:exc:`ImportError` when the source code being loaded triggers a
|
|
|
|
:exc:`SyntaxError` or :exc:`UnicodeDecodeError`. As :exc:`ImportError` is
|
|
|
|
meant to be raised only when source code cannot be found but it should, it was
|
|
|
|
felt to be over-reaching/overloading of that meaning when the source code is
|
|
|
|
found but improperly structured. If you were catching ImportError before and
|
|
|
|
wish to continue to ignore syntax or decoding issues, catch all three
|
2013-06-20 19:31:55 -03:00
|
|
|
exceptions now.
|
2013-07-15 08:13:08 -03:00
|
|
|
|
|
|
|
* :func:`functools.update_wrapper` and :func:`functools.wraps` now correctly
|
2013-10-26 12:57:34 -03:00
|
|
|
set the ``__wrapped__`` attribute to the function being wrapper, even if
|
|
|
|
that function also had its ``__wrapped__`` attribute set. This means
|
|
|
|
``__wrapped__`` attributes now correctly link a stack of decorated
|
|
|
|
functions rather than every ``__wrapped__`` attribute in the chain
|
|
|
|
referring to the innermost function. Introspection libraries that
|
|
|
|
assumed the previous behaviour was intentional can use
|
|
|
|
:func:`inspect.unwrap` to access the first function in the chain that has
|
|
|
|
no ``__wrapped__`` attribute.
|
2013-10-10 11:18:20 -03:00
|
|
|
|
2013-10-19 12:46:38 -03:00
|
|
|
* :class:`importlib.machinery.PathFinder` now passes on the current working
|
2013-10-18 12:39:04 -03:00
|
|
|
directory to objects in :data:`sys.path_hooks` for the empty string. This
|
|
|
|
results in :data:`sys.path_importer_cache` never containing ``''``, thus
|
|
|
|
iterating through :data:`sys.path_importer_cache` based on :data:`sys.path`
|
|
|
|
will not find all keys. A module's ``__file__`` when imported in the current
|
|
|
|
working directory will also now have an absolute path, including when using
|
|
|
|
``-m`` with the interpreter (this does not influence when the path to a file
|
|
|
|
is specified on the command-line).
|
2013-12-13 05:57:04 -04:00
|
|
|
|
2013-12-13 09:33:01 -04:00
|
|
|
Changes in the C API
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
* :c:func:`PyErr_SetImportError` now sets :exc:`TypeError` when its **msg**
|
|
|
|
argument is not set. Previously only ``NULL`` was returned with no exception
|
|
|
|
set.
|
|
|
|
|
|
|
|
* The result of the :c:data:`PyOS_ReadlineFunctionPointer` callback must
|
|
|
|
now be a string allocated by :c:func:`PyMem_RawMalloc` or
|
|
|
|
:c:func:`PyMem_RawRealloc`, or *NULL* if an error occurred, instead of a
|
|
|
|
string allocated by :c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc`.
|
|
|
|
|
|
|
|
* :c:func:`PyThread_set_key_value` now always set the value. In Python
|
2013-12-13 05:57:04 -04:00
|
|
|
3.3, the function did nothing if the key already exists (if the current
|
|
|
|
value is a non-NULL pointer).
|
|
|
|
|
2013-12-13 09:33:01 -04:00
|
|
|
* The ``f_tstate`` (thread state) field of the :c:type:`PyFrameObject`
|
|
|
|
structure has been removed to fix a bug: see :issue:`14432` for the
|
|
|
|
rationale.
|
|
|
|
|