What’s New In Python 3.9

BadariNath
2 min readSep 25, 2021

--

New syntax features:

  • PEP 584, union operators added to dict;
  • PEP 585, type hinting generics in standard collections;
  • PEP 614, relaxed grammar restrictions on decorators.

New built-in features:

  • PEP 616, string methods to remove prefixes and suffixes.

New features in the standard library:

  • PEP 593, flexible function and variable annotations;
  • os.pidfd_open() added that allows process management without races and signals.

New library modules:

  • PEP 615, the IANA Time Zone Database is now present in the standard library in the zoneinfo module;
  • an implementation of a topological sort of a graph is now provided in the new graphlib module.

New Features

Dictionary Merge & Update Operators

Merge (|) and update (|=) operators have been added to the built-in dict class. Those complement the existing dict.update and {**d1, **d2} methods of merging dictionaries.

New String Methods to Remove Prefixes and Suffixes

str.removeprefix(prefix) and str.removesuffix(suffix) have been added to easily remove an unneeded prefix or a suffix from a string. Corresponding bytes, bytearray, and collections.UserString methods have also been added.

New Modules

zoneinfo

The zoneinfo module brings support for the IANA time zone database to the standard library. It adds zoneinfo.ZoneInfo, a concrete datetime.tzinfo implementation backed by the system’s time zone data.

graphlib

A new module, graphlib, was added that contains the graphlib.TopologicalSorter class to offer functionality to perform topological sorting of graphs.

CPython bytecode changes

  • The LOAD_ASSERTION_ERROR opcode was added for handling the assert statement. Previously, the assert statement would not work correctly if the AssertionError exception was being shadowed.
  • The COMPARE_OP opcode was split into four distinct instructions:
  • COMPARE_OP for rich comparisons
  • IS_OP for ‘is’ and ‘is not’ tests
  • CONTAINS_OP for ‘in’ and ‘not in’ test
  • JUMP_IF_NOT_EXC_MATCH for checking exceptions in ‘try-except’ statements.

--

--

BadariNath
BadariNath

Written by BadariNath

I'm a graduate student. I'm so interested on writing blogs about tech. so keep follow and update about tech changes in world

No responses yet