summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--git/config.py6
-rw-r--r--git/diff.py14
-rw-r--r--git/index/fun.py11
-rw-r--r--git/objects/commit.py21
-rw-r--r--git/objects/tree.py6
-rw-r--r--git/refs/reference.py2
-rw-r--r--git/refs/symbolic.py2
-rw-r--r--git/remote.py12
-rw-r--r--git/repo/base.py5
-rw-r--r--git/types.py14
10 files changed, 49 insertions, 44 deletions
diff --git a/git/config.py b/git/config.py
index 345cb40e..b25707b2 100644
--- a/git/config.py
+++ b/git/config.py
@@ -34,7 +34,7 @@ import configparser as cp
from typing import (Any, Callable, IO, List, Dict, Sequence,
TYPE_CHECKING, Tuple, Union, cast, overload)
-from git.types import Lit_config_levels, ConfigLevels_Tup, PathLike, TBD, assert_never, is_config_level
+from git.types import Lit_config_levels, ConfigLevels_Tup, PathLike, TBD, assert_never
if TYPE_CHECKING:
from git.repo.base import Repo
@@ -309,9 +309,9 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser)): #
else:
if config_level is None:
if read_only:
- self._file_or_files = [get_config_path(f)
+ self._file_or_files = [get_config_path(cast(Lit_config_levels, f))
for f in CONFIG_LEVELS
- if is_config_level(f) and f != 'repository']
+ if f != 'repository']
else:
raise ValueError("No configuration level or configuration files specified")
else:
diff --git a/git/diff.py b/git/diff.py
index 98a5cfd9..74ca0b64 100644
--- a/git/diff.py
+++ b/git/diff.py
@@ -15,8 +15,8 @@ from .objects.util import mode_str_to_int
# typing ------------------------------------------------------------------
-from typing import Any, Iterator, List, Match, Optional, Tuple, Type, TypeVar, Union, TYPE_CHECKING
-from git.types import PathLike, TBD, Literal, TypeGuard
+from typing import Any, Iterator, List, Match, Optional, Tuple, Type, TypeVar, Union, TYPE_CHECKING, cast
+from git.types import PathLike, TBD, Literal
if TYPE_CHECKING:
from .objects.tree import Tree
@@ -28,9 +28,9 @@ if TYPE_CHECKING:
Lit_change_type = Literal['A', 'D', 'C', 'M', 'R', 'T', 'U']
-def is_change_type(inp: str) -> TypeGuard[Lit_change_type]:
- # return True
- return inp in ['A', 'D', 'C', 'M', 'R', 'T', 'U']
+# def is_change_type(inp: str) -> TypeGuard[Lit_change_type]:
+# # return True
+# return inp in ['A', 'D', 'C', 'M', 'R', 'T', 'U']
# ------------------------------------------------------------------------
@@ -517,8 +517,8 @@ class Diff(object):
# Change type can be R100
# R: status letter
# 100: score (in case of copy and rename)
- assert is_change_type(_change_type[0]), f"Unexpected value for change_type received: {_change_type[0]}"
- change_type: Lit_change_type = _change_type[0]
+ # assert is_change_type(_change_type[0]), f"Unexpected value for change_type received: {_change_type[0]}"
+ change_type: Lit_change_type = cast(Lit_change_type, _change_type[0])
score_str = ''.join(_change_type[1:])
score = int(score_str) if score_str.isdigit() else None
path = path.strip()
diff --git a/git/index/fun.py b/git/index/fun.py
index e071e15c..3b963a2b 100644
--- a/git/index/fun.py
+++ b/git/index/fun.py
@@ -53,7 +53,7 @@ from .util import (
from typing import (Dict, IO, List, Sequence, TYPE_CHECKING, Tuple, Type, Union, cast)
-from git.types import PathLike, TypeGuard
+from git.types import PathLike
if TYPE_CHECKING:
from .base import IndexFile
@@ -188,15 +188,16 @@ def entry_key(*entry: Union[BaseIndexEntry, PathLike, int]) -> Tuple[PathLike, i
""":return: Key suitable to be used for the index.entries dictionary
:param entry: One instance of type BaseIndexEntry or the path and the stage"""
- def is_entry_key_tup(entry_key: Tuple) -> TypeGuard[Tuple[PathLike, int]]:
- return isinstance(entry_key, tuple) and len(entry_key) == 2
+ # def is_entry_key_tup(entry_key: Tuple) -> TypeGuard[Tuple[PathLike, int]]:
+ # return isinstance(entry_key, tuple) and len(entry_key) == 2
if len(entry) == 1:
entry_first = entry[0]
assert isinstance(entry_first, BaseIndexEntry)
return (entry_first.path, entry_first.stage)
else:
- assert is_entry_key_tup(entry)
+ # assert is_entry_key_tup(entry)
+ entry = cast(Tuple[PathLike, int], entry)
return entry
# END handle entry
@@ -244,7 +245,7 @@ def read_cache(stream: IO[bytes]) -> Tuple[int, Dict[Tuple[PathLike, int], 'Inde
content_sha = extension_data[-20:]
# truncate the sha in the end as we will dynamically create it anyway
- extension_data = extension_data[:-20]
+ extension_data = extension_data[: -20]
return (version, entries, extension_data, content_sha)
diff --git a/git/objects/commit.py b/git/objects/commit.py
index 11cf52a5..884f6522 100644
--- a/git/objects/commit.py
+++ b/git/objects/commit.py
@@ -39,9 +39,9 @@ import logging
# typing ------------------------------------------------------------------
-from typing import Any, IO, Iterator, List, Sequence, Tuple, Union, TYPE_CHECKING
+from typing import Any, IO, Iterator, List, Sequence, Tuple, Union, TYPE_CHECKING, cast
-from git.types import PathLike, TypeGuard, Literal
+from git.types import PathLike, Literal
if TYPE_CHECKING:
from git.repo import Repo
@@ -323,16 +323,18 @@ class Commit(base.Object, TraversableIterableObj, Diffable, Serializable):
:param proc: git-rev-list process instance - one sha per line
:return: iterator returning Commit objects"""
- def is_proc(inp) -> TypeGuard[Popen]:
- return hasattr(proc_or_stream, 'wait') and not hasattr(proc_or_stream, 'readline')
+ # def is_proc(inp) -> TypeGuard[Popen]:
+ # return hasattr(proc_or_stream, 'wait') and not hasattr(proc_or_stream, 'readline')
- def is_stream(inp) -> TypeGuard[IO]:
- return hasattr(proc_or_stream, 'readline')
+ # def is_stream(inp) -> TypeGuard[IO]:
+ # return hasattr(proc_or_stream, 'readline')
- if is_proc(proc_or_stream):
+ if hasattr(proc_or_stream, 'wait'):
+ proc_or_stream = cast(Popen, proc_or_stream)
if proc_or_stream.stdout is not None:
stream = proc_or_stream.stdout
- elif is_stream(proc_or_stream):
+ elif hasattr(proc_or_stream, 'readline'):
+ proc_or_stream = cast(IO, proc_or_stream)
stream = proc_or_stream
readline = stream.readline
@@ -351,7 +353,8 @@ class Commit(base.Object, TraversableIterableObj, Diffable, Serializable):
# END for each line in stream
# TODO: Review this - it seems process handling got a bit out of control
# due to many developers trying to fix the open file handles issue
- if is_proc(proc_or_stream):
+ if hasattr(proc_or_stream, 'wait'):
+ proc_or_stream = cast(Popen, proc_or_stream)
finalize_process(proc_or_stream)
@ classmethod
diff --git a/git/objects/tree.py b/git/objects/tree.py
index dd1fe783..70f36af5 100644
--- a/git/objects/tree.py
+++ b/git/objects/tree.py
@@ -24,7 +24,7 @@ from .fun import (
from typing import (Any, Callable, Dict, Iterable, Iterator, List,
Tuple, Type, Union, cast, TYPE_CHECKING)
-from git.types import PathLike, TypeGuard, Literal
+from git.types import PathLike, Literal
if TYPE_CHECKING:
from git.repo import Repo
@@ -36,8 +36,8 @@ TraversedTreeTup = Union[Tuple[Union['Tree', None], IndexObjUnion,
Tuple['Submodule', 'Submodule']]]
-def is_tree_cache(inp: Tuple[bytes, int, str]) -> TypeGuard[TreeCacheTup]:
- return isinstance(inp[0], bytes) and isinstance(inp[1], int) and isinstance([inp], str)
+# def is_tree_cache(inp: Tuple[bytes, int, str]) -> TypeGuard[TreeCacheTup]:
+# return isinstance(inp[0], bytes) and isinstance(inp[1], int) and isinstance([inp], str)
#--------------------------------------------------------
diff --git a/git/refs/reference.py b/git/refs/reference.py
index f584bb54..64662281 100644
--- a/git/refs/reference.py
+++ b/git/refs/reference.py
@@ -8,7 +8,7 @@ from .symbolic import SymbolicReference, T_References
# typing ------------------------------------------------------------------
from typing import Any, Callable, Iterator, List, Match, Optional, Tuple, Type, TypeVar, Union, TYPE_CHECKING # NOQA
-from git.types import Commit_ish, PathLike, TBD, Literal, TypeGuard, _T # NOQA
+from git.types import Commit_ish, PathLike, TBD, Literal, _T # NOQA
if TYPE_CHECKING:
from git.repo import Repo
diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py
index 426d40d4..0e9dad5c 100644
--- a/git/refs/symbolic.py
+++ b/git/refs/symbolic.py
@@ -24,7 +24,7 @@ from .log import RefLog
# typing ------------------------------------------------------------------
from typing import Any, Iterator, List, Match, Optional, Tuple, Type, TypeVar, Union, TYPE_CHECKING # NOQA
-from git.types import Commit_ish, PathLike, TBD, Literal, TypeGuard # NOQA
+from git.types import Commit_ish, PathLike, TBD, Literal # NOQA
if TYPE_CHECKING:
from git.repo import Repo
diff --git a/git/remote.py b/git/remote.py
index d903552f..7da466e6 100644
--- a/git/remote.py
+++ b/git/remote.py
@@ -37,9 +37,9 @@ from .refs import (
# typing-------------------------------------------------------
from typing import (Any, Callable, Dict, Iterator, List, NoReturn, Optional, Sequence, # NOQA[TC002]
- TYPE_CHECKING, Type, Union, overload)
+ TYPE_CHECKING, Type, Union, cast, overload)
-from git.types import PathLike, Literal, TBD, TypeGuard, Commit_ish # NOQA[TC002]
+from git.types import PathLike, Literal, TBD, Commit_ish # NOQA[TC002]
if TYPE_CHECKING:
from git.repo.base import Repo
@@ -50,8 +50,8 @@ if TYPE_CHECKING:
flagKeyLiteral = Literal[' ', '!', '+', '-', '*', '=', 't', '?']
-def is_flagKeyLiteral(inp: str) -> TypeGuard[flagKeyLiteral]:
- return inp in [' ', '!', '+', '-', '=', '*', 't', '?']
+# def is_flagKeyLiteral(inp: str) -> TypeGuard[flagKeyLiteral]:
+# return inp in [' ', '!', '+', '-', '=', '*', 't', '?']
# -------------------------------------------------------------
@@ -342,8 +342,8 @@ class FetchInfo(IterableObj, object):
# parse lines
remote_local_ref_str: str
control_character, operation, local_remote_ref, remote_local_ref_str, note = match.groups()
- assert is_flagKeyLiteral(control_character), f"{control_character}"
-
+ # assert is_flagKeyLiteral(control_character), f"{control_character}"
+ control_character = cast(flagKeyLiteral, control_character)
try:
_new_hex_sha, _fetch_operation, fetch_note = fetch_line.split("\t")
ref_type_name, fetch_note = fetch_note.split(' ', 1)
diff --git a/git/repo/base.py b/git/repo/base.py
index 64f32bd3..03851756 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -36,7 +36,7 @@ import gitdb
# typing ------------------------------------------------------
-from git.types import TBD, PathLike, Lit_config_levels, Commit_ish, Tree_ish, is_config_level
+from git.types import TBD, PathLike, Lit_config_levels, Commit_ish, Tree_ish
from typing import (Any, BinaryIO, Callable, Dict,
Iterator, List, Mapping, Optional, Sequence,
TextIO, Tuple, Type, Union,
@@ -498,7 +498,8 @@ class Repo(object):
unknown, instead the global path will be used."""
files = None
if config_level is None:
- files = [self._get_config_path(f) for f in self.config_level if is_config_level(f)]
+ files = [self._get_config_path(cast(Lit_config_levels, f))
+ for f in self.config_level if cast(Lit_config_levels, f)]
else:
files = [self._get_config_path(config_level)]
return GitConfigParser(files, read_only=True, repo=self)
diff --git a/git/types.py b/git/types.py
index 53f0f1e4..05c5b345 100644
--- a/git/types.py
+++ b/git/types.py
@@ -12,10 +12,10 @@ if sys.version_info[:2] >= (3, 8):
else:
from typing_extensions import Final, Literal, SupportsIndex, TypedDict, Protocol, runtime_checkable # noqa: F401
-if sys.version_info[:2] >= (3, 10):
- from typing import TypeGuard # noqa: F401
-else:
- from typing_extensions import TypeGuard # noqa: F401
+# if sys.version_info[:2] >= (3, 10):
+# from typing import TypeGuard # noqa: F401
+# else:
+# from typing_extensions import TypeGuard # noqa: F401
if sys.version_info[:2] < (3, 9):
@@ -41,9 +41,9 @@ Lit_commit_ish = Literal['commit', 'tag', 'blob', 'tree']
Lit_config_levels = Literal['system', 'global', 'user', 'repository']
-def is_config_level(inp: str) -> TypeGuard[Lit_config_levels]:
- # return inp in get_args(Lit_config_level) # only py >= 3.8
- return inp in ("system", "user", "global", "repository")
+# def is_config_level(inp: str) -> TypeGuard[Lit_config_levels]:
+# # return inp in get_args(Lit_config_level) # only py >= 3.8
+# return inp in ("system", "user", "global", "repository")
ConfigLevels_Tup = Tuple[Literal['system'], Literal['user'], Literal['global'], Literal['repository']]