Skip to content

Commit

Permalink
Resolve forward ref
Browse files Browse the repository at this point in the history
  • Loading branch information
daizutabi committed Jun 15, 2020
1 parent b7cc0f7 commit db5ff85
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 9 additions & 1 deletion mkapi/core/inherit.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_section(node: Node, name: str, mode: str) -> Section:
else:
return Section(name)
else:
if hasattr(node.object.signature, name):
if hasattr(node.object.signature, name.lower()):
return node.object.signature[name]
else:
return Section(name)
Expand Down Expand Up @@ -93,6 +93,14 @@ def inherit_base(node: Node, base: Node, name: str = "both"):
base_section = get_section(base, name, "Docstring")
node_section = get_section(node, name, "Docstring")
section = base_section.merge(node_section, force=True)
if name == "Parameters":
sig_section = get_section(node, name, "Signature")
items = []
for item in section.items:
if item.name in sig_section:
items.append(item)

section.items = items
if section:
node.docstring.set_section(section, replace=True)

Expand Down
8 changes: 4 additions & 4 deletions mkapi/core/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ def to_string(annotation, kind: str = "returns", obj=None) -> str:
if kind == "yields":
if hasattr(annotation, "__args__") and annotation.__args__:
if len(annotation.__args__) == 1:
return to_string(annotation.__args__[0])
return to_string(annotation.__args__[0], obj=obj)
else:
return to_string(annotation)
return to_string(annotation, obj=obj)
else:
return ""

Expand All @@ -160,15 +160,15 @@ def to_string(annotation, kind: str = "returns", obj=None) -> str:
if origin is Union:
return union(annotation)
if origin is tuple:
args = [to_string(x) for x in annotation.__args__]
args = [to_string(x, obj=obj) for x in annotation.__args__]
if args:
return "(" + ", ".join(args) + ")"
else:
return "tuple"
if origin is dict:
if type(annotation.__args__[0]) == TypeVar:
return "dict"
args = [to_string(x) for x in annotation.__args__]
args = [to_string(x, obj=obj) for x in annotation.__args__]
if args:
return "dict(" + ": ".join(args) + ")"
else:
Expand Down

0 comments on commit db5ff85

Please sign in to comment.