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

Add type information to create_ and add_ method documentation #620

Merged
merged 6 commits into from
Oct 31, 2024

Conversation

greschd
Copy link
Member

@greschd greschd commented Oct 16, 2024

Provide type information for the parameters of the create_* and add_* methods in the documentation.

The __signature__ of the methods is constructed from from the wrapped class's signature, only adding a 'self' parameter.

For the add_* methods, the Parameters block (and everything below it) is now also obtained from the class if present.

The 'sphinx-autodoc-typehints' extension previously used does not support showing this dynamically created signature, so it was replaced by using the built-in type hint support of 'sphinx.ext.autodoc'. The only drawback is that defaults are now shown only in the signature, and no longer in the description.

Since 'sphinx.ext.autodoc' however overwrites the class parameter type hints with the class attribute type hints, the helper function used to generate the signature is monkeypatched.

Closes #612

Copy link

codecov bot commented Oct 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.94%. Comparing base (17fbf43) to head (df424ff).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #620      +/-   ##
==========================================
+ Coverage   93.92%   93.94%   +0.02%     
==========================================
  Files          95       95              
  Lines        5165     5184      +19     
==========================================
+ Hits         4851     4870      +19     
  Misses        314      314              
Flag Coverage Δ
python-3.10 93.82% <100.00%> (+0.02%) ⬆️
python-3.11 93.75% <100.00%> (+0.02%) ⬆️
python-3.12 93.86% <100.00%> (+0.02%) ⬆️
server-2024R2 91.37% <100.00%> (+0.03%) ⬆️
server-2025R1 93.75% <100.00%> (+0.02%) ⬆️
server-latest 93.82% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@greschd
Copy link
Member Author

greschd commented Oct 16, 2024

Screenshots:

new

image
image
image

old

image
image
image

@greschd greschd marked this pull request as draft October 16, 2024 21:38
@greschd
Copy link
Member Author

greschd commented Oct 16, 2024

I don't know why name is now suddenly shown as ReadWriteProperty[str, str] in the main class documentation; that needs fixing.
Maybe we'll have to move the class docstrings to the __init__; I think Sphinx is getting confused between attributes and parameters.

EDIT: This is a Sphinx bug, see sphinx-doc/sphinx#11207. Probably worth investigating if this can be easily fixed upstream.

@greschd greschd force-pushed the feat/show_types_in_create_method_doc branch from 5d735e8 to 20a3e7d Compare October 22, 2024 21:37
@greschd
Copy link
Member Author

greschd commented Oct 22, 2024

EDIT: This is a Sphinx bug, see sphinx-doc/sphinx#11207. Probably worth investigating if this can be easily fixed upstream.

For now, I have added a monkeypatch that simply uses the builtin inspect.signature.

@greschd greschd marked this pull request as ready for review October 22, 2024 21:38
@greschd greschd marked this pull request as draft October 23, 2024 06:33
@greschd
Copy link
Member Author

greschd commented Oct 23, 2024

Marked as draft because there is an issue with intersphinx that I'll need to investigate - see the failing doc build.

Provide type information for the parameters of the ``create_*``
and ``add_*`` methods in the documentation.

The __signature__ of the methods is constructed from from the wrapped
class's signature, only adding a 'self' parameter.

The 'sphinx-autodoc-typehints' extension previously used does not
support showing this dynamically created signature, so it was replaced
by using the built-in type hint support of 'sphinx.ext.autodoc'.

Return types are provided in the signature, but Sphinx incorrectly
shows the generic type (e.g. CreatableTreeObject) instead of the
one present in __signature__. Since this is not useful, the return
type is hidden unless specifically documented.

Closes #612
@greschd greschd force-pushed the feat/show_types_in_create_method_doc branch from 5c43235 to 836e1fb Compare October 31, 2024 13:03
@greschd greschd marked this pull request as ready for review October 31, 2024 16:06
@greschd greschd enabled auto-merge (squash) October 31, 2024 16:08
@greschd greschd disabled auto-merge October 31, 2024 22:01
@greschd greschd enabled auto-merge (squash) October 31, 2024 22:09
@greschd greschd force-pushed the feat/show_types_in_create_method_doc branch from e3fdf7b to df424ff Compare October 31, 2024 22:20
@greschd greschd merged commit f98ec6b into main Oct 31, 2024
26 checks passed
@greschd greschd deleted the feat/show_types_in_create_method_doc branch October 31, 2024 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type information is not shown in create_ method documentation
2 participants