Python3.10の新機能 require-xxx

(その1) パターンマッチ(その2) with文のネスト(その3) エラーメッセージの改善(その4) | 演算子によるユニオン型の指定(その5) パラメータ仕様変数(その6) 明示的な型エイリアス(その7) ユーザ定義型ガード(その8) OpenSSL 1.1.1が必須に(その9) zip()関数に引数 strict を追加(その10) Dataclassでslotsが利用可能に

PEP 626, Precise line numbers for debugging and other tools.

PEP 632, Deprecate distutils module.

PEP 597, Add optional EncodingWarning

0xfor(d)-University

0xfor-d*University

 [15or x in (1, 2, 3)]

For pretty much the same reason that "1+2" is not parsed as an invalid integer.

0xfor1 File "", line 1 0xfor1 ^ SyntaxError: invalid hexadecimal literal 0xfor 1

:1: DeprecationWarning: invalid hexadecimal literal

https://docs.python.org/3/reference/lexical_analysis.html#whitespace-between-tokens

Except at the beginning of a logical line or in string literals, the whitespace characters space, tab and formfeed can be used interchangeably to separate tokens. Whitespace is needed between two tokens only if their concatenation could otherwise be interpreted as a different token (e.g., ab is one token, but a b is two tokens).

x - set(y) {'_', 'EncodingWarning', 'anext', 'aiter'}

Keyword-only fields¶

https://bugs.python.org/issue4356

Added the possibility of providing a key function to the APIs in the bisect module. (Contributed by Raymond Hettinger in bpo-4356.)

https://github.com/python/cpython/commit/871934d4cf00687b3d1411c6e344af311646c1ae

Currently Python accepts numeric literals immediately followed by keywords, for example 0in x, 1or x, 0if 1else 2. It allows confusing and ambigious expressions like [0x1for x in y] (which can be interpreted as [0x1 for x in y] or [0x1f or x in y]). Starting in this release, a deprecation warning is raised if the numeric literal is immediately followed by one of keywords and, else, for, if, in, is and or. If future releases it will be changed to syntax warning, and finally to syntax error. (Contributed by Serhiy Storchaka in bpo-43833).

PEP 618, Add Optional Length-Checking To zip.

PEP 626, Precise line numbers for debugging and other tools.

PEP 632, Deprecate distutils module.

PEP 644, Require OpenSSL 1.1.1 or newer

Better error messages¶

PEP 604: New Type Union Operator¶ int|float

PEP 612: Parameter Specification Variables¶

from typing import Awaitable, Callable, ParamSpec, TypeVar

P = ParamSpec("P") R = TypeVar("R")

def add_logging(f: Callable[P, R]) -> Callable[P, Awaitable[R]]: async def inner(args: P.args, **kwargs: P.kwargs) -> R: await log_to_database() return f(args, **kwargs) return inner

@add_logging def takes_int_str(x: int, y: str) -> int: return x + 7

from typing import Concatenate

def with_request(f: Callable[Concatenate[Request, P], R]) -> Callable[P, R]: def inner(args: P.args, **kwargs: P.kwargs) -> R: return f(Request(), args, **kwargs) return inner

@with_request def takes_int_str(request: Request, x: int, y: str) -> int:

use request

return x + 7

takes_int_str(1, "A") # Accepted takes_int_str("B", 2) # Correctly rejected by the type checker

Copyright © 2001-2021 python.jp Privacy Policy python_japan
Amazon.co.jpアソシエイト
Amazonで他のPython書籍を検索