Skip to content

Commit

Permalink
Add Signature to rendered ascii (#332)
Browse files Browse the repository at this point in the history
Initial proposal for rendering signature in ascii output. Colors can be
debated 😄

This is how it looks like to me:


![Screenshot_20231117_165014](https://github.com/jupyter/papyri/assets/3949932/2ff0b583-c74a-49a0-8006-739e8b3e393b)

And this is how the html rendering already looked like:


![Screenshot_20231117_165434](https://github.com/jupyter/papyri/assets/3949932/2a540a8a-3b22-4694-afd0-49f44b731b70)

Note that default values are not yet rendered, and there may be other
issues to follow up on.

Closes #330
  • Loading branch information
Carreau authored Nov 20, 2023
2 parents 37b8689 + 2ccca3a commit 113c8a1
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 113c8a1

Please sign in to comment.