Skip to content

Commit 2a350b5

Browse files
committed
Add final final types to symbolic.py
1 parent 3c2454d commit 2a350b5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Diff for: git/refs/symbolic.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
__all__ = ["SymbolicReference"]
4141

4242

43-
def _git_dir(repo: 'Repo', path: PathLike) -> PathLike:
43+
def _git_dir(repo: 'Repo', path: Union[PathLike, None]) -> PathLike:
4444
""" Find the git dir that's appropriate for the path"""
4545
name = f"{path}"
4646
if name in ['HEAD', 'ORIG_HEAD', 'FETCH_HEAD', 'index', 'logs']:
@@ -140,26 +140,28 @@ def _iter_packed_refs(cls, repo: 'Repo') -> Iterator[Tuple[str, str]]:
140140
# alright.
141141

142142
@classmethod
143-
def dereference_recursive(cls, repo: 'Repo', ref_path: PathLike) -> str:
143+
def dereference_recursive(cls, repo: 'Repo', ref_path: Union[PathLike, None]) -> str:
144144
"""
145145
:return: hexsha stored in the reference at the given ref_path, recursively dereferencing all
146146
intermediate references as required
147147
:param repo: the repository containing the reference at ref_path"""
148+
148149
while True:
149-
hexsha, ref_path = cls._get_ref_info(repo, ref_path) # type: ignore
150+
hexsha, ref_path = cls._get_ref_info(repo, ref_path)
150151
if hexsha is not None:
151152
return hexsha
152153
# END recursive dereferencing
153154

154155
@classmethod
155-
def _get_ref_info_helper(cls, repo: 'Repo', ref_path: PathLike) -> Union[Tuple[str, None], Tuple[None, str]]:
156+
def _get_ref_info_helper(cls, repo: 'Repo', ref_path: Union[PathLike, None]
157+
) -> Union[Tuple[str, None], Tuple[None, str]]:
156158
"""Return: (str(sha), str(target_ref_path)) if available, the sha the file at
157159
rela_path points to, or None. target_ref_path is the reference we
158160
point to, or None"""
159161
tokens: Union[None, List[str], Tuple[str, str]] = None
160162
repodir = _git_dir(repo, ref_path)
161163
try:
162-
with open(os.path.join(repodir, ref_path), 'rt', encoding='UTF-8') as fp:
164+
with open(os.path.join(repodir, str(ref_path)), 'rt', encoding='UTF-8') as fp:
163165
value = fp.read().rstrip()
164166
# Don't only split on spaces, but on whitespace, which allows to parse lines like
165167
# 60b64ef992065e2600bfef6187a97f92398a9144 branch 'master' of git-server:/path/to/repo
@@ -191,7 +193,7 @@ def _get_ref_info_helper(cls, repo: 'Repo', ref_path: PathLike) -> Union[Tuple[s
191193
raise ValueError("Failed to parse reference information from %r" % ref_path)
192194

193195
@classmethod
194-
def _get_ref_info(cls, repo: 'Repo', ref_path: PathLike) -> Union[Tuple[str, None], Tuple[None, str]]:
196+
def _get_ref_info(cls, repo: 'Repo', ref_path: Union[PathLike, None]) -> Union[Tuple[str, None], Tuple[None, str]]:
195197
"""Return: (str(sha), str(target_ref_path)) if available, the sha the file at
196198
rela_path points to, or None. target_ref_path is the reference we
197199
point to, or None"""

0 commit comments

Comments
 (0)