@@ -201,87 +201,87 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
201201 (type , ":py:class:`type`" ),
202202 (collections .abc .Callable , ":py:class:`~collections.abc.Callable`" ),
203203 (Type , ":py:class:`~typing.Type`" ),
204- (Type [A ], ":py:class:`~typing.Type`\\ [:py:class:`~%s.A`]" % __name__ ),
204+ (Type [A ], ":py:class:`~typing.Type`\\ \\ [:py:class:`~%s.A`]" % __name__ ),
205205 (Any , ":py:data:`~typing.Any`" ),
206206 (AnyStr , ":py:data:`~typing.AnyStr`" ),
207- (Generic [T ], ":py:class:`~typing.Generic`\\ [:py:class:`~typing.TypeVar`\\ (``T``)]" ),
207+ (Generic [T ], ":py:class:`~typing.Generic`\\ \\ [:py:class:`~typing.TypeVar`\\ (``T``)]" ),
208208 (Mapping , ":py:class:`~typing.Mapping`" ),
209209 (
210210 Mapping [T , int ], # type: ignore[valid-type]
211- ":py:class:`~typing.Mapping`\\ [:py:class:`~typing.TypeVar`\\ (``T``), :py:class:`int`]" ,
211+ ":py:class:`~typing.Mapping`\\ \\ [:py:class:`~typing.TypeVar`\\ (``T``), :py:class:`int`]" ,
212212 ),
213213 (
214214 Mapping [str , V_contra ], # type: ignore[valid-type]
215- ":py:class:`~typing.Mapping`\\ [:py:class:`str`, :py:class:`~typing.TypeVar`\\ ("
215+ ":py:class:`~typing.Mapping`\\ \\ [:py:class:`str`, :py:class:`~typing.TypeVar`\\ ("
216216 "``V_contra``, contravariant=True)]" ,
217217 ),
218218 (
219219 Mapping [T , U_co ], # type: ignore[valid-type]
220- ":py:class:`~typing.Mapping`\\ [:py:class:`~typing.TypeVar`\\ (``T``), "
220+ ":py:class:`~typing.Mapping`\\ \\ [:py:class:`~typing.TypeVar`\\ (``T``), "
221221 ":py:class:`~typing.TypeVar`\\ (``U_co``, covariant=True)]" ,
222222 ),
223- (Mapping [str , bool ], ":py:class:`~typing.Mapping`\\ [:py:class:`str`, :py:class:`bool`]" ),
223+ (Mapping [str , bool ], ":py:class:`~typing.Mapping`\\ \\ [:py:class:`str`, :py:class:`bool`]" ),
224224 (Dict , ":py:class:`~typing.Dict`" ),
225225 (
226226 Dict [T , int ], # type: ignore[valid-type]
227- ":py:class:`~typing.Dict`\\ [:py:class:`~typing.TypeVar`\\ (``T``), :py:class:`int`]" ,
227+ ":py:class:`~typing.Dict`\\ \\ [:py:class:`~typing.TypeVar`\\ (``T``), :py:class:`int`]" ,
228228 ),
229229 (
230230 Dict [str , V_contra ], # type: ignore[valid-type]
231- ":py:class:`~typing.Dict`\\ [:py:class:`str`, :py:class:`~typing.TypeVar`\\ (``V_contra``, contravariant=True)]" ,
231+ ":py:class:`~typing.Dict`\\ \\ [:py:class:`str`, :py:class:`~typing.TypeVar`\\ (``V_contra``, contravariant=True)]" , # noqa: E501
232232 ),
233233 (
234234 Dict [T , U_co ], # type: ignore[valid-type]
235- ":py:class:`~typing.Dict`\\ [:py:class:`~typing.TypeVar`\\ (``T``),"
235+ ":py:class:`~typing.Dict`\\ \\ [:py:class:`~typing.TypeVar`\\ (``T``),"
236236 " :py:class:`~typing.TypeVar`\\ (``U_co``, covariant=True)]" ,
237237 ),
238- (Dict [str , bool ], ":py:class:`~typing.Dict`\\ [:py:class:`str`, :py:class:`bool`]" ),
238+ (Dict [str , bool ], ":py:class:`~typing.Dict`\\ \\ [:py:class:`str`, :py:class:`bool`]" ),
239239 (Tuple , ":py:data:`~typing.Tuple`" ),
240- (Tuple [str , bool ], ":py:data:`~typing.Tuple`\\ [:py:class:`str`, :py:class:`bool`]" ),
241- (Tuple [int , int , int ], ":py:data:`~typing.Tuple`\\ [:py:class:`int`, :py:class:`int`, :py:class:`int`]" ),
242- (Tuple [str , ...], ":py:data:`~typing.Tuple`\\ [:py:class:`str`, :py:data:`...<Ellipsis>`]" ),
240+ (Tuple [str , bool ], ":py:data:`~typing.Tuple`\\ \\ [:py:class:`str`, :py:class:`bool`]" ),
241+ (Tuple [int , int , int ], ":py:data:`~typing.Tuple`\\ \\ [:py:class:`int`, :py:class:`int`, :py:class:`int`]" ),
242+ (Tuple [str , ...], ":py:data:`~typing.Tuple`\\ \\ [:py:class:`str`, :py:data:`...<Ellipsis>`]" ),
243243 (Union , ":py:data:`~typing.Union`" ),
244- (Union [str , bool ], ":py:data:`~typing.Union`\\ [:py:class:`str`, :py:class:`bool`]" ),
245- (Union [str , bool , None ], ":py:data:`~typing.Union`\\ [:py:class:`str`, :py:class:`bool`, :py:obj:`None`]" ),
246- pytest .param (Union [str , Any ], ":py:data:`~typing.Union`\\ [:py:class:`str`, :py:data:`~typing.Any`]" ),
247- (Optional [str ], ":py:data:`~typing.Optional`\\ [:py:class:`str`]" ),
248- (Union [str , None ], ":py:data:`~typing.Optional`\\ [:py:class:`str`]" ),
244+ (Union [str , bool ], ":py:data:`~typing.Union`\\ \\ [:py:class:`str`, :py:class:`bool`]" ),
245+ (Union [str , bool , None ], ":py:data:`~typing.Union`\\ \\ [:py:class:`str`, :py:class:`bool`, :py:obj:`None`]" ),
246+ pytest .param (Union [str , Any ], ":py:data:`~typing.Union`\\ \\ [:py:class:`str`, :py:data:`~typing.Any`]" ),
247+ (Optional [str ], ":py:data:`~typing.Optional`\\ \\ [:py:class:`str`]" ),
248+ (Union [str , None ], ":py:data:`~typing.Optional`\\ \\ [:py:class:`str`]" ),
249249 (
250250 Optional [Union [str , bool ]],
251- ":py:data:`~typing.Union`\\ [:py:class:`str`, :py:class:`bool`, :py:obj:`None`]" ,
251+ ":py:data:`~typing.Union`\\ \\ [:py:class:`str`, :py:class:`bool`, :py:obj:`None`]" ,
252252 ),
253253 (Callable , ":py:data:`~typing.Callable`" ),
254- (Callable [..., int ], ":py:data:`~typing.Callable`\\ [:py:data:`...<Ellipsis>`, :py:class:`int`]" ),
255- (Callable [[int ], int ], ":py:data:`~typing.Callable`\\ [\\ [:py:class:`int`], :py:class:`int`]" ),
254+ (Callable [..., int ], ":py:data:`~typing.Callable`\\ \\ [:py:data:`...<Ellipsis>`, :py:class:`int`]" ),
255+ (Callable [[int ], int ], ":py:data:`~typing.Callable`\\ \\ [\\ [:py:class:`int`], :py:class:`int`]" ),
256256 (
257257 Callable [[int , str ], bool ],
258- ":py:data:`~typing.Callable`\\ [\\ [:py:class:`int`, :py:class:`str`], :py:class:`bool`]" ,
258+ ":py:data:`~typing.Callable`\\ \\ [\\ [:py:class:`int`, :py:class:`str`], :py:class:`bool`]" ,
259259 ),
260260 (
261261 Callable [[int , str ], None ],
262- ":py:data:`~typing.Callable`\\ [\\ [:py:class:`int`, :py:class:`str`], :py:obj:`None`]" ,
262+ ":py:data:`~typing.Callable`\\ \\ [\\ [:py:class:`int`, :py:class:`str`], :py:obj:`None`]" ,
263263 ),
264264 (
265265 Callable [[T ], T ],
266- ":py:data:`~typing.Callable`\\ [\\ [:py:class:`~typing.TypeVar`\\ (``T``)],"
266+ ":py:data:`~typing.Callable`\\ \\ [\\ [:py:class:`~typing.TypeVar`\\ (``T``)],"
267267 " :py:class:`~typing.TypeVar`\\ (``T``)]" ,
268268 ),
269269 (
270270 AbcCallable [[int , str ], bool ], # type: ignore[valid-type,misc,type-arg]
271- ":py:class:`~collections.abc.Callable`\\ [\\ [:py:class:`int`, :py:class:`str`], :py:class:`bool`]" ,
271+ ":py:class:`~collections.abc.Callable`\\ \\ [\\ [:py:class:`int`, :py:class:`str`], :py:class:`bool`]" ,
272272 ),
273273 (Pattern , ":py:class:`~typing.Pattern`" ),
274- (Pattern [str ], ":py:class:`~typing.Pattern`\\ [:py:class:`str`]" ),
274+ (Pattern [str ], ":py:class:`~typing.Pattern`\\ \\ [:py:class:`str`]" ),
275275 (IO , ":py:class:`~typing.IO`" ),
276- (IO [str ], ":py:class:`~typing.IO`\\ [:py:class:`str`]" ),
276+ (IO [str ], ":py:class:`~typing.IO`\\ \\ [:py:class:`str`]" ),
277277 (Metaclass , ":py:class:`~%s.Metaclass`" % __name__ ),
278278 (A , ":py:class:`~%s.A`" % __name__ ),
279279 (B , ":py:class:`~%s.B`" % __name__ ),
280- (B [int ], ":py:class:`~%s.B`\\ [:py:class:`int`]" % __name__ ),
280+ (B [int ], ":py:class:`~%s.B`\\ \\ [:py:class:`int`]" % __name__ ),
281281 (C , ":py:class:`~%s.C`" % __name__ ),
282282 (D , ":py:class:`~%s.D`" % __name__ ),
283283 (E , ":py:class:`~%s.E`" % __name__ ),
284- (E [int ], ":py:class:`~%s.E`\\ [:py:class:`int`]" % __name__ ),
284+ (E [int ], ":py:class:`~%s.E`\\ \\ [:py:class:`int`]" % __name__ ),
285285 (W , f":py:{ 'class' if PY310_PLUS else 'func' } :`~typing.NewType`\\ (``W``, :py:class:`str`)" ),
286286 (T , ":py:class:`~typing.TypeVar`\\ (``T``)" ),
287287 (U_co , ":py:class:`~typing.TypeVar`\\ (``U_co``, covariant=True)" ),
@@ -306,17 +306,17 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
306306 # Zero-length tuple remains
307307 (Tuple [()], ":py:data:`~typing.Tuple`" ),
308308 # Internal single tuple with simple types is flattened in the output
309- (Tuple [(int ,)], ":py:data:`~typing.Tuple`\\ [:py:class:`int`]" ),
310- (Tuple [(int , int )], ":py:data:`~typing.Tuple`\\ [:py:class:`int`, :py:class:`int`]" ),
309+ (Tuple [(int ,)], ":py:data:`~typing.Tuple`\\ \\ [:py:class:`int`]" ),
310+ (Tuple [(int , int )], ":py:data:`~typing.Tuple`\\ \\ [:py:class:`int`, :py:class:`int`]" ),
311311 # Ellipsis in single tuple also gets flattened
312- (Tuple [(int , ...)], ":py:data:`~typing.Tuple`\\ [:py:class:`int`, :py:data:`...<Ellipsis>`]" ),
312+ (Tuple [(int , ...)], ":py:data:`~typing.Tuple`\\ \\ [:py:class:`int`, :py:data:`...<Ellipsis>`]" ),
313313 (
314314 RecList ,
315- ":py:data:`~typing.Union`\\ [:py:class:`int`, :py:class:`~typing.List`\\ [RecList]]" ,
315+ ":py:data:`~typing.Union`\\ \\ [:py:class:`int`, :py:class:`~typing.List`\\ \\ [RecList]]" ,
316316 ),
317317 (
318318 MutualRecA ,
319- ":py:data:`~typing.Union`\\ [:py:class:`bool`, :py:class:`~typing.List`\\ [MutualRecB]]" ,
319+ ":py:data:`~typing.Union`\\ \\ [:py:class:`bool`, :py:class:`~typing.List`\\ \\ [MutualRecB]]" ,
320320 ),
321321]
322322
@@ -327,39 +327,39 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
327327 (
328328 nptyping .NDArray [nptyping .Shape ["*" ], nptyping .Float ],
329329 (
330- ":py:class:`~nptyping.ndarray.NDArray`\\ [:py:class:`~nptyping.base_meta_classes.Shape`\\ [*], "
330+ ":py:class:`~nptyping.ndarray.NDArray`\\ \\ [:py:class:`~nptyping.base_meta_classes.Shape`\\ \\ [*], "
331331 ":py:class:`~numpy.float64`]"
332332 ),
333333 ),
334334 (
335335 nptyping .NDArray [nptyping .Shape ["64" ], nptyping .Float ],
336336 (
337- ":py:class:`~nptyping.ndarray.NDArray`\\ [:py:class:`~nptyping.base_meta_classes.Shape`\\ [64],"
337+ ":py:class:`~nptyping.ndarray.NDArray`\\ \\ [:py:class:`~nptyping.base_meta_classes.Shape`\\ \\ [64],"
338338 " :py:class:`~numpy.float64`]"
339339 ),
340340 ),
341341 (
342342 nptyping .NDArray [nptyping .Shape ["*, *" ], nptyping .Float ],
343343 (
344- ":py:class:`~nptyping.ndarray.NDArray`\\ [:py:class:`~nptyping.base_meta_classes.Shape`\\ [*, "
344+ ":py:class:`~nptyping.ndarray.NDArray`\\ \\ [:py:class:`~nptyping.base_meta_classes.Shape`\\ \\ [*, "
345345 "*], :py:class:`~numpy.float64`]"
346346 ),
347347 ),
348348 (
349349 nptyping .NDArray [nptyping .Shape ["*, ..." ], nptyping .Float ],
350- ":py:class:`~nptyping.ndarray.NDArray`\\ [:py:data:`~typing.Any`, :py:class:`~numpy.float64`]" ,
350+ ":py:class:`~nptyping.ndarray.NDArray`\\ \\ [:py:data:`~typing.Any`, :py:class:`~numpy.float64`]" ,
351351 ),
352352 (
353353 nptyping .NDArray [nptyping .Shape ["*, 3" ], nptyping .Float ],
354354 (
355- ":py:class:`~nptyping.ndarray.NDArray`\\ [:py:class:`~nptyping.base_meta_classes.Shape`\\ [*, 3"
355+ ":py:class:`~nptyping.ndarray.NDArray`\\ \\ [:py:class:`~nptyping.base_meta_classes.Shape`\\ \\ [*, 3"
356356 "], :py:class:`~numpy.float64`]"
357357 ),
358358 ),
359359 (
360360 nptyping .NDArray [nptyping .Shape ["3, ..." ], nptyping .Float ],
361361 (
362- ":py:class:`~nptyping.ndarray.NDArray`\\ [:py:class:`~nptyping.base_meta_classes.Shape`\\ [3, "
362+ ":py:class:`~nptyping.ndarray.NDArray`\\ \\ [:py:class:`~nptyping.base_meta_classes.Shape`\\ \\ [3, "
363363 "...], :py:class:`~numpy.float64`]"
364364 ),
365365 ),
@@ -379,7 +379,7 @@ def test_format_annotation(inv: Inventory, annotation: Any, expected_result: str
379379 # subsequent tests
380380 expected_result_not_simplified = expected_result .replace (", ``None``" , "" )
381381 # encapsulate Union in typing.Optional
382- expected_result_not_simplified = ":py:data:`~typing.Optional`\\ [" + expected_result_not_simplified
382+ expected_result_not_simplified = ":py:data:`~typing.Optional`\\ \\ [" + expected_result_not_simplified
383383 expected_result_not_simplified += "]"
384384 conf = create_autospec (Config , simplify_optional_unions = False , _annotation_globals = globals ())
385385 assert format_annotation (annotation , conf ) == expected_result_not_simplified
@@ -421,11 +421,11 @@ def test_format_annotation(inv: Inventory, annotation: Any, expected_result: str
421421@pytest .mark .parametrize (
422422 ("annotation" , "params" , "expected_result" ),
423423 [
424- ("ClassVar" , int , ":py:data:`~typing.ClassVar`\\ [:py:class:`int`]" ),
424+ ("ClassVar" , int , ":py:data:`~typing.ClassVar`\\ \\ [:py:class:`int`]" ),
425425 ("NoReturn" , None , ":py:data:`~typing.NoReturn`" ),
426- ("Literal" , ("a" , 1 ), ":py:data:`~typing.Literal`\\ [``'a'``, ``1``]" ),
426+ ("Literal" , ("a" , 1 ), ":py:data:`~typing.Literal`\\ \\ [``'a'``, ``1``]" ),
427427 ("Type" , None , ":py:class:`~typing.Type`" ),
428- ("Type" , (A ,), f":py:class:`~typing.Type`\\ [:py:class:`~{ __name__ } .A`]" ),
428+ ("Type" , (A ,), f":py:class:`~typing.Type`\\ \\ [:py:class:`~{ __name__ } .A`]" ),
429429 ],
430430)
431431def test_format_annotation_both_libs (library : ModuleType , annotation : str , params : Any , expected_result : str ) -> None :
@@ -524,16 +524,11 @@ class dummy_module.DataClass(x)
524524
525525def maybe_fix_py310 (expected_contents : str ) -> str :
526526 if not PY310_PLUS :
527- return expected_contents
527+ return expected_contents .replace ('"' , "" )
528+
528529 for old , new in [
529- ("*bool** | **None*" , '"Optional"["bool"]' ),
530- ("*int** | **str** | **float*" , '"int" | "str" | "float"' ),
531- ("*str** | **None*" , '"Optional"["str"]' ),
532- ("(*bool*)" , '("bool")' ),
533- ("(*int*" , '("int"' ),
534- (" str" , ' "str"' ),
535- ('"Optional"["str"]' , '"Optional"["str"]' ),
536- ('"Optional"["Callable"[["int", "bytes"], "int"]]' , '"Optional"["Callable"[["int", "bytes"], "int"]]' ),
530+ ("bool | None" , '"Optional"["bool"]' ),
531+ ("str | None" , '"Optional"["str"]' ),
537532 ]:
538533 expected_contents = expected_contents .replace (old , new )
539534 return expected_contents
@@ -559,14 +554,14 @@ def test_sphinx_output_future_annotations(app: SphinxTestApp, status: StringIO)
559554 Method docstring.
560555
561556 Parameters:
562- * **x** (* bool** | ** None* ) -- foo
557+ * **x** (bool | None) -- foo
563558
564- * **y** (* int** | ** str** | ** float* ) -- bar
559+ * **y** (" int" | " str" | " float" ) -- bar
565560
566- * **z** (* str** | ** None* ) -- baz
561+ * **z** (str | None) -- baz
567562
568563 Return type:
569- str
564+ " str"
570565 """
571566 expected_contents = maybe_fix_py310 (dedent (expected_contents ))
572567 assert contents == expected_contents
@@ -625,7 +620,7 @@ def test_sphinx_output_defaults(
625620 ("formatter_config_val" , "expected" ),
626621 [
627622 (None , ['("bool") -- foo' , '("int") -- bar' , '"str"' ]),
628- (lambda ann , conf : "Test" , ["(* Test* ) -- foo" , "(* Test* ) -- bar" , "Test" ]), # noqa: ARG005
623+ (lambda ann , conf : "Test" , ["(Test) -- foo" , "(Test) -- bar" , "Test" ]), # noqa: ARG005
629624 ("some string" , Exception ("needs to be callable or `None`" )),
630625 ],
631626)
0 commit comments