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.
2020.11.07
First version. a2 was released on 2020-10-04, but I wrote it based on what's new.
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.
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.
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.
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.
A method called bit_count ()
has been added to a variable of type int
. This is to return the number of 1
when the integer number is expressed in binary. It seems that this is also called Population Count (or pop count), but basically it is the same as doing bin (a) .count ('1')
, and it can be processed faster. It seems that it has become.
The view object returned by the dictionary-type methods keys ()
, values ()
, and items ()
has an attribute called mapping
that allows you to access the original dictionary-type data.
Decimal and Fraction can no longer be used as integer argument values. For example, in Python-3.9., The following code issued DeprecationWarning
, but from python-3.10, an error occurs.
from decimal import Decimal
i = Decimal(97)
print(chr(i))
(Not yet)
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.
str ()
bytes ()
bytesarray ()
is faster (30-40% for small objects)runpy
module imports fewer modules, and the startup time is on average 1.3 times faster when run with python -m module name
.find_loader ()
, find_module ()
, load_module ()
, __package__
and __loader__
attributes will be removed in a future version.--The complex
class's __int__
, __float__
, __floordiv__
, __mod__
, __divmod__
, __rfloordiv__
, __rmod__
, __rdivmod__
methods have been removed.
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