Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML: Break function signature elements into multiple spans #801

Open
lod opened this issue Jun 20, 2024 · 2 comments · May be fixed by #831
Open

HTML: Break function signature elements into multiple spans #801

lod opened this issue Jun 20, 2024 · 2 comments · May be fixed by #831

Comments

@lod
Copy link

lod commented Jun 20, 2024

The current HTML output doesn't work well for large complex functions. The function signature is mushed together onto a single long unreadable line.

Sphinx has the maximum_signature_line_length configuration option to do this. However a much simpler option would be to split the signature into multiple spans and allow themes to style long lines via CSS.

As an example Sphinx uses <em class="sig-param"> for each parameter. The details of the parameter are broken down further but that feels less useful.

As an example for def extract_final_subscript(annotation: [ast.Subscript](https://docs.python.org/3/library/ast.html#ast.Subscript)) -> ast.expr:

The current html structure for the arguments is:
<span class="function-signature">(annotation:<code><a ...>ast.Subscript</a></code>) -> <code>ast.expr</code></span>

An alternative would be:
<span class="function-signature">(<span class="function-params"><span class="function-param">annotation:<code><a ...>ast.Subscript</a></code></span></span>) -> <code>ast.expr</code></span>

Example CSS:

.function-params:has(> :nth-child(4)) : /* 5 or more arguments, use vertical styling */
.function-params:not:has(> :nth-child(4)) : /* small function definition, single line styling */
@lod
Copy link
Author

lod commented Jun 20, 2024

This may related to #41.

@tristanlatr
Copy link
Contributor

tristanlatr commented Jun 20, 2024

Hello,

Thanks for the detailed feature request. This should not be hard. But regarding the css proposition, we might want to find a better heuristic than the number of arguments, like the total signature length instead. But it might also do the job…

Linked to #422.

tristanlatr added a commit that referenced this issue Oct 25, 2024
We mimic the Signature.__str__ method for the implementation but instead of returning a str we return a ParsedDocstring, which is far more convenient.

This change fixes #801:
- Parameters html are divided into .sig-param spans.
- When the function is long enought an extra CSS class .expand-signature is added to the parent function-signature.
- The first parameter 'cls' or 'self' of (class) methods is marked with the 'undocumented' CSS class, this way it's clearly not part of the API.
- Add some CSS  to expand the signature of long functions when they have the focus only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants