What's new in Python 3.10 (Summary)

Introduction

I've posted an article summarizing the contents of What's New since Python 3.5.

The release cycle has been one year, and when I thought that 3.9 had just come out the other day, a2 of 3.10 had already come out (sweat). As I wrote in here, the next alpha version will be released at the same time as the official version is released, so it's on schedule, but the pace is a bit fast. (^^;

Still, I'm curious about what will come out in the next release, so I'd like to extract and summarize it. The next version of 3.9 is 3.10 instead of 4.0 (laughs). First of all, the usual development roadmap (PEP-619).

If it goes according to schedule, 3.10 will come out in October 2021, just one year after 3.9.

Change log

2020.11.07

First version. a2 was released on 2020-10-04, but I wrote it based on what's new.

New features of interest

PEP 563: Annotation lazy evaluation defaults

As a new feature of Python-3.7, "[Delay annotation evaluation](https://qiita.com/ksato9700/items/35a0bdc04693b3b09757#pep-563-%E3%82%A2%E3%83%8E%E3%83] % 86% E3% 83% BC% E3% 82% B7% E3% 83% A7% E3% 83% B3% E3% 81% AE% E8% A9% 95% E4% BE% A1% E3% 82% 92 % E9% 81% 85% E3% 82% 89% E3% 81% 9B% E3% 82% 8B) ", but that behavior is now the default. So, until now, to enable lazy evaluation

from __future__ import annotations

It was necessary to put the import statement, but from 3.10 it will not be necessary. At 3.7, it was written that "Python-4.0 will be the standard", but it was 3.10.

And some functions of type annotation system have changed. One is the behavior of inspect.signature, which returns the type itself instead of returning the string representation of the type. For example, if you try to display the parameter type of a function with the following code,

from __future__ import annotations
import inspect

def func_a(a: int, b: list, c: C):
    pass

class C:
    pass

sig = inspect.signature(func_a)

for (name, param) in sig.parameters.items():
    print(name, repr(param.annotation))

Before Python-3.9

a 'int'
b 'list'
c 'C'

The character string is returned like, but from python-3.10

a <class 'int'>
b <class 'list'>
c <class '__main__.C'>

A class object of type will be returned in the form of. If class C is not found, the string'C' will be returned as before.

PEP 613: Type alias annotation

Type aliases (aliasing types) were introduced in PEP 484, but are represented by top-level assignment expressions. Therefore, there was a problem that it was difficult to distinguish it from the assignment to a normal variable. An annotation called TypeAlias is added to make it clear that it is a type alias.

For example, until now

IntType = int	

What was written

IntType: TypeAlias = int

You will be able to write like this.

PEP 604: Complex operator

This is also a type relationship change, but until now, when annotating variables that take two or more types,

number: Union[int, float]

Where I had to write

number: int | float

You will be able to write. It feels like incorporating the notation that is also used in TypeScript.

PEP 618: Additional parameters for the zip function

A parameter called stric is added to thezip ()function, and when this is True it checks that the two iterables to zip are of the same length. If the lengths are different, a ValueError exception will be thrown.

Other language changes

  from decimal import Decimal
  i = Decimal(97)
  print(chr(i))

Newly added module

(Not yet)

Module improvements

base64

Base64.b43hexencode () and base64. To support the extended Hex alphabet defined in [RFC-4648](https://tools.ietf.org/html/rfc4648.html#section-7) b43hexdecode () was added. The regular Base32 alphabet does not use '0' and '1', which look similar to other characters, but this extended Hex alphabet does use them and maps them instead. It is characterized by the fact that the characters are sorted (though it is a mystery what makes me happy).

curses

You will be able to use the extended colors introduced in ncurses 6.1. You can check if the ncurses library you are using from Python supports this with curses.has_extended_color_support ().

glob

The root_dir and dir_fd parameters have been added to glob () and iglob () to allow you to specify the root directory for file searches. The former is a path-like object and the latter specifies the file descriptor of the root directory.

types

types.EllipsisType, types.NoneType, and types.NotImplementedType have been (re) introduced.

optimisation

Scheduled to be abolished

Function removed

--The complex class's __int__, __float__, __floordiv__, __mod__, __divmod__, __rfloordiv__, __rmod__, __rdivmod__ methods have been removed.

Summary

Here's a summary of the changes in Python 3.10. There are still 11 months left until the official release of a2, so I think there will be changes in the future, but I would like to keep up with it.

Recommended Posts

What's new in Python 3.10 (Summary)
What's new in Python 3.9 (Summary)
What's new in Python 3.5
What's new in Python 3.6
What's new in Python 3.4.0 (2) --enum
What's new in python3.9 Merge dictionaries
New in Python 3.4.0 (1)-pathlib
Face detection summary in Python
Python Summary
Python summary
Quadtree in Python --2
Python in optimization
CURL in python
New in Python 3.9 (2)-Sort directed acyclic graphs in Python
Geocoding in python
SendKeys in Python
What's new in Django 1.8 Conditional Expressions #djangoja
Meta-analysis in Python
Unittest in python
Python tutorial summary
Summary of various for statements in Python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
pandas 1.2.0 What's new
New features in Python 3.4.0 (3)-Single-dispatch generic functions
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
Summary of built-in methods in Python list
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
python related summary
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
What's new in datetime that is a bit more useful in Python 3
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
Python basics summary
flatten in python