Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit70ef69a

Browse files
committed
Include TagObject in git.types.Tree_ish
The Tree_ish union omitted TagObject, whose instances are onlysometimes tree-ish, and unlike Commit_ish before#1859, it is notinherently a bug to define Tree_ish this way.However, this Tree_ish type actually has only one use in GitPython(which was also the case before the changes in#1859): as, itself,an alternative in the union used to annotate the rev parameter ofthe Repo.tree method (whose other alternatives are str and None).A TagObject may be passed, and if it points to a tree or committhen that will be resolved. Just to avoid a mypy error, code doingthat would (before this change) have to convert it to str first.That annotation should be improved, and the best way to do it is tokeep it written the same way but change the definition of Tree_ishin git.types to include TagObject. The reason is that doing soalleviates a major unintuitive aspect of the relationship betweenthe Commit_ish and Tree_ish types: Commit_ish was broader thaneverything commit-ish, while Tree_ish was narrower than everythingtree-ish.I had not considered making this change in#1859 because I didn'twant to modify Tree_ish unnecessarily, and its definition was notinherently a bug. However, the change to Commit_ish is sufficientlylarge (though it only affects static typing) that a change toTree_ish to make them coherent and intuitive may be justified.This commit changes Tree_ish so that, in addition to its Commit andTree alternatives, it also includes TagObject. This also updatesand simplifies its docstring accordingly, bringing it in line withthat of Commit_ish which is already defined with the same kind ofbreadth, and further revises both docstrings to more explicitlyclarify when tags are tree-ish or commit-ish and when they are not.This does not change the separate nonpublic Treeish type defined ingit.index.base (and named with no underscore), which omitsTagObject but includes bytes and str, and which is used to annotateparameters of the IndexFile.from_tree and IndexFile.merge_treemethods. Changes there may be valuable, but the goal here is justto build narrowly on#1859 to address a shortcoming of therevisions to git.types.
1 parentbcea9a8 commit70ef69a

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

‎git/types.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,18 @@
7373
See also the :class:`Tree_ish` and :class:`Commit_ish` unions.
7474
"""
7575

76-
Tree_ish=Union["Commit","Tree"]
77-
"""Union of :class:`~git.objects.base.Object`-based types that areinherently tree-ish.
76+
Tree_ish=Union["Commit","Tree","TagObject"]
77+
"""Union of :class:`~git.objects.base.Object`-based types that aresometimes tree-ish.
7878
7979
See gitglossary(7) on "tree-ish": https://git-scm.com/docs/gitglossary#def_tree-ish
8080
8181
:note:
82-
This union comprises **only** the :class:`~git.objects.commit.Commit` and
83-
:class:`~git.objects.tree.Tree` classes, **all** of whose instances are tree-ish.
84-
This has been done because of the way GitPython uses it as a static type annotation.
85-
86-
:class:`~git.objects.tag.TagObject`, some but not all of whose instances are
87-
tree-ish (those representing git tag objects that ultimately resolve to a tree or
88-
commit), is not covered as part of this union type.
82+
:class:`~git.objects.tree.Tree` and :class:`~git.objects.commit.Commit` are the
83+
classes whose instances are all tree-ish. This union includes them, but also
84+
:class:`~git.objects.tag.TagObject`, only **some** of whose instances are tree-ish.
85+
Whether a particular :class:`~git.objects.tag.TagObject` peels (recursively
86+
dereferences) to a tree or commit, rather than a blob, can in general only be known
87+
at runtime.
8988
9089
:note:
9190
See also the :class:`AnyGitObject` union of all four classes corresponding to git
@@ -102,12 +101,8 @@
102101
commit-ish. This union type includes :class:`~git.objects.commit.Commit`, but also
103102
:class:`~git.objects.tag.TagObject`, only **some** of whose instances are
104103
commit-ish. Whether a particular :class:`~git.objects.tag.TagObject` peels
105-
(recursively dereferences) to a commit can in general only be known at runtime.
106-
107-
:note:
108-
This is an inversion of the situation with :class:`Tree_ish`. This union is broader
109-
than all commit-ish objects, while :class:`Tree_ish` is narrower than all tree-ish
110-
objects.
104+
(recursively dereferences) to a commit, rather than a tree or blob, can in general
105+
only be known at runtime.
111106
112107
:note:
113108
See also the :class:`AnyGitObject` union of all four classes corresponding to git

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp