Tech Reviews

Python 3.8 Overview

The release of Python 3.8 is scheduled for October 2019, but now everyone has the opportunity to feel a set of new features of the language. While writing this post, python version 3.8b2 is available on the official website .

So, what is the upcoming release preparing for us?

f-string =

Now displaying debug information has become even easier and more beautiful. It is enough to pass the = sign to f-string:

Assignment Expressions or: =, aka walrus operator

The legendary PEP572, due to which Guido stepped down as dictator of Python. A statement assigns a value to a variable in an expression. For example, you want to check if a key is in the dictionary, and also assign the value of this key to a variable. In versions of Python before 3.8, you need to do:

In version 3.8, the code looks a little more compact:

params = {'foo': 'bar'}
if z := params.get('foo'):
    print(z)

Positional-only arguments

In python 3, keyword-only arguments ( PEP3102 ) appeared back in 2006 . Their task is to enforce the passing of arguments to a function or method by key after the *

The interpreter tells us that the function accepts only 2 positional arguments, but 4 was passed in order to avoid swearing, the function must be called like this:

test(1, 2, key1=3, key2=4)

In python 3.8, it became possible to specify the transfer of arguments exclusively according to their position. Unlike keyword-only arguments, all arguments must be passed according to position:

def position_only(a, b, c, d=0, /):
    pass

position_only(1, 2, 3)  # OK

position_only(1, 2, c=3)  # This raises exception

Shared memory for IPC

For interprocessor communication, python 3.8 introduced shared memory. Previously, in order to transfer data between processes, the internal mechanism meant serializing and deserializing an object and sending data to a socket. With the use of the OS mechanism for allocating shared memory, there is no need to communicate through a disk or socket, and this gives a significant increase in performance. The shared_memory module has been added to the multiprocessing package . An example of using shared memory between two different processes:

from multiprocessing import shared_memory
a = shared_memory.ShareableList(range(5))

TypedDict

Now you can specify the type of values ​​for dictionaries with a fixed number of string keys. For instance:

from typing import TypedDict

class Movie(TypedDict):
    title: str
    year: int

movie: Movie = {
    'title': 'Movie title', 
    'year': 2020
}

The Movie class can be used in annotations:

from typing import List
def my_function(films: List[Movie]):
    pass

final

Those who are familiar with Java immediately understand what final is. What is marked final should not change during the life cycle of the script.

from typing import Final, final

birth_year: Final = 1989
birth_year = 1901  

Classes marked with the final decorator must not be inherited:

@final
class FinalClass:
    pass

class InheritedFromFinal(FinalClass): 
    pass

You can also formally prohibit overriding a method in a child class:

class MyClass:
    @final
    def prohibited(self):
        pass

class SecondClass(MyClass):
    def prohibited(self): 
        pass

These are not all the features in the new version of Python. More information about the new products can be found here .

shahidsidd

Recent Posts

Chicago Cubs vs Milwaukee Brewers Match Player Stats – Full Scorecard & Key Highlights (2026)

The latest Chicago Cubs vs Milwaukee Brewers match Player States delivered an exciting showdown packed… Read More

4 days ago

Best Pickleball Courts in Vadodara: Top 5 Places to Play Right Now

Pickleball is growing fast in Vadodara! More and more people are picking up a paddle… Read More

7 days ago

Why the Master Lock System is Vital for Modern Security Solutions

Have you ever found yourself juggling a massive keyring, desperately searching for the right key… Read More

1 week ago

How Keyword Clustering Can Boost Your SEO Content Strategy

What if one well-keyword-optimized piece of content could outperform dozens of isolated posts? Today’s top… Read More

2 weeks ago

The Unmatched Versatility of the Qt8 Garments Jacket

Every few years, a piece of outerwear comes along that genuinely earns the description of… Read More

2 weeks ago

Premium Valet Parking Services in Singapore: The 2026 Guide

In the high-stakes corporate world, professional valet parking services in Singapore have evolved from a… Read More

2 weeks ago