What’s new in Python 3.10

Python 3.10, the latest in-development version of Python, has been released. Intrepid Python developers are encouraged to test their code against it, with proper precautions

Structural pattern matching

An outgrowth of previous failed attempts to add a switch/case-like syntax to Python, structural pattern matching lets you match variables against one of a set of possible values (as with switch/case in other languages). But it also allows you to match against patterns of values — e.g., an object with a certain property set to a certain value. This greatly expands the range of possibilities, and makes it possible to write code that quickly encompasses a variety of scenarios. 

More precise error reporting

Python’s error reporting has long been at the mercy of the whims of its parser. Python 3.9 rolled out an entirely new parser — faster, more robust, easier for the Python team to maintain, and less riddled with internal hacks.

Parameter specification variables

Python’s typing module, used to annotate code with type information, lets you describe the types of a callable (e.g., a function). But that type information can’t be propagated across callables. This makes it hard to annotate things like function decorators.

Two new additions to typing, typing.ParamSpec and typing.Concatenate, make it possible to annotate callables with more abstract type definition information.

Other major changes in Python 3.10

  • Union types can now be expressed as X|Y, instead of Union[X,Y], for brevity
  • The zip built-in, which braids together the results of multiple iterables, now has a strict keyword. When set to True, it causes zip to raise an exception if one of the iterables is exhausted before the others
  • with statements now support multi-line, parenthetical syntax
  • Variables can now be declared as type aliases, to allow forward references, more robust errors involving types, and better distinctions between type declarations in scopes
  • OpenSSL 1.1.1 or newer is now required to build CPython. This modernizes one of CPython’s key dependencies

Reference: https://www.infoworld.com/article/3617460/whats-new-in-python-310.html

Leave a Comment

Your email address will not be published. Required fields are marked *