@@ -50,6 +50,17 @@ class NonUnionContainer:
50
50
a : typing .List [Parent ]
51
51
52
52
53
+ @attr .define
54
+ class CircularA :
55
+ a : int
56
+ other : "typing.List[CircularA]"
57
+
58
+
59
+ @attr .define
60
+ class CircularB (CircularA ):
61
+ b : int
62
+
63
+
53
64
IDS_TO_STRUCT_UNSTRUCT = {
54
65
"parent-only" : (Parent (1 ), dict (p = 1 )),
55
66
"child1-only" : (Child1 (1 , 2 ), dict (p = 1 , c1 = 2 )),
@@ -163,6 +174,21 @@ def test_structure_as_union():
163
174
assert res == [Child1 (1 , 2 )]
164
175
165
176
177
+ def test_circular_reference ():
178
+ c = Converter (include_subclasses = True )
179
+ struct = CircularB (a = 1 , other = [CircularB (a = 2 , other = [], b = 3 )], b = 4 )
180
+ unstruct = dict (a = 1 , other = [dict (a = 2 , other = [], b = 3 )], b = 4 )
181
+
182
+ res = c .unstructure (struct )
183
+ assert res == unstruct
184
+
185
+ res = c .unstructure (struct , CircularA )
186
+ assert res == unstruct
187
+
188
+ res = c .structure (unstruct , CircularA )
189
+ assert res == struct
190
+
191
+
166
192
@pytest .mark .parametrize (
167
193
"struct_unstruct" , IDS_TO_STRUCT_UNSTRUCT .values (), ids = IDS_TO_STRUCT_UNSTRUCT
168
194
)
0 commit comments