Skip to content

Commit b2189d9

Browse files
codexByron
authored andcommitted
docs: render supported subclass interface docstrings (#1848)
Sphinx omits underscore-prefixed methods by default, hiding documented extension points such as `RemoteProgress._parse_progress_line()` and `LockFile._obtain_lock()`. Traversal documentation used a separate allowlist, and `Tree.traverse()` linked to its implementation using an ordinary URL. Mark supported subclass interfaces with Sphinx's built-in `:meta public:` docstring metadata. Remove the traversal-specific `:private-members:` list, use a method reference for traversal documentation, and explain this convention in `CONTRIBUTING.md`. Private implementation helpers stay hidden. Repair an existing malformed `is_relative_url()` return field so strict HTML validation can complete. Before this change, the HTML reference lacked the progress and lock extension-point targets. The strict Sphinx HTML build now passes. Assertions against its output verify all five selected interface targets, the traversal link, and omission of `LockFile._lock_file_path()`. Runtime logic is unchanged.
1 parent bdd27ec commit b2189d9

6 files changed

Lines changed: 22 additions & 5 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ Attributing AI assistance in commit metadata, for example with a `Co-authored-by
4848
trailer, is welcome but not required. Code is reviewed the same way regardless of its
4949
origin.
5050

51+
## Documenting subclass interfaces
52+
53+
Use Sphinx's `:meta public:` field in docstrings of underscore-prefixed methods
54+
that form a supported interface for subclasses. This includes their documentation
55+
in the API reference without exposing unrelated private implementation details.
56+
5157
## Temporary test directories
5258

5359
Tests require Python 3.11+, Git 2.52+, Bash, and the `test` extra, which installs

‎doc/source/reference.rst‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ Objects.Util
9191
.. automodule:: git.objects.util
9292
:members:
9393
:undoc-members:
94-
:private-members: _get_intermediate_items, _list_traverse, _traverse
9594
:special-members:
9695

9796
Index.Base

‎git/objects/submodule/util.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@ def _find_last_dir_sep(url: str) -> int:
9999

100100

101101
def is_relative_url(url: str) -> bool:
102-
""":return: ``True`` if `url` starts with ``./`` or ``../``, which git resolves
103-
against the superproject's remote rather than treating as a path"""
102+
"""Check whether Git resolves a URL against the superproject's remote.
103+
104+
:return:
105+
``True`` if `url` starts with ``./`` or ``../``.
106+
"""
104107
return _starts_with_dot_slash(url) or _starts_with_dot_dot_slash(url)
105108

106109

‎git/objects/tree.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ def traverse(
328328
ignore_self: int = 1,
329329
as_edge: bool = False,
330330
) -> Union[Iterator[IndexObjUnion], Iterator[TraversedTreeTup]]:
331-
"""For documentation, see
332-
`Traversable._traverse() <git.objects.util.Traversable._traverse>`.
331+
"""For documentation, see :meth:`~git.objects.util.Traversable._traverse`.
333332
334333
Trees are set to ``visit_once = False`` to gain more performance in the
335334
traversal.

‎git/objects/util.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ class Traversable(Protocol):
334334
@abstractmethod
335335
def _get_intermediate_items(cls, item: Any) -> Sequence["Traversable"]:
336336
"""
337+
:meta public:
338+
337339
:return:
338340
Tuple of items connected to the given item.
339341
Must be implemented in subclass.
@@ -354,6 +356,8 @@ def _list_traverse(
354356
) -> IterableList[Union["Commit", "Submodule", "Tree", "Blob"]]:
355357
"""Traverse self and collect all items found.
356358
359+
:meta public:
360+
357361
:return:
358362
:class:`~git.util.IterableList` with the results of the traversal as
359363
produced by :meth:`traverse`::
@@ -401,6 +405,8 @@ def _traverse(
401405
) -> Union[Iterator[Union["Traversable", "Blob"]], Iterator[TraversedTup]]:
402406
"""Iterator yielding items found when traversing `self`.
403407
408+
:meta public:
409+
404410
:param predicate:
405411
A function ``f(i,d)`` that returns ``False`` if item i at depth ``d`` should
406412
not be included in the result.

‎git/util.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,8 @@ def _parse_progress_line(self, line: AnyStr) -> Optional[object]:
712712
"""Parse progress information from the given line as retrieved by
713713
:manpage:`git-push(1)` or :manpage:`git-fetch(1)`.
714714
715+
:meta public:
716+
715717
- Lines that do not contain progress info are stored in :attr:`other_lines`.
716718
- Lines that seem to contain an error (i.e. start with ``error:`` or ``fatal:``)
717719
are stored in :attr:`error_lines`.
@@ -1171,6 +1173,8 @@ def _obtain_lock_or_raise(self) -> None:
11711173
def _obtain_lock(self) -> None:
11721174
"""The default implementation will raise if a lock cannot be obtained.
11731175
1176+
:meta public:
1177+
11741178
Subclasses may override this method to provide a different implementation.
11751179
"""
11761180
return self._obtain_lock_or_raise()

0 commit comments

Comments
 (0)