New Features in Python 3.8

This summer (June 2019, to be more precise) Python released a beta version of Python 3.8. There are four beta release previews planned and their main goal is to let the community test the new features and report on any bugs found.

While you can check out the full list of the new features here, we will focus on the most exciting ones that you can test right now.

New Features in Python 3.8

Position-only arguments

Python 3.8 will let developers specify position-only arguments with the new syntax “/”.

This new feature is aimed at helping library authors to ensure correct API usage. Positional-only parameters let library authors express the intended API usage and also contribute to language consistency. 

With the introduction of the new syntax, library authors will be more flexible in changing the name of position-only arguments without breaking callers. 

Assignment expressions

With this feature comes a new operator (:= expr.) which is also called a walrus operator. It will let the developers assign the variables within an expression. The feature is available in list comprehensions and statement forms.

The main idea behind the introduction of this feature was to reduce the bulky boilerplate that can be spotted in some of the programming patterns.

It is important to notice that an assignment expression will not introduce a new scope. In the majority of the cases, the scope will be self-explanatory.

Python Initialization Configuration

This feature will provide better control over the configuration and better reporting, according to the Python developers.

The Python Initialization Configuration will introduce new functions to the Python Initialization C API so that developers will be able to configure Python in a more reliable and clear manner. The benefits that the innovation will bring also include:

  • Opportunity to read the configuration and then override some parameters before applying it
  • Opportunity to completely override the way Python computes the module search paths
  • Easier building of a customized Python due to the new Py_RunMain() function

Vectorcall

Vectorcall is a fast calling protocol for CPython and is based on the “fastcall” convention, which is not new for Python developers. 

The vectorcall feature is aimed at optimizing calls of objects, which is important for the performance of your code. Due to the generalization of calling convention, all calls will benefit from a more efficient performance. 

Runtime audit hooks

Python 3.8 will bring two new APIs: Audit Hook (for arbitrary events) and Verified Open Hook (specific to the module import system). These APIs will be available in all Python implementations.

The runtime audit hooks will grant you the insights into the running Python app. This opportunity, in turn, will make it easier for developers and system administrators to integrate Python into their monitoring systems.

New pickle protocol version

The pickle module helps serialize and deserialize the data structures. Different Python versions support different levels of the pickle protocol, so it makes sense that the most recent version aka Python 3.8 will support a bigger range of capabilities and provide better serialization.

The new protocol is supported by NumPy and Apache Arrow external libraries and comes as an add-on for Python 3.7 and 3.6.

Other improvements that will come with Python 3.8:

  • Increase of speed of built-in methods and functions: from 20% to 50%
  • New opcode cache for faster instructions’ performance in the interpreter
  • The smaller size of the newly created lists (by approximately 12%)
  • Certain file-copying operations now use platform-specific calls for faster performance.

Conclusion

The Python 3.8 version is strongly focused on delivering better and faster performance and make the developers’ experience more enjoyable and smooth.

We strongly recommend you to check out the new Python 3.8 and try out its brand-new features. Judging by the presented features, this new Python will be more consistent, concise and efficient, which is a big plus for all the Python developers out there.

Want to stay updated on the latest tech news?

Sign up for our monthly blog newsletter in the form below.

Softteco Logo Footer