Skip to content

Commit a48e9c7

Browse files
committed
Start on fixing Submodule parent_commit annotations
These used the old Commit_ish. They may not all be the same as each other, since they perform different validation and some will look up a commit while others do not. In particular, this is complicated by how Submodile.__init__ documents its parent_commit parameter: it says to see the set_parent_commit method. But __init__ sets the _parent_commit attribute to parent_commit, while set_parent_commit treats its commit parameter differently, calling self.repo.commit on it to get get a Commit object from it even if it wasn't one to begin with. See gitpython-developers#1869 for full details. There may be some other subtleties as well. A number of uses of the of the old Commit_ish type appear in git.submodule.base, all related to parent_commit. These are all remaining references to it (identifiable due to the rename to Old_commit_ish done in 04a2753), though. So once the changes begun here for git.submodule.base are done, that will also have completed the broader replacement effort begun in 7328a00. At that point cleanup can be done in git.types (removing Old_commit_ish introduced in 04a2753, replacing Lit_old_commit_ish with a possibly-updated and deprecated Lit_commit_ish to avoid a breaking change, and possibly making further refinements to additions to the newly added docstrings).
1 parent 5b2869f commit a48e9c7

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Diff for: git/objects/submodule/base.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@
4545
from typing import Callable, Dict, Mapping, Sequence, TYPE_CHECKING, cast
4646
from typing import Any, Iterator, Union
4747

48-
from git.types import Old_commit_ish, Literal, PathLike, TBD
48+
from git.types import Commit_ish, Literal, Old_commit_ish, PathLike, TBD
4949

5050
if TYPE_CHECKING:
5151
from git.index import IndexFile
52-
from git.repo import Repo
52+
from git.objects.commit import Commit
5353
from git.refs import Head
54+
from git.repo import Repo
5455

5556
# -----------------------------------------------------------------------------
5657

@@ -99,7 +100,7 @@ class Submodule(IndexObject, TraversableIterableObj):
99100
"""Submodule flags. Submodules are directories with link-status."""
100101

101102
type: Literal["submodule"] = "submodule" # type: ignore
102-
"""This is a bogus type for base class compatibility."""
103+
"""This is a bogus type string for base class compatibility."""
103104

104105
__slots__ = ("_parent_commit", "_url", "_branch_path", "_name", "__weakref__")
105106

@@ -1242,7 +1243,7 @@ def remove(
12421243

12431244
return self
12441245

1245-
def set_parent_commit(self, commit: Union[Old_commit_ish, None], check: bool = True) -> "Submodule":
1246+
def set_parent_commit(self, commit: Union[Commit_ish, str, None], check: bool = True) -> "Submodule":
12461247
"""Set this instance to use the given commit whose tree is supposed to
12471248
contain the ``.gitmodules`` blob.
12481249
@@ -1495,7 +1496,7 @@ def url(self) -> str:
14951496
return self._url
14961497

14971498
@property
1498-
def parent_commit(self) -> "Old_commit_ish":
1499+
def parent_commit(self) -> "Commit":
14991500
"""
15001501
:return:
15011502
:class:`~git.objects.commit.Commit` instance with the tree containing the
@@ -1557,8 +1558,8 @@ def children(self) -> IterableList["Submodule"]:
15571558
def iter_items(
15581559
cls,
15591560
repo: "Repo",
1560-
parent_commit: Union[Old_commit_ish, str] = "HEAD",
1561-
*Args: Any,
1561+
parent_commit: Union[Commit_ish, str] = "HEAD",
1562+
*args: Any,
15621563
**kwargs: Any,
15631564
) -> Iterator["Submodule"]:
15641565
"""

0 commit comments

Comments
 (0)