Skip to content

Commit 430d0e7

Browse files
committed
More fixes
1 parent 7405d20 commit 430d0e7

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/cattrs/v/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Cattrs validation."""
22

3-
from typing import Any, Callable, List, TypeVar, Union, overload
3+
from typing import Any, Callable, List, Tuple, Type, TypeVar, Union, overload
44

55
from attrs import NOTHING, frozen
66

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

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

4346

4447
def format_exception(exc: BaseException, type: Union[type, None]) -> str:
@@ -154,18 +157,18 @@ def transform_error(
154157

155158
@overload
156159
def ensure(
157-
type: type[list[T]], *validators: Callable[[list[T]], Any], elems: type[E]
158-
) -> type[list[E]]: ...
160+
type: Type[List[T]], *validators: Callable[[List[T]], Any], elems: Type[E]
161+
) -> Type[List[E]]: ...
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
def ensure(type: Any, *validators: Any, elems: Any = NOTHING) -> Any:
166169
if elems is not NOTHING:
167170
# These are lists.
168171
if not validators:
169172
return type[elems]
170-
return Annotated[type, VAnnotation(validators)]
171-
return Annotated[type, VAnnotation(validators)]
173+
return Annotated[type, VAnnotation(*validators)]
174+
return Annotated[type, VAnnotation(*validators)]

0 commit comments

Comments
 (0)