Add a Sphinx extension to document cached properties of slots classes#1519
Add a Sphinx extension to document cached properties of slots classes#1519clayote wants to merge 32 commits intopython-attrs:mainfrom
Conversation
6fce05b to
365bc5c
Compare
|
I wrote a test for this, but it won't run in CI currently, because that test requires Sphinx to be installed. That's why the pre-commit check is failing. |
1daa5c1 to
b21e641
Compare
|
I need to make sure the |
|
I haven't a clue what's going on with those |
on a quick look I see two tests without docstrings |
|
Checks are passing, I think it's ready @hynek |
c824181 to
672bfb7
Compare
|
@clayote Your actions create a lot of noise and many notifications. It would be helpful if you did more work offline and and only post updates and questions when really needed. This would make it easier for reviewers/maintainers to help you. |
5858047 to
a31031b
Compare
|
@clayote: feel free to ping me when it's ready for me to test 👌🏼 |
|
@AdrianSosic Please do |
|
Huh, I guess I'd better write documentation for the extension. It's not part of the API, really? Where should it go... |
b679a23 to
43c0e16
Compare
86739d5 to
260eac3
Compare
|
Hey I'm sorry for not turning up earlier, and I'm extra sorry if my innocent question for a test on the other PR lead us to this +340 diff that also contains a whole Sphinx extension. I will not maintain a Sphinx extension, but if you want to, we can let yours live within the Either way, your changes to the very heart of attrs and its behavior is just too deep and far-reaching for a too narrow of a use-case. I should've stopped you earlier and I've also amended our contribution guidelines to avoid this situation in the future in #1528. I'm very sorry, I feel bad about how all this went down. |
Mostly! I did a little more experimentation, and it turns out that, if my PR to Sphinx is merged, I can write the extension with no changes to There still needs to be a Sphinx extension to reconstruct the |
|
Well, that extension does work, but it relies on the current way that cached properties get made on slotted classes. If the _make_cached_property_getattr utility function were to change slightly, the extension would break. @hynek would you be open to putting the cached property functions in the public API somewhere, perhaps |
Summary
This is a small extension for Sphinx, the documentation generator that attrs uses. Where cached properties on slots classes were missing previously (#1325), this extension restores them.
I added a dictionary to slotted class objects,
__attrs_cached_properties__, where they keep the cached property objects for Sphinx.I wrapped the
__slots__tuple itself in a customcollections.abc.Sequencethat acts exactly like its tuple, but isn't considered one for the purposes ofisinstance(), because, currently, I have to do that in order to make Sphinx use the extension on slots. I have a PR for Sphinx open to make that unnecessary.To use the extension, add
"attrs.sphinx_cached_property"toextensionsin your Sphinxconf.py.Pull Request Check List
mainbranch – use a separate branch!Our CI fails if coverage is not 100%.
.pyi).typing-examples/baseline.pyor, if necessary,typing-examples/mypy.py.attr/__init__.pyi, they've also been re-imported inattrs/__init__.pyi.docs/api.rstby hand.@attr.s()and@attrs.define()have to be added by hand too.versionadded,versionchanged, ordeprecateddirectives.The next version is the second number in the current release + 1.
The first number represents the current year.
So if the current version on PyPI is 22.2.0, the next version is gonna be 22.3.0.
If the next version is the first in the new year, it'll be 23.1.0.
attrs.define()andattr.s(), you have to add version directives to both..rstand.mdfiles is written using semantic newlines.changelog.d.