@@ -90,25 +90,30 @@ def test_typing_Type_Union(ex):
90
90
assert ex in (str , list )
91
91
92
92
93
+ class Elem :
94
+ pass
95
+
96
+
93
97
@pytest .mark .parametrize (
94
98
"typ,coll_type,instance_of" ,
95
99
[
96
- (typing .Set [int ], set , int ),
97
- (typing .FrozenSet [int ], frozenset , int ),
98
- (typing .Dict [int , int ], dict , int ),
99
- (typing .DefaultDict [int , int ], collections .defaultdict , int ),
100
- (typing .KeysView [int ], type ({}.keys ()), int ),
101
- (typing .ValuesView [int ], type ({}.values ()), int ),
102
- (typing .List [int ], list , int ),
103
- (typing .Tuple [int ], tuple , int ),
104
- (typing .Tuple [int , ...], tuple , int ),
105
- (typing .Iterator [int ], typing .Iterator , int ),
106
- (typing .Sequence [int ], typing .Sequence , int ),
107
- (typing .Iterable [int ], typing .Iterable , int ),
108
- (typing .Mapping [int , None ], typing .Mapping , int ),
109
- (typing .Container [int ], typing .Container , int ),
110
- (typing .NamedTuple ("A_NamedTuple" , (("elem" , int ),)), tuple , int ),
100
+ (typing .Set [Elem ], set , Elem ),
101
+ (typing .FrozenSet [Elem ], frozenset , Elem ),
102
+ (typing .Dict [Elem , Elem ], dict , Elem ),
103
+ (typing .DefaultDict [Elem , Elem ], collections .defaultdict , Elem ),
104
+ (typing .KeysView [Elem ], type ({}.keys ()), Elem ),
105
+ (typing .ValuesView [Elem ], type ({}.values ()), Elem ),
106
+ (typing .List [Elem ], list , Elem ),
107
+ (typing .Tuple [Elem ], tuple , Elem ),
108
+ (typing .Tuple [Elem , ...], tuple , Elem ),
109
+ (typing .Iterator [Elem ], typing .Iterator , Elem ),
110
+ (typing .Sequence [Elem ], typing .Sequence , Elem ),
111
+ (typing .Iterable [Elem ], typing .Iterable , Elem ),
112
+ (typing .Mapping [Elem , None ], typing .Mapping , Elem ),
113
+ (typing .Container [Elem ], typing .Container , Elem ),
114
+ (typing .NamedTuple ("A_NamedTuple" , (("elem" , Elem ),)), tuple , Elem ),
111
115
],
116
+ ids = repr ,
112
117
)
113
118
@given (data = st .data ())
114
119
def test_specialised_collection_types (data , typ , coll_type , instance_of ):
@@ -119,17 +124,17 @@ def test_specialised_collection_types(data, typ, coll_type, instance_of):
119
124
assume (instances ) # non-empty collections without calling len(iterator)
120
125
121
126
122
- @given (from_type (typing .DefaultDict [int , int ]).filter (len ))
127
+ @given (from_type (typing .DefaultDict [Elem , Elem ]).filter (len ))
123
128
def test_defaultdict_values_type (ex ):
124
- assert all (isinstance (elem , int ) for elem in ex .values ())
129
+ assert all (isinstance (elem , Elem ) for elem in ex .values ())
125
130
126
131
127
- @given (from_type (typing .ItemsView [int , int ]).filter (len ))
132
+ @given (from_type (typing .ItemsView [Elem , Elem ]).filter (len ))
128
133
def test_ItemsView (ex ):
129
134
# See https://github.com/python/typing/issues/177
130
135
assert isinstance (ex , type ({}.items ()))
131
136
assert all (isinstance (elem , tuple ) and len (elem ) == 2 for elem in ex )
132
- assert all (all (isinstance (e , int ) for e in elem ) for elem in ex )
137
+ assert all (all (isinstance (e , Elem ) for e in elem ) for elem in ex )
133
138
134
139
135
140
def test_Optional_minimises_to_None ():
0 commit comments