summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--git/cmd.py8
-rw-r--r--git/config.py3
-rw-r--r--git/diff.py4
-rw-r--r--git/index/base.py1
-rw-r--r--git/objects/fun.py2
-rw-r--r--git/objects/tree.py2
-rw-r--r--git/objects/util.py8
-rw-r--r--git/repo/base.py1
-rw-r--r--git/repo/fun.py21
-rw-r--r--pyproject.toml2
10 files changed, 29 insertions, 23 deletions
diff --git a/git/cmd.py b/git/cmd.py
index 9d070367..e690dc12 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -42,7 +42,7 @@ from .util import (
from typing import (Any, AnyStr, BinaryIO, Callable, Dict, IO, Iterator, List, Mapping,
Sequence, TYPE_CHECKING, TextIO, Tuple, Union, cast, overload)
-from git.types import PathLike, Literal
+from git.types import PathLike, Literal, TBD
if TYPE_CHECKING:
from git.repo.base import Repo
@@ -575,8 +575,8 @@ class Git(LazyMixin):
self._environment: Dict[str, str] = {}
# cached command slots
- self.cat_file_header = None
- self.cat_file_all = None
+ self.cat_file_header: Union[None, TBD] = None
+ self.cat_file_all: Union[None, TBD] = None
def __getattr__(self, name: str) -> Any:
"""A convenience method as it allows to call the command as if it was
@@ -1012,8 +1012,6 @@ class Git(LazyMixin):
@classmethod
def __unpack_args(cls, arg_list: Sequence[str]) -> List[str]:
- if not isinstance(arg_list, (list, tuple)):
- return [str(arg_list)]
outlist = []
for arg in arg_list:
diff --git a/git/config.py b/git/config.py
index 91bf65d3..2a5aa142 100644
--- a/git/config.py
+++ b/git/config.py
@@ -236,7 +236,8 @@ def get_config_path(config_level: Lit_config_levels) -> str:
raise ValueError("No repo to get repository configuration from. Use Repo._get_config_path")
else:
# Should not reach here. Will raise ValueError if does. Static typing will warn missing elifs
- assert_never(config_level, ValueError(f"Invalid configuration level: {config_level!r}"))
+ assert_never(config_level, # type: ignore[unreachable]
+ ValueError(f"Invalid configuration level: {config_level!r}"))
class GitConfigParser(cp.RawConfigParser, metaclass=MetaParserBuilder):
diff --git a/git/diff.py b/git/diff.py
index fc16b73e..cea66d7e 100644
--- a/git/diff.py
+++ b/git/diff.py
@@ -456,8 +456,8 @@ class Diff(object):
# for now, we have to bake the stream
text = b''.join(text_list)
index: 'DiffIndex' = DiffIndex()
- previous_header = None
- header = None
+ previous_header: Union[Match[bytes], None] = None
+ header: Union[Match[bytes], None] = None
a_path, b_path = None, None # for mypy
a_mode, b_mode = None, None # for mypy
for _header in cls.re_header.finditer(text):
diff --git a/git/index/base.py b/git/index/base.py
index 4c8b923a..102703e6 100644
--- a/git/index/base.py
+++ b/git/index/base.py
@@ -1202,7 +1202,6 @@ class IndexFile(LazyMixin, git_diff.Diffable, Serializable):
handle_stderr(proc, checked_out_files)
return checked_out_files
# END paths handling
- assert "Should not reach this point"
@ default_index
def reset(self, commit: Union[Commit, 'Reference', str] = 'HEAD', working_tree: bool = False,
diff --git a/git/objects/fun.py b/git/objects/fun.py
index d6cdafe1..19b4e525 100644
--- a/git/objects/fun.py
+++ b/git/objects/fun.py
@@ -51,7 +51,7 @@ def tree_to_stream(entries: Sequence[EntryTup], write: Callable[['ReadableBuffer
if isinstance(name, str):
name_bytes = name.encode(defenc)
else:
- name_bytes = name
+ name_bytes = name # type: ignore[unreachable] # check runtime types - is always str?
write(b''.join((mode_str, b' ', name_bytes, b'\0', binsha)))
# END for each item
diff --git a/git/objects/tree.py b/git/objects/tree.py
index 0cceb59a..22531895 100644
--- a/git/objects/tree.py
+++ b/git/objects/tree.py
@@ -215,7 +215,7 @@ class Tree(IndexObject, git_diff.Diffable, util.Traversable, util.Serializable):
super(Tree, self).__init__(repo, binsha, mode, path)
@ classmethod
- def _get_intermediate_items(cls, index_object: 'Tree',
+ def _get_intermediate_items(cls, index_object: IndexObjUnion,
) -> Union[Tuple['Tree', ...], Tuple[()]]:
if index_object.type == "tree":
return tuple(index_object._iter_convert_to_object(index_object._cache))
diff --git a/git/objects/util.py b/git/objects/util.py
index d3842cfb..9c9ce773 100644
--- a/git/objects/util.py
+++ b/git/objects/util.py
@@ -167,7 +167,7 @@ def from_timestamp(timestamp: float, tz_offset: float) -> datetime:
return utc_dt
-def parse_date(string_date: str) -> Tuple[int, int]:
+def parse_date(string_date: Union[str, datetime]) -> Tuple[int, int]:
"""
Parse the given date as one of the following
@@ -182,8 +182,10 @@ def parse_date(string_date: str) -> Tuple[int, int]:
:note: Date can also be YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY.
"""
if isinstance(string_date, datetime) and string_date.tzinfo:
- offset = -int(string_date.utcoffset().total_seconds())
+ offset = -int(string_date.utcoffset().total_seconds()) # type: ignore[union-attr]
return int(string_date.astimezone(utc).timestamp()), offset
+ else:
+ assert isinstance(string_date, str) # for mypy
# git time
try:
@@ -338,7 +340,7 @@ class Traversable(Protocol):
"""
# Commit and Submodule have id.__attribute__ as IterableObj
# Tree has id.__attribute__ inherited from IndexObject
- if isinstance(self, (TraversableIterableObj, Has_id_attribute)):
+ if isinstance(self, Has_id_attribute):
id = self._id_attribute_
else:
id = "" # shouldn't reach here, unless Traversable subclass created with no _id_attribute_
diff --git a/git/repo/base.py b/git/repo/base.py
index 07cf7adf..2609bf55 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -200,7 +200,6 @@ class Repo(object):
# END while curpath
if self.git_dir is None:
- self.git_dir = cast(PathLike, self.git_dir)
raise InvalidGitRepositoryError(epath)
self._bare = False
diff --git a/git/repo/fun.py b/git/repo/fun.py
index 7d5c7823..b1b330c4 100644
--- a/git/repo/fun.py
+++ b/git/repo/fun.py
@@ -1,4 +1,6 @@
"""Package with general repository related functions"""
+from git.refs.reference import Reference
+from git.types import Commit_ish
import os
import stat
from string import digits
@@ -202,7 +204,7 @@ def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']:
raise NotImplementedError("commit by message search ( regex )")
# END handle search
- obj = cast(Object, None) # not ideal. Should use guards
+ obj: Union[Commit_ish, Reference, None] = None
ref = None
output_type = "commit"
start = 0
@@ -222,14 +224,16 @@ def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']:
ref = repo.head.ref
else:
if token == '@':
- ref = name_to_object(repo, rev[:start], return_ref=True)
+ ref = cast(Reference, name_to_object(repo, rev[:start], return_ref=True))
else:
- obj = name_to_object(repo, rev[:start])
+ obj = cast(Commit_ish, name_to_object(repo, rev[:start]))
# END handle token
# END handle refname
+ else:
+ assert obj is not None
if ref is not None:
- obj = ref.commit
+ obj = cast(Commit, ref.commit)
# END handle ref
# END initialize obj on first token
@@ -247,11 +251,13 @@ def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']:
pass # default
elif output_type == 'tree':
try:
+ obj = cast(Object, obj)
obj = to_commit(obj).tree
except (AttributeError, ValueError):
pass # error raised later
# END exception handling
elif output_type in ('', 'blob'):
+ obj = cast(TagObject, obj)
if obj and obj.type == 'tag':
obj = deref_tag(obj)
else:
@@ -280,13 +286,13 @@ def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']:
obj = Object.new_from_sha(repo, hex_to_bin(entry.newhexsha))
# make it pass the following checks
- output_type = None
+ output_type = ''
else:
raise ValueError("Invalid output type: %s ( in %s )" % (output_type, rev))
# END handle output type
# empty output types don't require any specific type, its just about dereferencing tags
- if output_type and obj.type != output_type:
+ if output_type and obj and obj.type != output_type:
raise ValueError("Could not accommodate requested object type %r, got %s" % (output_type, obj.type))
# END verify output type
@@ -319,6 +325,7 @@ def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']:
parsed_to = start
# handle hierarchy walk
try:
+ obj = cast(Commit_ish, obj)
if token == "~":
obj = to_commit(obj)
for _ in range(num):
@@ -347,7 +354,7 @@ def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']:
# still no obj ? Its probably a simple name
if obj is None:
- obj = name_to_object(repo, rev)
+ obj = cast(Commit_ish, name_to_object(repo, rev))
parsed_to = lr
# END handle simple name
diff --git a/pyproject.toml b/pyproject.toml
index 12c5d961..daf45f16 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -24,7 +24,7 @@ no_implicit_optional = true
warn_redundant_casts = true
implicit_reexport = true
warn_unused_ignores = true
-# warn_unreachable = True
+warn_unreachable = true
show_error_codes = true
# TODO: remove when 'gitdb' is fully annotated