]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-111729: update generic syntax for `typing.Concatenate` sample code in ...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 7 Nov 2023 01:00:16 +0000 (02:00 +0100)
committerGitHub <noreply@github.com>
Tue, 7 Nov 2023 01:00:16 +0000 (01:00 +0000)
(cherry picked from commit c3e19c3a62e82b9e77563e934059895b6230de6e)

Co-authored-by: 方糖 <cubesugarcheese@qq.com>
Doc/library/typing.rst

index 44665b63487b7205974d6b2aa68f8184c9cc2298..7cec24464a4cb9b737e6cd61ed54fa0d13e10bf6 100644 (file)
@@ -1135,16 +1135,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.