@@ -163,24 +163,22 @@ class A:
163
163
assert data == A (1 ) # type: ignore[call-arg]
164
164
165
165
166
- def test_list (module : DataclassModule ) -> None :
166
+ @pytest .mark .parametrize ("annotation_class" , (t .List , t .Sequence , t .MutableSequence ))
167
+ def test_list (module : DataclassModule , annotation_class : type ) -> None :
167
168
"""Build a generic list *without* setting a factory on the dataclass."""
168
-
169
- @module .dataclass
170
- class A :
171
- y : t .List [int ]
169
+ klass = type ("A" , (object ,), {"__annotations__" : {"y" : annotation_class [int ]}})
170
+ A = module .dataclass (klass )
172
171
173
172
schema = desert .schema_class (A )()
174
173
data = schema .load ({"y" : [1 ]})
175
174
assert data == A ([1 ]) # type: ignore[call-arg]
176
175
177
176
178
- def test_dict (module : DataclassModule ) -> None :
177
+ @pytest .mark .parametrize ("annotation_class" , (t .Dict , t .Mapping , t .MutableMapping ))
178
+ def test_dict (module : DataclassModule , annotation_class : type ) -> None :
179
179
"""Build a dict without setting a factory on the dataclass."""
180
-
181
- @module .dataclass
182
- class A :
183
- y : t .Dict [int , int ]
180
+ klass = type ("A" , (object ,), {"__annotations__" : {"y" : annotation_class [int , int ]}})
181
+ A = module .dataclass (klass )
184
182
185
183
schema = desert .schema_class (A )()
186
184
data = schema .load ({"y" : {1 : 2 , 3 : 4 }})
@@ -527,15 +525,12 @@ class A:
527
525
desert .schema_class (A )
528
526
529
527
530
- @pytest .mark .skipif (
531
- sys .version_info [:2 ] <= (3 , 6 ), reason = "3.6 has isinstance(t.Sequence[int], type)."
532
- )
533
528
def test_raise_unknown_generic (module : DataclassModule ) -> None :
534
529
"""Raise UnknownType for unknown generics."""
535
530
536
531
@module .dataclass
537
532
class A :
538
- x : t .Sequence [int ]
533
+ x : t .Iterable [int ]
539
534
540
535
with pytest .raises (desert .exceptions .UnknownType ):
541
536
desert .schema_class (A )
0 commit comments