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.

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.

See also

Summary – Release highlights

New syntax features:

  • None yet.

New library modules:

  • None yet.

New built-in features:

  • None yet.

Implementation improvements:

Significantly Improved Library Modules:

  • SHA-3 (Keccak) support for hashlib.
  • TLSv1.1 and TLSv1.2 support for ssl.

Security improvements:

  • None yet.

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

Other Language Changes

Some smaller changes made to the core Python language are:

  • Unicode database updated to UCD version 6.2.
  • Import now raises the new exception ModuleNotFoundError (subclass of ImportError) when it cannot find something.

New Modules

  • None yet.

Improved Modules

dis

The dis module is now built around an Instruction class that provides details of individual bytecode operations and a get_instructions() iterator that emits the Instruction stream for a given piece of Python code. The various display tools in the dis module have been updated to be based on these new components.

The new 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)

doctest

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

smtplib

SMTPException is now a subclass of 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).

wave

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

Optimizations

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.

Deprecated

Unsupported Operating Systems

  • None yet.

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 importlib.abc now either raise the appropriate exception or return a default value instead of raising NotImplementedError blindly. This will only affect code calling super() and falling through all the way to the ABCs. For compatibility, catch both NotImplementedError or the appropriate exception as needed.
  • The module type now initializes the __package__ and __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.
  • 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 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__').
  • PyErr_SetImportError() now sets TypeError when its msg argument is not set. Previously only NULL was returned.
  • py_compile.compile() now raises 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.
  • importlib.abc.SourceLoader.get_source() no longer raises ImportError when the source code being loaded triggers a SyntaxError or UnicodeDecodeError. As 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.