Skip to content

Commit c9952e1

Browse files
committed
Fix Sphinx references; give Diffable.Index a docstring
1 parent 65863a2 commit c9952e1

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

git/diff.py

+21-6
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,30 @@ class Diffable:
149149
:const:`git.NULL_TREE` and :const:`git.diff.NULL_TREE`.
150150
"""
151151

152-
INDEX = Index = INDEX
152+
INDEX = INDEX
153153
"""Stand-in indicating you want to diff against the index.
154154
155155
See the :meth:`diff` method, which accepts this as a value of its ``other``
156156
parameter.
157157
158158
This is the same as :const:`DiffConstants.INDEX`, and may also be accessed as
159-
:const:`git.INDEX` and :const:`git.diff.INDEX`.
159+
:const:`git.INDEX` and :const:`git.diff.INDEX`, as well as :class:`Diffable.INDEX`,
160+
which is kept for backward compatibility (it is now defined an alias of this).
161+
"""
162+
163+
Index = INDEX
164+
"""Stand-in indicating you want to diff against the index
165+
(same as :const:`~Diffable.INDEX`).
166+
167+
This is an alias of :const:`~Diffable.INDEX`, for backward compatibility. See
168+
:const:`~Diffable.INDEX` and :meth:`diff` for details.
169+
170+
:note:
171+
Although always meant for use as an opaque constant, this was formerly defined
172+
as a class. Its usage is unchanged, but static type annotations that attempt
173+
to permit only this object must be changed to avoid new mypy errors. This was
174+
previously not possible to do, though ``Type[Diffable.Index]`` approximated it.
175+
It is now possible to do precisely, using ``Literal[DiffConstants.INDEX]``.
160176
"""
161177

162178
def _process_diff_args(
@@ -213,10 +229,9 @@ def diff(
213229
A :class:`DiffIndex` representing the computed diff.
214230
215231
:note:
216-
On a bare repository, `other` needs to be provided as
217-
:class:`~Diffable.Index`, or as an instance of
218-
:class:`~git.objects.tree.Tree` or :class:`~git.objects.commit.Commit`, or a
219-
git command error will occur.
232+
On a bare repository, `other` needs to be provided as :const:`INDEX`, or as
233+
an instance of :class:`~git.objects.tree.Tree` or
234+
:class:`~git.objects.commit.Commit`, or a git command error will occur.
220235
"""
221236
args: List[Union[PathLike, Diffable]] = []
222237
args.append("--abbrev=40") # We need full shas.

0 commit comments

Comments
 (0)