Python3.8 New Features

Python 3.8 is a current stable version, released on 14, October, 2019 with various major and minor updates compare to its previous version Python 3.7. It includes new programming features, new and improved modules, and packages etc. Lets have a look in the detailed description.

  • Walrus Operator
  • Positional-Only Parameters
  • Cache for Compiled Bytecode Files
  • Same ABI for Build and Debug build
  • Improvement for self-documenting expressions and debugging
  • Python Runtime Audit Hooks
  • Python Initialization Configuration
  • Vectorcall: a fast calling protocol for CPython

Assignment Expression (walrus operator)

Walrus Operator is added to the new release. This new operator assigns values to variables as part of a larger expression. The syntax of this operator is := (eye and tusks of walrus) that’s why it is known as walrus operator.

Positional-Only Parameters

Python included a new syntax “/” to indicate that some parameters are position-only and can’t be used as keyword arguments. The benefits of marking a parameter as positional-only is that it allows the parameter name to be changed in the future without risk of breaking client code. Suppose we have a function having parameters a,b then in the future we can change these names to x,y without breaking any code.

Cache for Compiled Bytecode Files

The Python introduced new PYTHONPYCACHEPREFIX setting which configures the implicit bytecode cache to use a separate parallel filesystem tree, rather than the defaul__pycache__subdirectories within each source directory in the Python.

Same ABI for Build and Debug build

The Python new version now uses the same ABI for Build and debug Build mode. On Unix platform, when Python is built in debug mode, it is now possible to load C extensions built in release mode and C extensions built using the stable ABI.

Improvement for self-documenting expressions and debugging

Python added an equal (=) specifier to f-strings. An f-string such as f'{expr=}' will expand to the text of the expression, an equal sign, then the representation of the evaluated expression in Python.

Python Runtime Audit Hooks

Python added two hooks one for audit and second for verified Open Hook. Both hooks are available from Python and its native code that allow to take advantage of notification for applications and frameworks written in pure Python.

Python Initialization Configuration

Python3.8 version added new C API to configure the Python Initialization process which provides better control on the whole configuration and error reporting.

New Control Structures:
  • PyConfig
  • PyStatus
  • PyPreConfig
  • PyWideStringList
New Functions:
  • PyConfig_Clear()
  • PyConfig_InitIsolatedConfig()
  • PyConfig_InitPythonConfig()
  • PyConfig_Read()
  • PyConfig_SetArgv()
  • PyConfig_SetBytesArgv()
  • PyConfig_SetBytesString()
  • PyConfig_SetString()
  • PyPreConfig_InitIsolatedConfig()
  • PyPreConfig_InitPythonConfig()
  • PyStatus_Error()
  • PyStatus_Exception()
  • PyStatus_Exit()
  • PyStatus_IsError()
  • PyStatus_IsExit()
  • PyStatus_NoMemory()
  • PyStatus_Ok()
  • PyWideStringList_Append()
  • ... and many more

Vectorcall: a fast calling protocol for CPython

A new protocol “vectorcall” is added to the Python/C API. It is meant to formalize existing optimizations which were already done for various classes. Any extension type implementing a callable can use this protocol.

Added New Module

A new importlib.metadata module provides (provisional) support for reading metadata from third-party packages. For example, it can extract an installed package’s version number, list of entry points etc.

Other Language Updates

  • Now we can use continue in finally clouse without any error.
  • A new method reversed() is added to iterate Dict and dictviews reverse insertion order.
  • The bool, int, and fractions.Fraction types now have an as_integer_ratio() method like that found in float and decimal.Decimal.
  • Added support of \N{name}escapes in regular expressions:
  • Arithmetic operations between subclasses of or datetime.datetime and datetime.timedelta objects now return an instance of the subclass, rather than the base class.
  • The reduce method of object type can now return a tuple from two to six elements long.