Looking forward to Python 3.9

Python is often thought of as a hobbyist language, and its popularity among software developers for its flexibility and simplicity tend to make it an excellent choice for hobby projects. However, Python's use in high-profile enterprise application development has also made it a go-to choice for businesses looking to gain a competitive edge. At JBS, we have written many applications for clients that handle Internet-scale volume every day using the Python language and ecosystem. With its first major version since Python 2's end-of-life set to release this year, it is an excellent time to see what’s new in the programming language that is taking the world by storm, and consider if now is the right time to think about writing your own custom enterprise software with Python. Python 3.9 will bring many new features to the language, and continue to cement Python's place as one of the most popular programming languages in use today.

Notably, since support for Python 2 ended at the beginning of this year, many functions that have been kept for compatibility reasons are finally being removed. These functions have raised `DeprecationWarning` exceptions for years, and their removal is expected to allow for cleaner modules and faster development, which was the ultimate promise of the Python 3 transition in 2008.

Under the hood, Python will be debuting a new parser based on Parsing Expression Grammar (PEG). The parser it

used to verify that Python code has the correct syntax to be translated into machine language. The previous parser had limited expressive range and required interventions at other levels of the compilation pipeline to handle certain Python expressions. Some constructs were simply not possible, holding back new features. The new parser can accurately represent all current Python syntax and opens the door for new language features in future releases. The short term gains from this new parser will be decreased complexity in Python’s syntax trees, including the removal of an entire syntax tree that was used only to circumvent the limitations of the former parser. This, in turn, will decrease the maintenance burden of the language, a recurring theme of the 3.9 release. The new parser will require slightly more memory on average, but some excessive memory use issues will disappear and it is expected to be comparable in speed to the previous parser.

Several interesting new language features are also arriving with Python 3.9. Function decorators, one of Python’s killer features, are being expanded to allow any valid Python expression. Previously, only function names or function calls were permitted. Additionally, type hinting is now possible using built-in collection types such as `list` or `dict`, removing the need to import a type from the `typing` module. This will bring the built-in types in-line with custom types, and make writing type annotations even simpler.

# Python 3.9 decorators allow any Python expression
@Controller.get_controller('left').buttons['X'].when_pressed
def trigger_event():
pass

# Python 3.8 collection type-hinting
from typing import List
def check_all_active(settings: List[str]) -> bool:
return True

# Python 3.9 using generic types directly
def check_all_active(settings: list[str]) -> bool:
return True

Python 3.9 also introduces a set-like merge operator (`|`) for dictionaries. Previously, the suggested way of merging dictionaries was with dictionary unpacking, which was introduced in Python 3.5. That method was surprisingly unreadable for Python and seldom used. The introduction of the `|` operator for dictionaries should aid readability, always a welcome improvement.

# Python 3.8 used dictionary unpacking to merge dictionaries
merged_dict = {**dict1, **dict2}

# Python 3.9 using the dictionary merge operator
merged_dict = dict1 | dict2

Often recognized for its robust standard library and immense third-party ecosystem, Python 3.9 continues to expand on things that many engineers need to build robust software. The zoneinfo module brings IANA time zone database support to the standard library, something that has long been reliant upon a third-party library, pytz.

With its welcome improvements and laying a strong foundation for continued innovation into the future, Python continues to be an attractive option for all levels of software development. There are many more changes coming in 3.9 than we've had time to comment on here, and you can real all about them in the official documentation. Python 3.9 is scheduled for release on October 5th of this year

Introducing the JBS Quick Launch Lab!

FREE 1/2 Day Assessment

Quantify what it will take to implement your next big idea! Our intensive 1/2 day session will deliver tangible timelines, costs, high-level requirements, and recommend architectures that will work best, and all for FREE. Let JBS show you why over 20 years of experience matters.
Yes, I'd Like A FREE Assessment