1
1
"""Cattrs validation."""
2
- from typing import Any , Callable , List , TypeVar , Union , overload
2
+ from typing import Any , Callable , List , Tuple , Type , TypeVar , Union , overload
3
3
4
4
from attrs import NOTHING , frozen
5
5
37
37
class VAnnotation :
38
38
"""Use this with Annotated to get validation."""
39
39
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 )
41
44
42
45
43
46
def format_exception (exc : BaseException , type : Union [type , None ]) -> str :
@@ -153,13 +156,13 @@ def transform_error(
153
156
154
157
@overload
155
158
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 ]]:
158
161
...
159
162
160
163
161
164
@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 ]:
163
166
...
164
167
165
168
@@ -168,5 +171,5 @@ def ensure(type: Any, *validators: Any, elems: Any = NOTHING) -> Any:
168
171
# These are lists.
169
172
if not validators :
170
173
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