⇽ back to luminar.dev

In this post I would like to summarize which features can be used in which Python3 versions. I only choose features and changes that are relevant or interesting to me. There is a link to "What’s new" page for each version where you can find the full list.

Python 3.5

Released in September 2015. Comes pre-installed on Debian 9 (Stretch) and Ubuntu 16.04. Complete list of changes is here.

New syntax

Coroutines can now be defined with async keyword and awaited with await keyword. These keywords are not reserved yet. They will be become proper reserved keywords in Python 3.7.

async can also be used in async for and async with statements for asynchronous for loops and context managers.

New library modules

typing module adds support for Type Hints (PEP484). While syntax for function annotation was introduced back in Python3.0 (PEP3107, this module provides some standard tools (such as types Any, Union, Tuple, Callable, etc.) that can be used in type annotations.

zipapp provides tools to manage the creation of zip files containing Python code, which can be executed directly by the Python interpreter.

Improvements in stdlib

collections.OrderedDict is significantly faster now.

Python 3.6

Released in December 2016. Comes pre-installed on Ubuntu 18.04. Complete list of changes is here.

New syntax

Formatted string literals (f-strings). Defined in PEP498.

>>> name = "Max"
>>> print(f"Hello, {name}!")
Hello, Max!

Support for variable type hints (PEP526).

Underscores in numeric literals: 1_000_000 (PEP515).

Asynchronous generators (PEP525) and comprehensions (PEP530).

New library modules

secrets for generating cryptographically strong random numbers suitable for managing data such as passwords, account authentication, security tokens, and related secrets. Described in PEP506.

Implementation improvements

The new implementation of dictionaries is 20% to 25% more compact and preserves insertion order (but this should not be relied upon yet). See this great talk by Raymond Hettinger in which he explains how dictionaries changed over time.

Improvements in stdlib

asyncio is no longer provisional and the API is considered stable.

A new file system path protocol was added to support path-like object.

The datetime module has gained support for Local Time Disambiguation.

json.load() and json.loads() now support binary input.

A new function random.choices() returns a list of specified size with elements from a population with optional weights.

Class unittest.mock.Mock has new methods assert_called and assert_called_once.

Python 3.7

Released in June 2018. Comes pre-installed on Debian 10 (Buster) and Ubuntu 18.04 and 19.04. Complete list of changes is here.

New syntax features

Postponed evaluation of type annotations (PEP526).

  • Annotations can now support forward references

  • Annotations are cheaper and faster to store

async and await are now reserved keywords.

New library modules

dataclasses provides a decorator and functions for automatically adding generated special methods such as __init__() and __repr__() to user-defined classes. It is useful when you need to create a simple class that only holds data but has no behavior.

New built-in features

breakpoint() function for debuggers.

Dictionaries now officially preserve insertion order of elements.

Improvements in stdlib

asyncio received a lot of new features and improvements (high-level asyncio.run() function for running coroutines, many others).

time module now has support for nanosecond resolution.

Deprecations

Debian 8, Ubuntu 16, CentOS 7.5 and other platforms that use OpenSSL 0.9.8 and 1.0.1 are no longer supported. At least OpenSSL 1.0.2 is required. You can build Python3.7 on those platforms but you have to manually link a new OpenSSL version.

Python 3.8

Will be released sometime in 2019. Will come pre-installed on Debian 9, Ubuntu 19.04. Complete list of changes is here.

New syntax

Assignment expressions (the "walrus operator", :=):

if (n := len(a)) > 10:
    print(f"List is too long ({n} elements, expected <= 10)")

Positional only arguments: There is new syntax (/) to indicate that some function parameters must be specified positionally.

def pow(x, y, z=None, /):
    r = x**y
    if z is not None:
        r %= z
    return r

This is in addition to keyword only arguments.

Library improvements

json.tool has a new option (--json-lines) to parse every input line as separate JSON object.

New class unittest.mock.AsyncMock for asynchronous mocking.