Skip to content

Commit 1f03e7f

Browse files
committed
Fix other submodule.base parent_commit annotations
This finishes the work in git.objects.submodule.base begun in 1541c62. Some remaining occurrences of the old Commit_ish type are in git.objects.submodule.root, which still need to be replaced. Even once that is done, this will not have fixed #1869, though it will be somewhat mitigated because each method's annotations related to parent_commit will reflect the types that can actually be used reliably under the current implementation, even if in some cases that may not be as broad as was meant, or hoped, to be supported. I expect this may lead the way to a fix for #1869, since the existing behavior and relationships will be clearer. Where the old Commit_ish annotations were changed here to "Commit", it reflects assumptions found by examining the implementation that other alternatives are not usable becuse something beloning to a Commit is used and no conversion or fallback is performed for it. Where a commit is looked up (which uses rev_parse), broader types are annotated. Where the argument is used without conversion and must have a `tree` attribute, it must be a Commit. Where the argument could be broader but must be compared meaningfully with something known to be a commit, it must at minimum have a binsha attribute to allow that equality comparison, implemented in Object, to be meaningful, so in such cases its type cannot include str.
1 parent 1541c62 commit 1f03e7f

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

git/objects/submodule/base.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,19 @@
4242

4343
# typing ----------------------------------------------------------------------
4444

45-
from typing import Callable, Dict, Mapping, Sequence, TYPE_CHECKING, cast
46-
from typing import Any, Iterator, Union
45+
from typing import (
46+
Any,
47+
Callable,
48+
Dict,
49+
Iterator,
50+
Mapping,
51+
Sequence,
52+
TYPE_CHECKING,
53+
Union,
54+
cast,
55+
)
4756

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

5059
if TYPE_CHECKING:
5160
from git.index import IndexFile
@@ -113,7 +122,7 @@ def __init__(
113122
mode: Union[int, None] = None,
114123
path: Union[PathLike, None] = None,
115124
name: Union[str, None] = None,
116-
parent_commit: Union[Old_commit_ish, None] = None,
125+
parent_commit: Union["Commit", None] = None,
117126
url: Union[str, None] = None,
118127
branch_path: Union[PathLike, None] = None,
119128
) -> None:
@@ -145,7 +154,6 @@ def __init__(
145154
if url is not None:
146155
self._url = url
147156
if branch_path is not None:
148-
# assert isinstance(branch_path, str)
149157
self._branch_path = branch_path
150158
if name is not None:
151159
self._name = name
@@ -214,7 +222,7 @@ def __repr__(self) -> str:
214222

215223
@classmethod
216224
def _config_parser(
217-
cls, repo: "Repo", parent_commit: Union[Old_commit_ish, None], read_only: bool
225+
cls, repo: "Repo", parent_commit: Union["Commit", None], read_only: bool
218226
) -> SubmoduleConfigParser:
219227
"""
220228
:return:
@@ -265,7 +273,7 @@ def _clear_cache(self) -> None:
265273
# END for each name to delete
266274

267275
@classmethod
268-
def _sio_modules(cls, parent_commit: Old_commit_ish) -> BytesIO:
276+
def _sio_modules(cls, parent_commit: "Commit") -> BytesIO:
269277
"""
270278
:return:
271279
Configuration file as :class:`~io.BytesIO` - we only access it through the
@@ -278,7 +286,7 @@ def _sio_modules(cls, parent_commit: Old_commit_ish) -> BytesIO:
278286
def _config_parser_constrained(self, read_only: bool) -> SectionConstraint:
279287
""":return: Config parser constrained to our submodule in read or write mode"""
280288
try:
281-
pc: Union["Old_commit_ish", None] = self.parent_commit
289+
pc = self.parent_commit
282290
except ValueError:
283291
pc = None
284292
# END handle empty parent repository

0 commit comments

Comments
 (0)