Engineering, Technology

                               

Python 3.9 is coming

Changes are coming

Python 3.9.0rc2 was recently released on September 17, 2020, with the final version scheduled for October 5, 2020. This release comes almost a year since the release of Python 3.8 on October 19, 2019.

What’s Changing?

Due to our utilization of Python in many projects, this upcoming release has some great features that we’re excited about.

Union Operators in dict

Dictionaries are one of the most frequently used data types in Python. To help improve the combination of multiple dictionaries, new operators have been added for merging (|) and updating (|=) the built-in dict class as defined in PEP 584.

Performing a dict union will return a new dict consisting of the left operand merged with the right operand. One important aspect to keep in mind is that each of operand must be a dict (or an instance of a dict subclass). In the instance that a key appears in both operands, the last-seen value (i.e. the value from the right-hand operand) will be used:
>>> a = {'blue': 1, 'green': 2, 'yellow': 3}
>>> b = {'yellow': 'a', 'orange': 'b'}
>>> a | b
{'blue': 1, 'green': 2, 'yellow': 'a', 'orange': 'b'}
>>> b | a
{'orange': 'b', 'blue': 1, 'green': 2, 'yellow': 3}
>>> a |= b
>>> a
{'blue': 1, 'green': 2, 'yellow': 'a', 'orange': 'b'}

Python switches to a yearly release cycle

The previous cadence was 18 months between each release. With the updated annual cadence, updates will be more frequent, albeit with less features due to the shorter time between releases.

The new timeline means Python 3.9 will ship on October 5, 2020, with Python 3.10 slated for October 2021. Pre-alpha development for Python 3.10 started on May 19, 2020 and will enter the alpha development phase when Python 3.9 ships. With the updated cadence, future Python releases will follow the same pattern.

Improved performance

Each release of Python packs in miscellaneous performance updates and this release is no different.

The first improvement involves capitalizing the use of the vectorcall protocol that was introduced in Python 3.8. The performance increase comes from how vectorcall makes many common function calls faster by minimizing or eliminating temporary objects created for the call. In Python 3.9, several Python built-ins — dict, frozenset, list, range, set, tuple — are now sped up by using vectorcall.

Other enhancements include multiple changes were made to prevent memory leaks when Python is initialized multiple times in the same process.

Multi-phase Initialization

A number of Python modules (_abc, audioop, _bz2, _codecs, _contextvars, _crypt, _functools, _json, _locale, operator, resource, time, _weakref) now use multi-phase initialization as defined by PEP 489. These changes were added to address a previously unsuccessful attempt at solving import related problems. The new behavior is more inline with the way that Python modules behave.

What’s Next?

Head over to the official release download page to read more about the changes and to download the release to take it for a spin yourself.

If you’re considering Python for an upcoming project or want to know more, then feel free to reach out and we’d love to discuss how we could help with execute your vision.

Comments are closed.