File tree Expand file tree Collapse file tree 4 files changed +12
-7
lines changed
Expand file tree Collapse file tree 4 files changed +12
-7
lines changed Original file line number Diff line number Diff line change 7979)
8080from .enums import enum_structure_factory , enum_unstructure_factory
8181from .errors import (
82+ CattrsError ,
8283 IterableValidationError ,
8384 IterableValidationNote ,
8485 StructureHandlerNotFoundError ,
@@ -708,7 +709,7 @@ def _structure_call(obj: Any, cl: type[T]) -> Any:
708709 @staticmethod
709710 def _structure_simple_literal (val , type ):
710711 if val not in type .__args__ :
711- raise Exception (f"{ val } not in literal { type } " )
712+ raise CattrsError (f"{ val } not in literal { type } " )
712713 return val
713714
714715 @staticmethod
@@ -717,7 +718,7 @@ def _structure_enum_literal(val, type):
717718 try :
718719 return vals [val ]
719720 except KeyError :
720- raise Exception (f"{ val } not in literal { type } " ) from None
721+ raise CattrsError (f"{ val } not in literal { type } " ) from None
721722
722723 def _structure_newtype (self , val : UnstructuredValue , type ) -> StructuredValue :
723724 base = get_newtype_base (type )
Original file line number Diff line number Diff line change 55
66from .._compat import is_subclass
77from ..converters import Converter , UnstructureHook
8+ from ..errors import CattrsError
89from ..fns import identity
910
1011
1112def validate_datetime (v , _ ):
1213 if not isinstance (v , datetime ):
13- raise Exception (f"Expected datetime, got { v } " )
14+ raise CattrsError (f"Expected datetime, got { v } " )
1415 return v
1516
1617
Original file line number Diff line number Diff line change 88from yaml import safe_dump , safe_load
99
1010from cattrs ._compat import FrozenSetSubscriptable
11- from cattrs .errors import ClassValidationError
11+ from cattrs .errors import CattrsError , ClassValidationError
1212from cattrs .preconf .pyyaml import make_converter
1313
1414from ..test_preconf import Everything , everythings , native_unions
@@ -70,13 +70,15 @@ class A:
7070 date: 1
7171 """
7272
73- with raises (ClassValidationError if detailed_validation else Exception ) as exc_info :
73+ with raises (
74+ ClassValidationError if detailed_validation else CattrsError
75+ ) as exc_info :
7476 converter .loads (bad_data , A )
7577
7678 if detailed_validation :
7779 assert (
7880 repr (exc_info .value .exceptions [0 ])
79- == "Exception ('Expected datetime, got 1')"
81+ == "CattrsError ('Expected datetime, got 1')"
8082 )
8183 assert (
8284 repr (exc_info .value .exceptions [1 ]) == "ValueError('Expected date, got 1')"
Original file line number Diff line number Diff line change 88
99from cattrs import BaseConverter
1010from cattrs ._compat import Literal
11+ from cattrs .errors import CattrsError
1112
1213from .untyped import enums_of_primitives
1314
@@ -27,7 +28,7 @@ def test_enum_failure(enum):
2728 converter = BaseConverter ()
2829 type = Literal [next (iter (enum ))]
2930
30- with raises (Exception ) as exc_info :
31+ with raises (CattrsError ) as exc_info :
3132 converter .structure ("" , type )
3233
3334 assert exc_info .value .args [0 ] == f" not in literal { type !r} "
You can’t perform that action at this time.
0 commit comments