Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Python 3.5 Promises New Syntax Features

Python 3.5 Promises New Syntax Features

The Python Software Foundation has announced new features expected in Python 3.5.

In the article What’s New In Python 3.5 core developer Benjamin Petersen details new syntax features, and new library modules, as well as new built-in features and significantly improved library features.

Among the dynamic language's new syntax features is coroutines with async and await syntax. The feature's author, Yury Selivanov, says "Feedback on the initial beta release of Python 3.5 resulted in a redesign of the object model supporting this PEP to more clearly separate native coroutines from generators -- rather than being a new kind of generator, native coroutines are now their own completely distinct type."

Selivanov says he wants to make "coroutines a native Python language feature", clearly separating them from generators. Selivanov says this would remove "generator/coroutine ambiguity", and make it possible "to reliably define coroutines without reliance on a specific library."

According to Selivanov, "native coroutines and the associated new syntax features make it possible to define context manager and iteration protocols in asynchronous terms." Making it possible for Python programs to perform asynchronous calls when entering and exiting a runtime context, to perform asynchronous calls in iterators.

New with the 3.5 release is the zipapp module, providing an API and command line tool for creating executable Python Zip Applications. Previously introduced in Python 2.6, Petersen notes that Zip Applications were not well publicised. Daniel Holth and Paul Moore, authors of the module, say they aim to re-publicise the feature, as well as defining the .pyz and .pyzw extensions as "Python ZIP Applications" and "Windowed Python ZIP Applications", and provide simple tooling to manage the format.

Holth and Moore say the new module will provide functions including create_archive(source, target=None, interpreter=None, main=None) and get_interpreter(archive).

Among the improved library features comes collections.OrderedDict now implemented in C, improving its performance between 4x and 100x times, Petersen notes.

Furthermore, developers are now able to pass bytes to the tempfile module’s APIs, which will return the temporary pathname as bytes instead of str. Petersen says

[this] will return the temporary pathname as bytes instead of str. It also accepts a value of None on parameters where only str was accepted in the past to do the right thing based on the types of the other inputs. Two functions, gettempdirb() and gettempprefixb(), have been added to go along with this. This behavior matches that of the os APIs.

The Python community's response so far to the features has been warm. In the Reddit discussion What's New in Python 3.5 user beaverteeth92 commented "I'm so ready for that matrix multiplication operator. It's going to make my code so much more legible", with similar messages of support coming from nillion42, who said "I use matrix multiplication for various simulation and engineering related work. Python+numpy can often be used as a matlab alternative. In addition, I write code involving coordinate transforms using matrices at home."

The Python Software Foundation encourages everyone to contribute to Python, and includes details on how to get involved in their Python Developer Guide.

Python is developed under an OSI-approved open source license, making it freely usable and distributable, even for commercial use. Python's license is administered by the Python Software Foundation.

Rate this Article