From fd22d4544fb871c4025e88aee7ee0f370ad596ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tin=20Tvrtkovi=C4=87?= Date: Tue, 23 Jan 2024 23:25:59 +0100 Subject: [PATCH] Introduce VAnnotation --- src/cattrs/v/__init__.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cattrs/v/__init__.py b/src/cattrs/v/__init__.py index b7e73b0d..0329fc3a 100644 --- a/src/cattrs/v/__init__.py +++ b/src/cattrs/v/__init__.py @@ -1,5 +1,7 @@ """Cattrs validation.""" -from typing import Callable, List, Union +from typing import Any, Callable, List, Union + +from attrs import frozen from .._compat import ExceptionGroup from ..errors import ( @@ -31,6 +33,13 @@ ] +@frozen +class VAnnotation: + """Use this with Annotated to get validation.""" + + validators: tuple[Callable[[Any], Any]] + + def format_exception(exc: BaseException, type: Union[type, None]) -> str: """The default exception formatter, handling the most common exceptions.