11"""OpenAPI spec validator validation decorators module."""
22
33import logging
4+ from collections .abc import Callable
45from collections .abc import Iterable
56from collections .abc import Iterator
67from functools import wraps
7- from typing import Any
8- from typing import Callable
8+ from typing import ParamSpec
99from typing import TypeVar
1010
1111from jsonschema .exceptions import ValidationError
1212
1313from openapi_spec_validator .validation .caches import CachedIterable
1414from openapi_spec_validator .validation .exceptions import OpenAPIValidationError
1515
16- Args = TypeVar ( "Args " )
16+ P = ParamSpec ( "P " )
1717T = TypeVar ("T" )
1818
1919log = logging .getLogger (__name__ )
2020
2121
2222def wraps_errors (
23- func : Callable [..., Any ],
24- ) -> Callable [... , Iterator [ValidationError ]]:
23+ func : Callable [P , Iterator [ ValidationError ] ],
24+ ) -> Callable [P , Iterator [ValidationError ]]:
2525 @wraps (func )
26- def wrapper (* args : Any , ** kwds : Any ) -> Iterator [ValidationError ]:
26+ def wrapper (* args : P . args , ** kwds : P . kwargs ) -> Iterator [ValidationError ]:
2727 errors = func (* args , ** kwds )
2828 for err in errors :
2929 if not isinstance (err , OpenAPIValidationError ):
@@ -36,21 +36,21 @@ def wrapper(*args: Any, **kwds: Any) -> Iterator[ValidationError]:
3636
3737
3838def wraps_cached_iter (
39- func : Callable [[ Args ] , Iterator [T ]],
40- ) -> Callable [[ Args ] , CachedIterable [T ]]:
39+ func : Callable [P , Iterator [T ]],
40+ ) -> Callable [P , CachedIterable [T ]]:
4141 @wraps (func )
42- def wrapper (* args : Any , ** kwargs : Any ) -> CachedIterable [T ]:
42+ def wrapper (* args : P . args , ** kwargs : P . kwargs ) -> CachedIterable [T ]:
4343 result = func (* args , ** kwargs )
4444 return CachedIterable (result )
4545
4646 return wrapper
4747
4848
4949def unwraps_iter (
50- func : Callable [[ Args ] , Iterable [T ]],
51- ) -> Callable [[ Args ] , Iterator [T ]]:
50+ func : Callable [P , Iterable [T ]],
51+ ) -> Callable [P , Iterator [T ]]:
5252 @wraps (func )
53- def wrapper (* args : Any , ** kwargs : Any ) -> Iterator [T ]:
53+ def wrapper (* args : P . args , ** kwargs : P . kwargs ) -> Iterator [T ]:
5454 result = func (* args , ** kwargs )
5555 return iter (result )
5656
0 commit comments