Skip to content

Commit

Permalink
Add Signature to rendered ascii
Browse files Browse the repository at this point in the history
  • Loading branch information
melissawm committed Nov 17, 2023
1 parent dcc330c commit 2ccca3a
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions papyri/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,19 @@ def render_Param(self, param):
]
)

def render_SignatureNode(self, sig):
if "Empty" in str(sig.return_annotation):
annotation = "None"
else:
annotation = ("signature", sig.return_annotation)
return [
("signature", "("),
[("param", f"{p.name}, ") for p in sig.parameters],
("signature", ")"),
("signature", " -> "),
annotation,
]


def main(qualname: str):
if not isinstance(qualname, str):
Expand All @@ -560,8 +573,21 @@ def gen_content(blob, frame):
R = Renderer(frame, walk, gen_content, stack)
doc = []
doc.append(blank)
if blob.signature.value:
doc.append(Text([("signature", blob.signature.value)]))
if blob.signature:
doc.append(Text(("section", "Signature")))
doc.append(blank)
doc.append(
Text(
[
("signature", blob.signature.kind),
(" "),
("bb", qualname),
(" "),
R.render(blob.signature),
]
),
)
doc.append(blank)

for k, v in blob.content.items():
if not v.empty():
Expand Down Expand Up @@ -672,7 +698,7 @@ def callback():
("link_selected", "black,bold", "white"),
("link-broken", "dark red,strikethrough", "", "bold"),
("type", "dark cyan", "", "bold"),
("signature", "dark cyan,bold", "", "bold"),
("signature", "yellow,bold", "", "bold"),
("param", "dark blue", "", "bold"),
("section", "dark magenta,bold", "", "bold"),
("unknown", "white", "dark red", "bold"),
Expand Down

0 comments on commit 2ccca3a

Please sign in to comment.