Skip to content

Commit 9de7310

Browse files
committed
Minor type fixes
1 parent 481f672 commit 9de7310

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

git/refs/symbolic.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def set_object(self, object: Union[Commit_ish, 'SymbolicReference', str], logmsg
285285
commit = property(_get_commit, set_commit, doc="Query or set commits directly") # type: ignore
286286
object = property(_get_object, set_object, doc="Return the object our ref currently refers to") # type: ignore
287287

288-
def _get_reference(self) -> 'Reference':
288+
def _get_reference(self) -> 'SymbolicReference':
289289
""":return: Reference Object we point to
290290
:raise TypeError: If this symbolic reference is detached, hence it doesn't point
291291
to a reference, but to a commit"""
@@ -683,7 +683,7 @@ def iter_items(cls: Type[T_References], repo: 'Repo', common_path: Union[PathLik
683683
return (r for r in cls._iter_items(repo, common_path) if r.__class__ == SymbolicReference or not r.is_detached)
684684

685685
@classmethod
686-
def from_path(cls, repo: 'Repo', path: PathLike) -> Union['Head', 'TagReference', 'Reference']:
686+
def from_path(cls: Type[T_References], repo: 'Repo', path: PathLike) -> T_References:
687687
"""
688688
:param path: full .git-directory-relative path name to the Reference to instantiate
689689
:note: use to_full_path() if you only have a partial path of a known Reference Type
@@ -698,12 +698,13 @@ def from_path(cls, repo: 'Repo', path: PathLike) -> Union['Head', 'TagReference'
698698
from . import HEAD, Head, RemoteReference, TagReference, Reference
699699
for ref_type in (HEAD, Head, RemoteReference, TagReference, Reference, SymbolicReference):
700700
try:
701+
instance: T_References
701702
instance = ref_type(repo, path)
702703
if instance.__class__ == SymbolicReference and instance.is_detached:
703704
raise ValueError("SymbolRef was detached, we drop it")
704705
else:
705-
assert isinstance(instance, Reference), "instance should be Reference or subtype"
706706
return instance
707+
707708
except ValueError:
708709
pass
709710
# END exception handling

git/remote.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ def stale_refs(self) -> IterableList[Reference]:
632632
as well. This is a fix for the issue described here:
633633
https://github.com/gitpython-developers/GitPython/issues/260
634634
"""
635-
out_refs: IterableList[RemoteReference] = IterableList(RemoteReference._id_attribute_, "%s/" % self.name)
635+
out_refs: IterableList[Reference] = IterableList(RemoteReference._id_attribute_, "%s/" % self.name)
636636
for line in self.repo.git.remote("prune", "--dry-run", self).splitlines()[2:]:
637637
# expecting
638638
# * [would prune] origin/new_branch
@@ -642,7 +642,7 @@ def stale_refs(self) -> IterableList[Reference]:
642642
ref_name = line.replace(token, "")
643643
# sometimes, paths start with a full ref name, like refs/tags/foo, see #260
644644
if ref_name.startswith(Reference._common_path_default + '/'):
645-
out_refs.append(SymbolicReference.from_path(self.repo, ref_name))
645+
out_refs.append(Reference.from_path(self.repo, ref_name))
646646
else:
647647
fqhn = "%s/%s" % (RemoteReference._common_path_default, ref_name)
648648
out_refs.append(RemoteReference(self.repo, fqhn))

0 commit comments

Comments
 (0)