From 8e8c504c624579eeb38b7806e3093947e24f71d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E7=B3=96?= Date: Sat, 4 Nov 2023 17:53:39 +0800 Subject: [PATCH] use new generic syntax --- Doc/library/typing.rst | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index f82f53514a71dc..a4767d222d0af7 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -1145,16 +1145,13 @@ These can be used as types in annotations. They all support subscription using from collections.abc import Callable from threading import Lock - from typing import Concatenate, ParamSpec, TypeVar - - P = ParamSpec('P') - R = TypeVar('R') + from typing import Concatenate # Use this lock to ensure that only one thread is executing a function # at any time. my_lock = Lock() - def with_lock(f: Callable[Concatenate[Lock, P], R]) -> Callable[P, R]: + def with_lock[**P, R](f: Callable[Concatenate[Lock, P], R]) -> Callable[P, R]: '''A type-safe decorator which provides a lock.''' def inner(*args: P.args, **kwargs: P.kwargs) -> R: # Provide the lock as the first argument.