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.

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

  • difflib.SequenceMatcher.isbjunk() and difflib.SequenceMatcher.isbpopulur(): use x in sm.bjunk and x in sm.bpopular, where sm is a SequenceMatcher object.

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.