]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111729: update generic syntax for `typing.Concatenate` sample code in `Doc/library...
author方糖 <cubesugarcheese@qq.com>
Tue, 7 Nov 2023 00:53:17 +0000 (08:53 +0800)
committerGitHub <noreply@github.com>
Tue, 7 Nov 2023 00:53:17 +0000 (16:53 -0800)
use new generic syntax

Doc/library/typing.rst

index f82f53514a71dc0f46bff85bf9983b87739a691c..a4767d222d0af79a60be7f301a75f931220d2884 100644 (file)
@@ -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.