gh-111729: update generic syntax for typing.Concatenate sample code in Doc/library/typing.rst (#111734)

use new generic syntax
This commit is contained in:
方糖 2023-11-07 08:53:17 +08:00 committed by GitHub
parent 3e99c9cbf6
commit c3e19c3a62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View 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.