Skip to content

Add option to document properties using autoproperty instead of autoattribute - #197

Merged
astrofrog merged 5 commits into
astropy:mainfrom
WilliamJamieson:autoproperty
Mar 21, 2025
Merged

astrofrog merged 5 commits into
astropy:mainfrom
WilliamJamieson:autoproperty

Conversation

@WilliamJamieson

Copy link
Copy Markdown
Contributor

Currently attributes and properties are treated the same by automodapi when it comes to generating documentation. This is problematic if one wants to do things like have the return type of a property type hint to be included in the documentation. The autoproperty directive can do this, where as the autoattribute cannot.

This PR adds the config option automodsumm_properties_are_attributes which when True(the default) treats all properties like they are attributes and when False treats them using the autoproperty directive.

@pllim pllim added this to the 0.19.0 milestone Jan 10, 2025
@WilliamJamieson

Copy link
Copy Markdown
Contributor Author

To see the difference, before these changes:
Before
vs after these changes with automodsumm_properties_are_attributes=False:
After

@pllim

pllim commented Jan 10, 2025

Copy link
Copy Markdown
Member

Might wanna wait for #196 to make sure this actually passes with sphinx-dev

@WilliamJamieson
WilliamJamieson marked this pull request as ready for review January 10, 2025 19:53
Comment on lines +629 to +647
public_properties, all_properties = \
get_members_class(obj, 'property',
include_base=include_base)
if properties_are_attributes:
ns['attributes'].extend(public_properties)
ns['all_attributes'].extend(all_properties)
else:
ns['properties'] = public_properties
ns['all_properties'] = all_properties

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the real change.

@bsipocz

bsipocz commented Jan 10, 2025

Copy link
Copy Markdown
Member

Want to revisit #134 after this, too and then we can cut a release?

@Cadair

Cadair commented Jan 10, 2025

Copy link
Copy Markdown
Member

I am pro making this new behavior the default. @WilliamJamieson said to me that automodapi predates autoproperty in sphinx. I see no good reason why we should use this everywhere.

@codecov

codecov Bot commented Jan 10, 2025 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 90.47619% with 2 lines in your changes missing coverage. Please review.

Project coverage is 90.05%. Comparing base (594fc12) to head (09aeffb).
Report is 50 commits behind head on main.

Files with missing lines Patch % Lines
...automodapi/tests/example_module/attribute_class.py 71.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #197      +/-   ##
==========================================
- Coverage   90.29%   90.05%   -0.25%     
==========================================
  Files          30       31       +1     
  Lines        1206     1227      +21     
==========================================
+ Hits         1089     1105      +16     
- Misses        117      122       +5     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pllim

pllim commented Jan 10, 2025

Copy link
Copy Markdown
Member

@WilliamJamieson , please rebase to pick up devdeps fixes. Thanks!

making this new behavior the default

Might be surprising for downstream packages. Are you sure?!

@Cadair

Cadair commented Jan 13, 2025

Copy link
Copy Markdown
Member

Might be surprising for downstream packages. Are you sure?!

Sure things change when you upgrade packages. I think this is a straight upgrade, with no real downside other than "different". If we want to we could make it throw a warning until someone explicitly sets the config flag?

@pllim

pllim commented Jan 13, 2025

Copy link
Copy Markdown
Member

Given @eteq originally wrote this and @astrofrog then patched it (9 years ago!), maybe they have opinions?

If not, maybe at least a draft PR to astropy with this branch to compare before merge?

@Cadair

Cadair commented Mar 20, 2025 •

Copy link
Copy Markdown
Member

I just ran into this again in a different project. Can we merge it 😆

@astrofrog astrofrog left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving as seems ok to me, but see small comment below. Also @WilliamJamieson can you confirm the astropy docs build fine with this PR?

# elif typ == 'attribute' and documenter.objtype == 'property':
# # In Sphinx 2.0 and above, properties have a separate
# # objtype, but we treat them the same here.
# items.append(name)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be removed?

@Cadair

Cadair commented Mar 20, 2025

Copy link
Copy Markdown
Member

A astropy doc build is running here: astropy/astropy#17919

@astrofrog

Copy link
Copy Markdown
Member

The astropy RTD build passed with the default option. I think we can merge this, and once a few packages are using this on an opt-in basis successfully we can consider toggling the default?

@astrofrog
astrofrog merged commit 54a3ac3 into astropy:main Mar 21, 2025
@pllim

pllim commented Mar 21, 2025

Copy link
Copy Markdown
Member

Someone will have to do new release. ;)

@bsipocz

bsipocz commented Mar 21, 2025

Copy link
Copy Markdown
Member

If no one does it, I can do one in the evening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants