mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #9522 from Gobot1234/4.x
Recursively resolve PEP 585 builtins in restify
This commit is contained in:
commit
6ac326e019
@ -124,7 +124,13 @@ def restify(cls: Optional[Type]) -> str:
|
||||
else:
|
||||
return ' | '.join(restify(a) for a in cls.__args__)
|
||||
elif cls.__module__ in ('__builtin__', 'builtins'):
|
||||
return ':class:`%s`' % cls.__name__
|
||||
if hasattr(cls, '__args__'):
|
||||
return ':class:`%s`\\ [%s]' % (
|
||||
cls.__name__,
|
||||
', '.join(restify(arg) for arg in cls.__args__),
|
||||
)
|
||||
else:
|
||||
return ':class:`%s`' % cls.__name__
|
||||
else:
|
||||
if sys.version_info >= (3, 7): # py37+
|
||||
return _restify_py37(cls)
|
||||
|
@ -140,6 +140,14 @@ def test_restify_type_Literal():
|
||||
assert restify(Literal[1, "2", "\r"]) == ":obj:`~typing.Literal`\\ [1, '2', '\\r']"
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info < (3, 9), reason='python 3.9+ is required.')
|
||||
def test_restify_pep_585():
|
||||
assert restify(list[str]) == ":class:`list`\\ [:class:`str`]" # type: ignore
|
||||
assert restify(dict[str, str]) == ":class:`dict`\\ [:class:`str`, :class:`str`]" # type: ignore
|
||||
assert restify(dict[str, tuple[int, ...]]) == \
|
||||
":class:`dict`\\ [:class:`str`, :class:`tuple`\\ [:class:`int`, ...]]" # type: ignore
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info < (3, 10), reason='python 3.10+ is required.')
|
||||
def test_restify_type_union_operator():
|
||||
assert restify(int | None) == ":class:`int` | :obj:`None`" # type: ignore
|
||||
|
Loading…
Reference in New Issue
Block a user