Goo Goo Ga Joob – Python 3.8 aims for better readability, introduces walrus op

Python 3.8 is now available, introducing the walrus operator, positional-only parameters, and caching updates amongst other things.

After eight months of previews, the Python team has officially released version 3.8 of the programming language. The most highlighted feature is a new syntax for assigning values to variables which is meant to improve code readability by reducing complexity. The so called walrus operator := (yes, it takes a bit of imagination to see its tusks and eyes) can help reduce repetitions by offering a more compact notation for a variety of use cases, regular expression matching and while-loops being just two. A simple example that can be found in the documentation is:

if (n := len(a)) > 10:

    print(f”List is too long ({n} elements, expected <= 10)”)


which avoids calling len() twice.

Another new addition is / which is supposed to indicate that “some function parameters must be specified positionally and cannot be used as keyword arguments”. An example would be

def d(a, b, /, c, d, *, e, f)

with a and b being positional-only, and e and f required to be keywords, while c and d could be either. 

Benefits of such a syntax include the emulation of behaviour of functions coded in C, or the ability to preclude keyword arguments when the parameter name isn’t helpful. It also allows changing a parameter name without breaking client code, should the need arise.

The new release also comes with an Audit as well as a Verified Open Hook and new C API to configure Python initialisation for better error reporting and a more granular level of control.

Apart from that Python 3.8 is the first to use the same ABI for debug and release builds and includes a new setting –  PYTHONPYCACHEPREFIX – which leads to the implicit bytecode cache using a separate parallel file system tree. The former, for example, lets statically linked Python load C extensions built using a shared Python library. The change goes hand in hand with a few adjustments to the way Python is embedded into an application, so a quick read through the documentation is really worthwhile.

Curiously enough, the release of the new Python version coincides with the 7.2 release of Python interpreter PyPy. It includes two implementations, one supporting Python 2.7 features and syntax and one that does the same for 3.6. PyPy now supports 64-bit aarch64 ARM architecture and features a faster JSON decoder as well as an updated CFFI backend. 

Some additional tweaks facilitate the updating of certain libraries for end users and packagers and mean less links to DLLs which should lead to collision reduction when different versions of the same shared object have to be loaded. More details on the new release can be found in the release notes.

- Advertisement -