Current Date: Thu, May 6, 2021 1:17 PM

The latest changes in Python 3.9

The latest changes in Python 3.9

Python 3.9, released on October 5, brings significant changes to both the features of the language and how the language is developed. Python has gained in popularity over the past few years, and its use has really exploded in fast-growing fields, like Data Science and Machine Learning. The project is being actively developed to keep pace with all new needs.

  • Best Python Tools for Machine Learning and Data Science

Below is a summary of all the new features in Python 3.9.

Python moves to the annual release cycle

Up to this point, Python is developed and released on an 18-month cycle. PEP 602 proposed that the Python development team should adopt the annual release cycle, and that suggestion was accepted.

Annual release cycle means fewer features per release, but also means feature testing will be more responsive, less breakable changes per release. Therefore, there is more incentive for Linux users and distribution managers to upgrade Python more often. It also means that new features proposed late in the development cycle won't take long to roll into new releases.

The new timeline means Python 3.9 will ship in October 2020. Python 3.10, which officially started pre-alpha development on May 19, 2020, will enter alpha development when Python 3.9 ships and launch October 2021. Future Python releases will follow the same pattern.

The latest changes in Python 3.9 Python moves to the annual release cycle

Python becomes faster by default

Every revision of Python has a performance improvement over the previous version. Python 3.9 has two major improvements that increase performance without requiring any changes to existing code.

The first improvement related to more use of the vectorcall protocol was introduced in Python 3.8. vectorcall makes many common function calls faster by minimizing or eliminating the temporary objects made for the call. In Python 3.9, some of Python's built-in -range, tuple, set, frozenset, list, dict Uses internal vectorcall to speed up execution.

The second biggest performance enhancement tool is the more efficient Python source code parser. The new parser for the CPython runtime is not designed to solve performance problems but rather to handle internal inconsistencies in the original parser. Another important benefit, however, is faster parsing, especially for large volumes of code.

New features for Python dictionaries and strings

Python makes it easy to manipulate common data types, and Python 3.9 extends this ease with new features for strings and dictionaries. For strings, there are new ways to remove prefixes and suffixes, operations that have long required a lot of manual manipulation to perform. For dictionaries, there are now conjugate operators, one to merge two dictionaries into a new dictionary and one to update the contents of one dictionary with another.

The latest changes in Python 3.9 Python 3.9 brought new features to strings and dictionaries

The decorator loosened some limitations

Previously, Decorator could only include symbols @, name (for example: func) or dotted name (func.method) and (optionally) a single call (func.method (arg1, arg2)). With Python 3.9, Decorator can now include any valid expression.

A long-standing way to get around this limitation is to create a function or lambda expression, which would replace a more complex expression when used as a decorator. Now any expression will work, as long as it yields something that can act as a decorator.

New import operations in Python

In recent versions, Python has extended support for type hinting. This is mainly for the sake of linter (tool used to analyze source and detect code mistakes) and code checkers. But type hinting is a powerful tool for ensuring consistency across large code bases, so Python code can still benefit from having type hints.

Two new features for type hinting and type annotation were introduced in Python 3.9. Enter suggestions for the contents of the collection - for example, lists and dictionaries - that are now available natively in Python. This means you can for example describe a list as list[int] - list of integers - without library typing to perform.

The second addition to Python's input mechanisms is the flexible function and variable annotations. This allows the use of styles Annotated to describe a type of using metadata, which can be checked ahead of time (with linting tools) or at runtime. For example: Annotated[int, ctype("char")] can be used to describe an integer, considered to be of type char in C. By default, Python will do nothing with such annotation, but it can be used by linter codes.

Internal Python improvements

Internal cleanup, refinement, and modernization Python is an ongoing creative process for developers, and Python 3.9 has made some changes in that direction.

The first is the redesign of the module way. Python extension modules, written in C, can now use a new load mechanism that makes them behave like regular Python modules when imported.

Several modules in the new Python standard library support this behavior: _abc, audioop, _bz2, _codecs, _contextvars, _crypt, _functools, _json, _locale, operator, resource, time, _weakref. The new loading mechanism not only allows extension modules to be handled more flexibly by Python, but also allows for many new capabilities.

The second cleanup initiative is a stable internal ABI for CPython, an ABI that's guaranteed to last for the lifetime of Python 3. Historically, every major revision of Python has been incompatible. ABI with previous versions required the extension modules to be recompiled for every new version. From now on, any extension modules that use stable ABI will work on Python versions. With Python 3.9, the following modules in the standard library use stable ABI: audioop, ast, grp, _hashlib, pwd, _posixsubprocess, random, select, struct, termios, zlib.

Other changes in Python 3.9

The Python standard library currently supports the IANA Time Zone Database. This database is well maintained and widely used. There is a direct way to use it in Python's datetime library which will save you a lot of time.

New string methods allow the easy removal of prefixes and suffixes. This is one of the more common use cases where everyday use requires too much boilerplate than it needs. Methods .removeprefix () and .removesuffix () new returns a modified copy of a string, removing the prefix or suffix in question, as long as they exist in the string.

See more:

  • How to install Python on Windows, macOS, Linux