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 29 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... |
|
|
||
|
|
||
| class _TupleProxy(Sequence): | ||
| __slots__ = ("_tup",) |
There was a problem hiding this comment.
A docstring must be the first node in the class definition for it to end up in __doc__. Otherwise, it's a docstring of the __slots__ attribute which most tools don't parse as such (I only know of Sphinx). Though, looking at the text, it seems you meant it to be a class docstring...
b679a23 to
43c0e16
Compare
6fe52c2 to
fdccaa5
Compare
8c94c7f to
64e8291
Compare
for more information, see https://pre-commit.ci
| return props[name] | ||
|
|
||
|
|
||
| def setup(app: Sphinx): |
There was a problem hiding this comment.
| def setup(app: Sphinx): | |
| def setup(app: Sphinx) -> dict[str, bool | str]: |
|
|
||
| def get_cached_property_for_member_descriptor( | ||
| cls: type, name: str, default=None | ||
| ): |
There was a problem hiding this comment.
| ): | |
| ) -> str: |
?
There was a problem hiding this comment.
Maybe scope this all in a subdir?
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.