Merge pull request #5303 from tk0miya/5291_autodoc_crashed_by_ForwardRef

Fix #5291: autodoc crashed by ForwardRef types
This commit is contained in:
Takeshi KOMIYA 2018-08-17 00:07:14 +09:00 committed by GitHub
commit 01f4d3ba23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 0 deletions

View File

@ -28,6 +28,8 @@ Bugs fixed
font with XeLaTeX/LuaLateX (refs: #5251) font with XeLaTeX/LuaLateX (refs: #5251)
* #5280: autodoc: Fix wrong type annotations for complex typing * #5280: autodoc: Fix wrong type annotations for complex typing
* autodoc: Optional types are wrongly rendered * autodoc: Optional types are wrongly rendered
* #5291: autodoc crashed by ForwardRef types
Testing Testing
-------- --------

View File

@ -477,6 +477,8 @@ class Signature(object):
qualname = annotation._name qualname = annotation._name
elif getattr(annotation, '__qualname__', None): elif getattr(annotation, '__qualname__', None):
qualname = annotation.__qualname__ qualname = annotation.__qualname__
elif getattr(annotation, '__forward_arg__', None):
qualname = annotation.__forward_arg__
else: else:
qualname = self.format_annotation(annotation.__origin__) # ex. Union qualname = self.format_annotation(annotation.__origin__) # ex. Union
elif hasattr(annotation, '__qualname__'): elif hasattr(annotation, '__qualname__'):
@ -510,6 +512,8 @@ class Signature(object):
qualname = annotation._name qualname = annotation._name
elif getattr(annotation, '__qualname__', None): elif getattr(annotation, '__qualname__', None):
qualname = annotation.__qualname__ qualname = annotation.__qualname__
elif getattr(annotation, '__forward_arg__', None):
qualname = annotation.__forward_arg__
else: else:
qualname = self.format_annotation(annotation.__origin__) # ex. Union qualname = self.format_annotation(annotation.__origin__) # ex. Union
elif hasattr(annotation, '__qualname__'): elif hasattr(annotation, '__qualname__'):

View File

@ -297,6 +297,9 @@ def test_Signature_annotations():
sig = inspect.Signature(Node.children).format_args() sig = inspect.Signature(Node.children).format_args()
assert sig == '(self) -> List[typing_test_data.Node]' assert sig == '(self) -> List[typing_test_data.Node]'
sig = inspect.Signature(Node.__init__).format_args()
assert sig == '(self, parent: Optional[Node]) -> None'
def test_safe_getattr_with_default(): def test_safe_getattr_with_default():
class Foo(object): class Foo(object):

View File

@ -73,5 +73,8 @@ def f13() -> Optional[str]:
class Node: class Node:
def __init__(self, parent: Optional['Node']) -> None:
pass
def children(self) -> List['Node']: def children(self) -> List['Node']:
pass pass