python-clinic / Doc / whatsnew / 3.4.rst

What's New In Python 3.4

This article explains the new features in Python 3.4, compared to 3.3.

For full details, see the changelog.


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.

Summary -- Release highlights

New syntax features:

  • None yet.

New library modules:

New built-in features:

  • None yet.

Implementation improvements:

Significantly Improved Library Modules:

Security improvements:

  • None yet.

Please read on for a comprehensive list of user-facing changes.

PEP 445: Add new APIs to customize Python memory allocators

The PEP 445 adds new Application Programming Interfaces (API) to customize Python memory allocators.

PEP 442: Safe object finalization

This PEP removes the current limitations and quirks of object finalization. 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.

Other Language Changes

Some smaller changes made to the core Python language are:

  • Unicode database updated to UCD version 6.2.
  • :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`.

New Modules

  • None yet.

Improved Modules


The :mod:`dis` module is now built around an :class:`Instruction` class that provides details of individual bytecode operations and a :func:`get_instructions` iterator that emits the Instruction stream for a 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.

(Contributed by Nick Coghlan, Ryan Kelly and Thomas Kluyver in :issue:`11816`)


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`.)


The :meth:`~aifc.getparams` method now returns a namedtuple rather than a plain tuple. (Contributed by Claudiu Popa in :issue:`17818`.)


New :func:`functools.singledispatch` decorator: see the PEP 443.


:func:`~inspect.unwrap` makes it easy to unravel wrapper function chains created by :func:`functools.wraps` (and any other API that sets the __wrapped__ attribute on a wrapper function).


:exc:`~smtplib.SMTPException` is now a subclass of :exc:`OSError`, which allows 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`).


TLSv1.1 and TLSv1.2 support (Contributed by Michele Orrù and Antoine Pitrou in :issue:`16692`)

New diagnostic functions :func:`~ssl.get_default_verify_paths`, :meth:`~ssl.SSLContext.cert_store_stats` and :meth:`~ssl.SSLContext.get_ca_certs`

Add :func:`ssl.enum_cert_store` to retrieve certificates and CRL from Windows' cert store.

(Contributed by Christian Heimes in :issue:`18143`, :issue:`18147` and :issue:`17134`)


The :meth:`~wave.getparams` method now returns a namedtuple rather than a plain tuple. (Contributed by Claudiu Popa in :issue:`17487`.)

:meth:`` now supports the context manager protocol. (Contributed by Claudiu Popa in :issue:`17616`.)


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.


Major performance enhancements have been added:

  • The UTF-32 decoder is now 3x to 4x faster.

Build and C API Changes

Changes to Python's build process and to the C API include:

  • None yet.


Unsupported Operating Systems

  • OS/2
  • Windows 2000

Deprecated Python modules, functions and methods

Deprecated functions and types of the C API

  • None yet.

Deprecated features

  • None yet.

Porting to Python 3.4

This section lists previously described changes and other bugfixes that may require changes to your code.

  • The ABCs defined in :mod:`` 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.
  • 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. 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 :func:`importlib.util.module_to_load` for module management.
  • Import now resets relevant attributes (e.g. __name__, __loader__, __package__, __file__, __cached__) unconditionally when reloading.
  • Frozen packages no longer set __path__ to a list containg the package name but an empty list instead. Determing if a module is a package should be done using hasattr(module, '__path__').
  • :c:func:`PyErr_SetImportError` now sets :exc:`TypeError` when its msg argument is not set. Previously only NULL was returned with no exception set.
  • :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.
  • :meth:`` 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 exceptions now.
  • :func:`functools.update_wrapper` and :func:`functools.wraps` now correctly set the __wrapped__ attribute even if the wrapped function had a 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 gain equivalent behaviour.