2727)
2828from unittest .mock import create_autospec , patch
2929
30+ import nptyping # type: ignore
3031import pytest
3132import typing_extensions
3233from sphinx .application import Sphinx
@@ -201,6 +202,55 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
201202 (E , ":py:class:`~%s.E`" % __name__ ),
202203 (E [int ], ":py:class:`~%s.E`\\ [:py:class:`int`]" % __name__ ),
203204 (W , f':py:{ "class" if PY310_PLUS else "func" } :' f"`~typing.NewType`\\ (``W``, :py:class:`str`)" ),
205+ # ## These test for correct internal tuple rendering, even if not all are valid Tuple types
206+ # Zero-length tuple remains
207+ (Tuple [()], ":py:data:`~typing.Tuple`\\ [()]" ),
208+ # Internal single tuple with simple types is flattened in the output
209+ (Tuple [(int ,)], ":py:data:`~typing.Tuple`\\ [:py:class:`int`]" ),
210+ (Tuple [(int , int )], ":py:data:`~typing.Tuple`\\ [:py:class:`int`, :py:class:`int`]" ),
211+ # Ellipsis in single tuple also gets flattened
212+ (Tuple [(int , ...)], ":py:data:`~typing.Tuple`\\ [:py:class:`int`, ...]" ),
213+ # Internal tuple with following additional type cannot be flattened (specific to nptyping?)
214+ # These cases will fail if nptyping restructures its internal module hierarchy
215+ (
216+ nptyping .NDArray [(Any ,), nptyping .Float ],
217+ (
218+ ":py:class:`~nptyping.types._ndarray.NDArray`\\ [(:py:data:`~typing.Any`, ), "
219+ ":py:class:`~nptyping.types._number.Float`]"
220+ ),
221+ ),
222+ (
223+ nptyping .NDArray [(Any ,), nptyping .Float [64 ]],
224+ (
225+ ":py:class:`~nptyping.types._ndarray.NDArray`\\ [(:py:data:`~typing.Any`, ), "
226+ ":py:class:`~nptyping.types._number.Float`\\ [64]]"
227+ ),
228+ ),
229+ (
230+ nptyping .NDArray [(Any , Any ), nptyping .Float ],
231+ (
232+ ":py:class:`~nptyping.types._ndarray.NDArray`\\ [(:py:data:`~typing.Any`, "
233+ ":py:data:`~typing.Any`), :py:class:`~nptyping.types._number.Float`]"
234+ ),
235+ ),
236+ (
237+ nptyping .NDArray [(Any , ...), nptyping .Float ],
238+ (
239+ ":py:class:`~nptyping.types._ndarray.NDArray`\\ [(:py:data:`~typing.Any`, ...), "
240+ ":py:class:`~nptyping.types._number.Float`]"
241+ ),
242+ ),
243+ (
244+ nptyping .NDArray [(Any , 3 ), nptyping .Float ],
245+ (
246+ ":py:class:`~nptyping.types._ndarray.NDArray`\\ [(:py:data:`~typing.Any`, 3), "
247+ ":py:class:`~nptyping.types._number.Float`]"
248+ ),
249+ ),
250+ (
251+ nptyping .NDArray [(3 , ...), nptyping .Float ],
252+ (":py:class:`~nptyping.types._ndarray.NDArray`\\ [(3, ...), :py:class:`~nptyping.types._number.Float`]" ),
253+ ),
204254 ],
205255)
206256def test_format_annotation (inv : Inventory , annotation : Any , expected_result : str ) -> None :
@@ -226,8 +276,9 @@ def test_format_annotation(inv: Inventory, annotation: Any, expected_result: str
226276 assert format_annotation (annotation , conf ) == expected_result_not_simplified
227277
228278 # Test with the "fully_qualified" flag turned on
229- if "typing" in expected_result or __name__ in expected_result :
279+ if "typing" in expected_result or "nptyping" in expected_result or __name__ in expected_result :
230280 expected_result = expected_result .replace ("~typing" , "typing" )
281+ expected_result = expected_result .replace ("~nptyping" , "nptyping" )
231282 expected_result = expected_result .replace ("~" + __name__ , __name__ )
232283 conf = create_autospec (Config , typehints_fully_qualified = True )
233284 assert format_annotation (annotation , conf ) == expected_result
0 commit comments