change format_args to prefer annotations from typing.get_type_hints

The current code looks for the pattern::

    class Node:
        def parent(self) -> 'Node': pass

This change allows more complex forward references::

    class Node:
        def children(self) -> Set['Node']: pass
This commit is contained in:
Terence Honles
2018-08-09 12:31:16 -07:00
committed by Terence D. Honles
parent 8a23ad1f44
commit 742c89f99b

View File

@@ -433,8 +433,7 @@ class Signature(object):
if PY2 or self.return_annotation is inspect.Parameter.empty:
return '(%s)' % ', '.join(args)
else:
if isinstance(self.return_annotation, string_types) and \
'return' in self.annotations:
if 'return' in self.annotations:
annotation = self.format_annotation(self.annotations['return'])
else:
annotation = self.format_annotation(self.return_annotation)