commit - 1ad7903cd8c5410dc6573ea27d284a4fa79ec184
commit + dcec8734567b6d4542b94e00d8d9386d60c1acca
blob - 95e5d1718f15aad4e0d34e272fd7a4eec94a926f
blob + 3435dcdb20838dfe9a2a44f51691c33357fe5588
--- dulwich/objectspec.py
+++ dulwich/objectspec.py
"""Object specification."""
-from typing import List, Tuple, Union
+from typing import List, Tuple, Union, TYPE_CHECKING, Optional, Iterator
+if TYPE_CHECKING:
+ from dulwich.objects import ShaFile, Commit, Tree
+ from dulwich.refs import RefsContainer, Ref
+ from dulwich.repo import Repo
-def to_bytes(text):
+
+def to_bytes(text: Union[str, bytes]) -> bytes:
if getattr(text, "encode", None) is not None:
- text = text.encode("ascii")
- return text
+ text = text.encode("ascii") # type: ignore
+ return text # type: ignore
-def parse_object(repo, objectish):
+def parse_object(repo: "Repo", objectish: Union[bytes, str]) -> "ShaFile":
"""Parse a string referring to an object.
Args:
return repo[objectish]
-def parse_tree(repo, treeish):
+def parse_tree(repo: "Repo", treeish: Union[bytes, str]) -> "Tree":
"""Parse a string referring to a tree.
Args:
return o
-def parse_ref(container, refspec):
+def parse_ref(container: Union["Repo", "RefsContainer"], refspec: Union[str, bytes]) -> "Ref":
"""Parse a string referring to a reference.
Args:
raise KeyError(refspec)
-def parse_reftuple(lh_container, rh_container, refspec, force=False):
+def parse_reftuple(
+ lh_container: Union["Repo", "RefsContainer"],
+ rh_container: Union["Repo", "RefsContainer"], refspec: Union[str, bytes],
+ force: bool = False) -> Tuple[Optional["Ref"], Optional["Ref"], bool]:
"""Parse a reftuple spec.
Args:
if refspec.startswith(b"+"):
force = True
refspec = refspec[1:]
+ lh: Optional[bytes]
+ rh: Optional[bytes]
if b":" in refspec:
(lh, rh) = refspec.split(b":")
else:
def parse_reftuples(
- lh_container, rh_container,
- refspecs: Union[bytes, List[bytes], List[Tuple[bytes, bytes]]],
+ lh_container: Union["Repo", "RefsContainer"],
+ rh_container: Union["Repo", "RefsContainer"],
+ refspecs: Union[bytes, List[bytes]],
force: bool = False):
"""Parse a list of reftuple specs to a list of reftuples.
return ret
-def parse_commit_range(repo, committishs):
+def parse_commit_range(repo: "Repo", committishs: Union[str, bytes]) -> Iterator["Commit"]:
"""Parse a string referring to a range of commits.
Args:
raise AmbiguousShortId(prefix, ret)
-def parse_commit(repo, committish):
+def parse_commit(repo: "Repo", committish: Union[str, bytes]) -> "Commit":
"""Parse a string referring to a single commit.
Args: