[ty] Render Markdown for reStructuredText fields in docstrings on hover#25903
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
60736c0 to
bb07029
Compare
e28356b to
1e77ca4
Compare
bb07029 to
1044385
Compare
1e77ca4 to
858f130
Compare
33fb99e to
7b06b44
Compare
7b06b44 to
a5915aa
Compare
a5915aa to
22d9d82
Compare
ec47f0a to
7a3bc00
Compare
696dcc3 to
130e848
Compare
9591e65 to
350dbe0
Compare
3da034f to
2a18e16
Compare
350dbe0 to
e8f24f4
Compare
1e31619 to
757bb8b
Compare
e8f24f4 to
80e5e76
Compare
757bb8b to
8f6f03f
Compare
b83e328 to
05760d0
Compare
741163a to
894a1eb
Compare
edcdbfc to
89301b9
Compare
6ed67b7 to
f8a5bf4
Compare
89301b9 to
d94888e
Compare
f8a5bf4 to
00c292a
Compare
d94888e to
b6afe06
Compare
00c292a to
a6102eb
Compare
MichaReiser
left a comment
There was a problem hiding this comment.
Thank you, this is great!
Here are two codex finding. You'll know better whether these need to be addressed or not.
[P3] Keep Sphinx parameter aliases in the same section.
key and keyword are parsed separately and rendered under “Keyword Arguments.” Sphinx defines them as aliases of param/argument, not as evidence that a parameter is keyword-only. This can misleadingly split one parameter list into two headings. They should remain Parameters unless semantic signature information drives the distinction. Sphinx reference[P3] Parse field names case-insensitively.
The literal match in parse_supported rejects valid capitalization such as :Param value: or :Returns:. If mixed with lowercase fields, the unknown-field fallback keeps the entire list raw. reST field names are case-insensitive when transformed, so dispatch should normalize or compare ASCII-insensitively. reStructuredText specification
|
I haven't reviewed the code, but the output in the PR summary looks awesome! Just one nit on that front:
To me it would look better here if we had a line break after "Source That's the style I'm most familiar with in Python documentation elsewhere -- e.g. numpy, pandas. Or other documentation themes often use a table, but still generally keep the description of the parameter more clearly separated from its name and type annotation -- e.g. textual, my own typeshed-stats project |
Thank you for sharing: I addressed both. The first in particular was interesting, and made be reconsider previous behaviour (we now isolate the "Keyword Arguments" section to Google-formatted docstrings, which is where they belong).
Yes, thank you for the feedback! I've implemented just that (pictured below). I would have loved to also indent the parameter docs (as in the numpy and pandas examples you shared, and also as Pylance does), but I couldn't figure out how to do so without an editor-specific hack1. I think the result is imperfect, but probably better than what I had before. We should adjust this as necessary in response to user feedback.
Footnotes
|
Associate Markdown rendering with docstring fragments Test reST parameter extraction boundaries Share reST field-list boundary filtering
|
This was one of the main things I missed coming from Pyright/Pylance, can't wait to try it, thanks! |


Summary
This introduces Markdown rendering for reStructuredText (reST) field lists in docstrings. Here's what it looks like in two different editors:
The implementation includes the following judgement calls that I think are acceptable, but that we may want to revisit based on user feedback:
I expect that it will be marginally easier to review this diff commit-by-commit rather than wholesale.
Closes astral-sh/ty#3454.
Test Plan
Please see included tests.