Skip to content

Commit 5858047

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 672bfb7 commit 5858047

6 files changed

Lines changed: 32 additions & 17 deletions

File tree

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: MIT
22

33
import os
4-
import sys
54

65
from importlib import metadata
76
from pathlib import Path

src/attr/_make.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,12 @@ def __reduce__(self, _none_constructor=type(None), _args=()): # noqa: B008
106106
class _TupleProxy(Sequence):
107107
__slots__ = ("_tup",)
108108
"""A wrapper for a tuple that makes it not type-check as a tuple
109-
109+
110110
This is a hack to make Sphinx document all cached properties on slots
111111
classes as if they were regular properties.
112-
112+
113113
"""
114+
114115
def __init__(self, tup: tuple):
115116
self._tup = tup
116117

@@ -958,9 +959,12 @@ def _create_slots_class(self):
958959
additional_closure_functions_to_update.append(original_getattr)
959960

960961
cd["__getattr__"] = _make_cached_property_getattr(
961-
{name: prop.func for (name, prop) in cached_properties.items()},
962+
{
963+
name: prop.func
964+
for (name, prop) in cached_properties.items()
965+
},
962966
original_getattr,
963-
self._cls
967+
self._cls,
964968
)
965969

966970
# We only add the names of attributes that aren't inherited.

src/attrs/sphinx_cached_property.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99
from sphinx.application import Sphinx
1010

1111

12-
def get_cached_property_for_member_descriptor(cls: type, name: str, default=None):
13-
props = getattr(cls, "__attrs_cached_properties__", None)
14-
if props is None or name not in props:
15-
return getattr(cls, name, default)
16-
return props[name]
12+
def get_cached_property_for_member_descriptor(
13+
cls: type, name: str, default=None
14+
):
15+
props = getattr(cls, "__attrs_cached_properties__", None)
16+
if props is None or name not in props:
17+
return getattr(cls, name, default)
18+
return props[name]
19+
1720

1821
def setup(app: Sphinx):
19-
app.add_autodoc_attrgetter(object, get_cached_property_for_member_descriptor)
22+
app.add_autodoc_attrgetter(
23+
object, get_cached_property_for_member_descriptor
24+
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.. autoclass:: tests.test_slots.SphinxDocTest
22

3-
.. autoproperty:: documented
3+
.. autoproperty:: documented

tests/members-cached-property.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
.. autoclass:: tests.test_slots.SphinxDocTest
2-
:members:
2+
:members:

tests/test_slots.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,10 @@ def documented(self):
778778
return True
779779

780780

781-
need_sphinx = pytest.mark.skipif(Sphinx is None, reason="Sphinx is not installed")
781+
need_sphinx = pytest.mark.skipif(
782+
Sphinx is None, reason="Sphinx is not installed"
783+
)
784+
782785

783786
@need_sphinx
784787
def test_sphinx_autodocuments_cached_property():
@@ -795,7 +798,9 @@ def test_sphinx_autodocuments_cached_property():
795798
outf.write(line)
796799
outdir = tmp_path.joinpath("docs")
797800
outdir.mkdir()
798-
app = Sphinx(tmp_path, here.parent.joinpath("docs"), outdir, tmp_path, "text")
801+
app = Sphinx(
802+
tmp_path, here.parent.joinpath("docs"), outdir, tmp_path, "text"
803+
)
799804
app.build(force_all=True)
800805
with (
801806
outdir.joinpath("index.txt").open("r") as written,
@@ -819,11 +824,13 @@ def test_sphinx_automembers_cached_property():
819824
outf.write(line)
820825
outdir = tmp_path.joinpath("docs")
821826
outdir.mkdir()
822-
app = Sphinx(tmp_path, here.parent.joinpath("docs"), outdir, tmp_path, "text")
827+
app = Sphinx(
828+
tmp_path, here.parent.joinpath("docs"), outdir, tmp_path, "text"
829+
)
823830
app.build(force_all=True)
824831
with (
825832
outdir.joinpath("index.txt").open("r") as written,
826-
here.joinpath("index.txt").open("r") as good
833+
here.joinpath("index.txt").open("r") as good,
827834
):
828835
assert written.read() == good.read()
829836

0 commit comments

Comments
 (0)