14
14
IO ,
15
15
Any ,
16
16
AnyStr ,
17
- Callable ,
18
17
Dict ,
19
18
Generic ,
20
19
List ,
21
- Mapping ,
22
- Match ,
23
20
NewType ,
24
21
Optional ,
25
- Pattern ,
26
22
Tuple ,
27
23
Type ,
28
24
TypeVar ,
@@ -146,20 +142,20 @@ def __getitem__(self, params): # noqa: ANN001, ANN204
146
142
pytest .param (Tuple , "typing" , "Tuple" , (), id = "Tuple" ), # noqa: UP006
147
143
pytest .param (Tuple [str , int ], "typing" , "Tuple" , (str , int ), id = "Tuple_parametrized" ), # noqa: UP006
148
144
pytest .param (Union [str , int ], "typing" , "Union" , (str , int ), id = "Union" ), # noqa: UP007
149
- pytest .param (Callable , "typing" , "Callable" , (), id = "Callable" ),
150
- pytest .param (Callable [..., str ], "typing" , "Callable" , (..., str ), id = "Callable_returntype" ),
151
- pytest .param (Callable [[int , str ], str ], "typing" , "Callable" , (int , str , str ), id = "Callable_all_types" ),
145
+ pytest .param (collections . abc . Callable , "typing" , "Callable" , (), id = "Callable" ),
146
+ pytest .param (collections . abc . Callable [..., str ], "typing" , "Callable" , (..., str ), id = "Callable_returntype" ),
147
+ pytest .param (collections . abc . Callable [[int , str ], str ], "typing" , "Callable" , (int , str , str ), id = "Callable_all_types" ),
152
148
pytest .param (
153
149
AbcCallable [[int , str ], str ], # type: ignore[type-arg,misc,valid-type]
154
150
"collections.abc" ,
155
151
"Callable" ,
156
152
(int , str , str ),
157
153
id = "collections.abc.Callable_all_types" ,
158
154
),
159
- pytest .param (Pattern , "typing" , "Pattern" , (), id = "Pattern" ),
160
- pytest .param (Pattern [str ], "typing" , "Pattern" , (str ,), id = "Pattern_parametrized" ),
161
- pytest .param (Match , "typing" , "Match" , (), id = "Match" ),
162
- pytest .param (Match [str ], "typing" , "Match" , (str ,), id = "Match_parametrized" ),
155
+ pytest .param (re . Pattern , "typing" , "Pattern" , (), id = "Pattern" ),
156
+ pytest .param (re . Pattern [str ], "typing" , "Pattern" , (str ,), id = "Pattern_parametrized" ),
157
+ pytest .param (re . Match , "typing" , "Match" , (), id = "Match" ),
158
+ pytest .param (re . Match [str ], "typing" , "Match" , (str ,), id = "Match_parametrized" ),
163
159
pytest .param (IO , "typing" , "IO" , (), id = "IO" ),
164
160
pytest .param (W , "typing" , "NewType" , (str ,), id = "W" ),
165
161
pytest .param (P , "typing" , "ParamSpec" , (), id = "P" ),
@@ -197,26 +193,26 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
197
193
pytest .param (Any , ":py:data:`~typing.Any`" , id = "Any" ),
198
194
pytest .param (AnyStr , ":py:data:`~typing.AnyStr`" , id = "AnyStr" ),
199
195
pytest .param (Generic [T ], r":py:class:`~typing.Generic`\ \[:py:class:`~typing.TypeVar`\ \(``T``)]" , id = "Generic" ),
200
- pytest .param (Mapping , ":py:class:`~typing.Mapping`" , id = "Mapping" ),
196
+ pytest .param (collections . abc . Mapping , ":py:class:`~typing.Mapping`" , id = "Mapping" ),
201
197
pytest .param (
202
- Mapping [T , int ], # type: ignore[valid-type]
198
+ collections . abc . Mapping [T , int ], # type: ignore[valid-type]
203
199
r":py:class:`~typing.Mapping`\ \[:py:class:`~typing.TypeVar`\ \(``T``), :py:class:`int`]" ,
204
200
id = "Mapping-T-int" ,
205
201
),
206
202
pytest .param (
207
- Mapping [str , V_contra ], # type: ignore[valid-type]
203
+ collections . abc . Mapping [str , V_contra ], # type: ignore[valid-type]
208
204
r":py:class:`~typing.Mapping`\ \[:py:class:`str`, :py:class:`~typing.TypeVar`\ \("
209
205
"``V_contra``, contravariant=True)]" ,
210
206
id = "Mapping-T-int-contra" ,
211
207
),
212
208
pytest .param (
213
- Mapping [T , U_co ], # type: ignore[valid-type]
209
+ collections . abc . Mapping [T , U_co ], # type: ignore[valid-type]
214
210
r":py:class:`~typing.Mapping`\ \[:py:class:`~typing.TypeVar`\ \(``T``), "
215
211
r":py:class:`~typing.TypeVar`\ \(``U_co``, covariant=True)]" ,
216
212
id = "Mapping-T-int-co" ,
217
213
),
218
214
pytest .param (
219
- Mapping [str , bool ],
215
+ collections . abc . Mapping [str , bool ],
220
216
r":py:class:`~typing.Mapping`\ \[:py:class:`str`, :py:class:`bool`]" ,
221
217
id = "Mapping-str-bool" ,
222
218
),
@@ -290,29 +286,29 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
290
286
r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:class:`bool`, :py:obj:`None`]" ,
291
287
id = "Optional-Union-str-bool" ,
292
288
),
293
- pytest .param (Callable , ":py:data:`~typing.Callable`" , id = "Callable" ),
289
+ pytest .param (collections . abc . Callable , ":py:data:`~typing.Callable`" , id = "Callable" ),
294
290
pytest .param (
295
- Callable [..., int ],
291
+ collections . abc . Callable [..., int ],
296
292
r":py:data:`~typing.Callable`\ \[:py:data:`...<Ellipsis>`, :py:class:`int`]" ,
297
293
id = "Callable-Ellipsis-int" ,
298
294
),
299
295
pytest .param (
300
- Callable [[int ], int ],
296
+ collections . abc . Callable [[int ], int ],
301
297
r":py:data:`~typing.Callable`\ \[\[:py:class:`int`], :py:class:`int`]" ,
302
298
id = "Callable-int-int" ,
303
299
),
304
300
pytest .param (
305
- Callable [[int , str ], bool ],
301
+ collections . abc . Callable [[int , str ], bool ],
306
302
r":py:data:`~typing.Callable`\ \[\[:py:class:`int`, :py:class:`str`], :py:class:`bool`]" ,
307
303
id = "Callable-int-str-bool" ,
308
304
),
309
305
pytest .param (
310
- Callable [[int , str ], None ],
306
+ collections . abc . Callable [[int , str ], None ],
311
307
r":py:data:`~typing.Callable`\ \[\[:py:class:`int`, :py:class:`str`], :py:obj:`None`]" ,
312
308
id = "Callable-int-str" ,
313
309
),
314
310
pytest .param (
315
- Callable [[T ], T ],
311
+ collections . abc . Callable [[T ], T ],
316
312
r":py:data:`~typing.Callable`\ \[\[:py:class:`~typing.TypeVar`\ \(``T``)],"
317
313
r" :py:class:`~typing.TypeVar`\ \(``T``)]" ,
318
314
id = "Callable-T-T" ,
@@ -322,8 +318,8 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
322
318
r":py:class:`~collections.abc.Callable`\ \[\[:py:class:`int`, :py:class:`str`], :py:class:`bool`]" ,
323
319
id = "AbcCallable-int-str-bool" ,
324
320
),
325
- pytest .param (Pattern , ":py:class:`~typing.Pattern`" , id = "Pattern" ),
326
- pytest .param (Pattern [str ], r":py:class:`~typing.Pattern`\ \[:py:class:`str`]" , id = "Pattern-str" ),
321
+ pytest .param (re . Pattern , ":py:class:`~typing.Pattern`" , id = "Pattern" ),
322
+ pytest .param (re . Pattern [str ], r":py:class:`~typing.Pattern`\ \[:py:class:`str`]" , id = "Pattern-str" ),
327
323
pytest .param (IO , ":py:class:`~typing.IO`" , id = "IO" ),
328
324
pytest .param (IO [str ], r":py:class:`~typing.IO`\ \[:py:class:`str`]" , id = "IO-str" ),
329
325
pytest .param (Metaclass , f":py:class:`~{ __name__ } .Metaclass`" , id = "Metaclass" ),
@@ -384,6 +380,7 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
384
380
),
385
381
]
386
382
383
+
387
384
@pytest .mark .parametrize (("annotation" , "expected_result" ), _CASES )
388
385
def test_format_annotation (inv : Inventory , annotation : Any , expected_result : str ) -> None :
389
386
conf = create_autospec (Config , _annotation_globals = globals (), always_use_bars_union = False )
0 commit comments