mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #4423 from tk0miya/3570_drop_typing_from_typehints
Fix #3570: autodoc: Do not display typing. module for type hints
This commit is contained in:
commit
822a04de9c
1
CHANGES
1
CHANGES
@ -74,6 +74,7 @@ Features added
|
||||
extension to limit the scope of inheritance graphs.
|
||||
* #4183: doctest: ``:pyversion:`` option also follows PEP-440 specification
|
||||
* #4235: html: Add :confval:`manpages_url` to make manpage roles to hyperlinks
|
||||
* #3570: autodoc: Do not display 'typing.' module for type hints
|
||||
|
||||
Features removed
|
||||
----------------
|
||||
|
@ -404,10 +404,18 @@ class Signature(object):
|
||||
if annotation == Ellipsis:
|
||||
return '...'
|
||||
if not isinstance(annotation, type):
|
||||
return repr(annotation)
|
||||
qualified_name = repr(annotation)
|
||||
if qualified_name.startswith('typing.'): # for typing.Union
|
||||
return qualified_name.split('.', 1)[1]
|
||||
else:
|
||||
return qualified_name
|
||||
|
||||
qualified_name = (annotation.__module__ + '.' + annotation.__qualname__ # type: ignore
|
||||
if annotation else repr(annotation))
|
||||
if not annotation:
|
||||
qualified_name = repr(annotation)
|
||||
elif annotation.__module__ == 'typing':
|
||||
qualified_name = annotation.__qualname__ # type: ignore
|
||||
else:
|
||||
qualified_name = (annotation.__module__ + '.' + annotation.__qualname__) # type: ignore # NOQA
|
||||
|
||||
if annotation.__module__ == 'builtins':
|
||||
return annotation.__qualname__ # type: ignore
|
||||
|
@ -211,15 +211,15 @@ def test_Signature_annotations():
|
||||
|
||||
# Generic types with concrete parameters
|
||||
sig = inspect.Signature(f1).format_args()
|
||||
assert sig == '(x: typing.List[int]) -> typing.List[int]'
|
||||
assert sig == '(x: List[int]) -> List[int]'
|
||||
|
||||
# TypeVars and generic types with TypeVars
|
||||
sig = inspect.Signature(f2).format_args()
|
||||
assert sig == '(x: typing.List[T], y: typing.List[T_co], z: T) -> typing.List[T_contra]'
|
||||
assert sig == '(x: List[T], y: List[T_co], z: T) -> List[T_contra]'
|
||||
|
||||
# Union types
|
||||
sig = inspect.Signature(f3).format_args()
|
||||
assert sig == '(x: typing.Union[str, numbers.Integral]) -> None'
|
||||
assert sig == '(x: Union[str, numbers.Integral]) -> None'
|
||||
|
||||
# Quoted annotations
|
||||
sig = inspect.Signature(f4).format_args()
|
||||
@ -239,14 +239,14 @@ def test_Signature_annotations():
|
||||
|
||||
# Callable types
|
||||
sig = inspect.Signature(f8).format_args()
|
||||
assert sig == '(x: typing.Callable[[int, str], int]) -> None'
|
||||
assert sig == '(x: Callable[[int, str], int]) -> None'
|
||||
|
||||
sig = inspect.Signature(f9).format_args()
|
||||
assert sig == '(x: typing.Callable) -> None'
|
||||
assert sig == '(x: Callable) -> None'
|
||||
|
||||
# Tuple types
|
||||
sig = inspect.Signature(f10).format_args()
|
||||
assert sig == '(x: typing.Tuple[int, str], y: typing.Tuple[int, ...]) -> None'
|
||||
assert sig == '(x: Tuple[int, str], y: Tuple[int, ...]) -> None'
|
||||
|
||||
# Instance annotations
|
||||
sig = inspect.Signature(f11).format_args()
|
||||
|
Loading…
Reference in New Issue
Block a user