Skip to content

Commit 04512b7

Browse files
committed
More fixes
1 parent 386fdf0 commit 04512b7

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/cattrs/v/__init__.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Cattrs validation."""
2-
from typing import Any, Callable, List, TypeVar, Union, overload
2+
from typing import Any, Callable, List, Tuple, Type, TypeVar, Union, overload
33

44
from attrs import NOTHING, frozen
55

@@ -37,7 +37,10 @@
3737
class VAnnotation:
3838
"""Use this with Annotated to get validation."""
3939

40-
validators: tuple[Callable[[Any], Any]]
40+
validators: Tuple[Callable[[Any], Any]]
41+
42+
def __init__(self, *validators: Callable[[Any], Any]):
43+
self.__attrs_init__(validators)
4144

4245

4346
def format_exception(exc: BaseException, type: Union[type, None]) -> str:
@@ -153,13 +156,13 @@ def transform_error(
153156

154157
@overload
155158
def ensure(
156-
type: type[list[T]], *validators: Callable[[list[T]], Any], elems: type[E]
157-
) -> type[list[E]]:
159+
type: Type[List[T]], *validators: Callable[[List[T]], Any], elems: Type[E]
160+
) -> Type[List[E]]:
158161
...
159162

160163

161164
@overload
162-
def ensure(type: type[T], *validators: Callable[[T], Any]) -> type[T]:
165+
def ensure(type: Type[T], *validators: Callable[[T], Any]) -> Type[T]:
163166
...
164167

165168

@@ -168,5 +171,5 @@ def ensure(type: Any, *validators: Any, elems: Any = NOTHING) -> Any:
168171
# These are lists.
169172
if not validators:
170173
return type[elems]
171-
return Annotated[type, VAnnotation(validators)]
172-
return Annotated[type, VAnnotation(validators)]
174+
return Annotated[type, VAnnotation(*validators)]
175+
return Annotated[type, VAnnotation(*validators)]

0 commit comments

Comments
 (0)