File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -113,3 +113,19 @@ class Foo:
113
113
Foo .struc (dict (union = dict (a = "some_value" )))
114
114
except Exception as exc :
115
115
raise AssertionError (f"Exception { repr (exc )} was raised when it should not have been." )
116
+
117
+
118
+
119
+
120
+ def test_struc_with_typed_dict_registered_hook ():
121
+ from typing_extensions import TypedDict
122
+ class Foo (TypedDict ):
123
+ bar : int
124
+
125
+ register_struc_hook (Foo , lambda x , _ : x )
126
+
127
+ @Cat
128
+ class Thing :
129
+ a : bool
130
+
131
+ Thing .struc (dict (a = True ))
Original file line number Diff line number Diff line change @@ -117,9 +117,9 @@ def get_default_converter():
117
117
return _TYPECATS_DEFAULT_CONVERTER
118
118
119
119
120
- def register_struc_hook (* args , ** kwargs ):
120
+ def register_struc_hook (typ , func , ** _ ):
121
121
"""Use this to register cattrs structuring hooks on the internal cattrs Converter"""
122
- _TYPECATS_DEFAULT_CONVERTER .register_structure_hook ( * args , ** kwargs )
122
+ _TYPECATS_DEFAULT_CONVERTER .register_structure_hook_func ( lambda t : t == typ , func )
123
123
124
124
125
125
def register_unstruc_hook (* args , ** kwargs ):
You can’t perform that action at this time.
0 commit comments