Skip to content

Commit fbdf7e8

Browse files
committed
Auto format
1 parent e48fbde commit fbdf7e8

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

src/mkdocstrings_handlers/python/rendering.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Order(enum.Enum):
5151
source = "source"
5252
"""Source code order."""
5353

54+
5455
class DocstringInheritStrategy(str, enum.Enum):
5556
"""Enumeration for the possible docstring inheritance strategies."""
5657

@@ -379,9 +380,11 @@ def _keep_object(name: str, filters: Sequence[tuple[Pattern, bool]]) -> bool:
379380
return rules != {False}
380381
return keep
381382

382-
def _construct_docstring_according_to_strategy(name: str, obj: Object | Alias, strategy: DocstringInheritStrategy, merge_delimiter: str = "\n") -> Docstring | None:
383-
"""
384-
Construct a docstring object according to the strategy.
383+
384+
def _construct_docstring_according_to_strategy(
385+
name: str, obj: Object | Alias, strategy: DocstringInheritStrategy, merge_delimiter: str = "\n"
386+
) -> Docstring | None:
387+
"""Construct a docstring object according to the strategy.
385388
386389
Parameters:
387390
name: The name of the member. Needed to lookup the member in the parent classes.
@@ -392,7 +395,6 @@ def _construct_docstring_according_to_strategy(name: str, obj: Object | Alias, s
392395
Returns:
393396
A new docstring object that just contains the docstring content.
394397
"""
395-
396398
if strategy == DocstringInheritStrategy.default:
397399
# Base case: we don't want to inherit docstrings
398400
return None
@@ -435,7 +437,9 @@ def do_optionally_inherit_docstrings(
435437
try:
436438
strategy = DocstringInheritStrategy(docstring_inherit_strategy)
437439
except ValueError as e:
438-
raise ValueError(f"Unknown docstring inherit strategy: '{docstring_inherit_strategy}', allowed options are: {', '.join(strategy.value for strategy in DocstringInheritStrategy)}") from e
440+
raise ValueError(
441+
f"Unknown docstring inherit strategy: '{docstring_inherit_strategy}', allowed options are: {', '.join(strategy.value for strategy in DocstringInheritStrategy)}"
442+
) from e
439443

440444
if strategy == DocstringInheritStrategy.default:
441445
return objects
@@ -446,7 +450,9 @@ def do_optionally_inherit_docstrings(
446450

447451
for obj, new_obj in zip(objects.values(), new_objects.values()):
448452
for member_name, new_member in new_obj.members.items():
449-
docstring = _construct_docstring_according_to_strategy(member_name, obj, strategy=strategy, merge_delimiter=docstring_merge_delimiter)
453+
docstring = _construct_docstring_according_to_strategy(
454+
member_name, obj, strategy=strategy, merge_delimiter=docstring_merge_delimiter
455+
)
450456

451457
if not docstring:
452458
continue
@@ -463,6 +469,7 @@ def do_optionally_inherit_docstrings(
463469

464470
return new_objects
465471

472+
466473
def do_filter_objects(
467474
objects_dictionary: dict[str, Object | Alias],
468475
*,

tests/test_rendering.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,27 +166,37 @@ def __init__(self, name: str, lineno: int | None = None, *, is_alias: bool = Fal
166166
assert [obj.name for obj in ordered] == expected_names
167167

168168

169-
170-
171169
@pytest.mark.parametrize(
172170
("strategy", "docstrings_list", "expected_docstrings_list"),
173171
[
174-
(rendering.DocstringInheritStrategy.default, ['"""base"""', '', ''], ['base', None, None]),
175-
(rendering.DocstringInheritStrategy.if_not_present, ['"""base"""', '"""main"""', ''], ['base', 'main', 'main']), # main: stays the same (no merge); sub: main is taken (not base)
176-
(rendering.DocstringInheritStrategy.merge, ['"""base"""', '"""main"""', ''], ['base', 'base+main', 'base+main']), # main: is merged with base; sub: empty is merged with base+main (not base+main+)
177-
(rendering.DocstringInheritStrategy.merge, ['', '"""main"""', ''], [None, 'main', 'main']), # Base class has no docstring after merging (as opposed to an empty one)
172+
(rendering.DocstringInheritStrategy.default, ['"""base"""', "", ""], ["base", None, None]),
173+
(
174+
rendering.DocstringInheritStrategy.if_not_present,
175+
['"""base"""', '"""main"""', ""],
176+
["base", "main", "main"],
177+
), # main: stays the same (no merge); sub: main is taken (not base)
178+
(
179+
rendering.DocstringInheritStrategy.merge,
180+
['"""base"""', '"""main"""', ""],
181+
["base", "base+main", "base+main"],
182+
), # main: is merged with base; sub: empty is merged with base+main (not base+main+)
183+
(
184+
rendering.DocstringInheritStrategy.merge,
185+
["", '"""main"""', ""],
186+
[None, "main", "main"],
187+
), # Base class has no docstring after merging (as opposed to an empty one)
178188
],
179189
)
180-
def test_do_optionally_inherit_docstrings(strategy: rendering.DocstringInheritStrategy, docstrings_list: list[str], expected_docstrings_list: list[str]) -> None:
181-
"""
182-
Test the inheritance strategies of docstrings for members.
190+
def test_do_optionally_inherit_docstrings(
191+
strategy: rendering.DocstringInheritStrategy, docstrings_list: list[str], expected_docstrings_list: list[str]
192+
) -> None:
193+
"""Test the inheritance strategies of docstrings for members.
183194
184195
Parameters:
185196
strategy: The docstring inheritance strategy to use.
186197
docstrings_list: The list of docstrings for the base, main, and sub classes. Needs triple quotes.
187198
expected_docstrings_list: The expected list of docstrings for the base, main, and sub classes. Just the content, i.e. without triple quotes. None for no docstring at all.
188199
"""
189-
190200
docstring_base, docstring_main, docstring_sub = docstrings_list
191201

192202
collection = ModulesCollection()
@@ -221,10 +231,7 @@ def base(self):
221231
docstring_inherit_strategy=strategy,
222232
docstring_merge_delimiter="+",
223233
)
224-
docstrings = [
225-
result[class_].members["base"].docstring
226-
for class_ in classes
227-
]
234+
docstrings = [result[class_].members["base"].docstring for class_ in classes]
228235
docstring_values = [docstring.value if docstring else None for docstring in docstrings]
229236

230-
assert docstring_values == expected_docstrings_list
237+
assert docstring_values == expected_docstrings_list

0 commit comments

Comments
 (0)