Merge pull request #5333 from tk0miya/5322_Any_causes_crashed

Fix #5322: autodoc: ``Any`` typehint causes formatting error
This commit is contained in:
Takeshi KOMIYA 2018-08-22 22:38:21 +09:00 committed by GitHub
commit a029a8f81d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 3 deletions

View File

@ -18,6 +18,7 @@ Bugs fixed
* #5320: intersphinx: crashed if invalid url given
* #5326: manpage: crashed when invalid docname is specified as ``man_pages``
* #5322: autodoc: ``Any`` typehint causes formatting error
Testing
--------

View File

@ -531,8 +531,10 @@ class Signature(object):
qualname = annotation.__qualname__
elif getattr(annotation, '__forward_arg__', None):
qualname = annotation.__forward_arg__
else:
elif getattr(annotation, '__origin__', None):
qualname = self.format_annotation(annotation.__origin__) # ex. Union
else:
qualname = repr(annotation).replace('typing.', '')
elif hasattr(annotation, '__qualname__'):
qualname = '%s.%s' % (module, annotation.__qualname__)
else:

View File

@ -232,7 +232,7 @@ def test_Signature_partialmethod():
reason='type annotation test is available on py34 or above')
def test_Signature_annotations():
from typing_test_data import (
f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, Node)
f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, Node)
# Class annotations
sig = inspect.Signature(f0).format_args()
@ -293,6 +293,10 @@ def test_Signature_annotations():
sig = inspect.Signature(f13).format_args()
assert sig == '() -> Optional[str]'
# Any
sig = inspect.Signature(f14).format_args()
assert sig == '() -> Any'
# type hints by string
sig = inspect.Signature(Node.children).format_args()
assert sig == '(self) -> List[typing_test_data.Node]'

View File

@ -1,5 +1,5 @@
from numbers import Integral
from typing import List, TypeVar, Union, Callable, Tuple, Optional
from typing import Any, List, TypeVar, Union, Callable, Tuple, Optional
def f0(x: int, y: Integral) -> None:
@ -72,6 +72,10 @@ def f13() -> Optional[str]:
pass
def f14() -> Any:
pass
class Node:
def __init__(self, parent: Optional['Node']) -> None:
pass