Skip to content

Commit 2a6a2e2

Browse files
committed
Improve types of diff.py
1 parent fb09bfa commit 2a6a2e2

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

git/diff.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@
2626

2727
Lit_change_type = Literal['A', 'D', 'M', 'R', 'T']
2828

29+
30+
def is_change_type(inp: str) -> TypeGuard[Lit_change_type]:
31+
return inp in Lit_change_type.__args__ # type: ignore
32+
2933
# ------------------------------------------------------------------------
3034

35+
3136
__all__ = ('Diffable', 'DiffIndex', 'Diff', 'NULL_TREE')
3237

3338
# Special object to compare against the empty tree in diffs
@@ -503,13 +508,10 @@ def _handle_diff_line(lines_bytes: bytes, repo: 'Repo', index: DiffIndex) -> Non
503508
a_blob_id: Union[str, None]
504509
b_blob_id: Union[str, None]
505510
old_mode, new_mode, a_blob_id, b_blob_id, _change_type = meta.split(None, 4)
506-
# Change type can be R100
511+
# _Change_type can be R100
507512
# R: status letter
508513
# 100: score (in case of copy and rename)
509514

510-
def is_change_type(inp: str) -> TypeGuard[Lit_change_type]:
511-
return inp in Lit_change_type.__args__ # type: ignore
512-
513515
assert is_change_type(_change_type[0])
514516
change_type: Lit_change_type = _change_type[0]
515517
score_str = ''.join(_change_type[1:])

git/objects/submodule/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
find_first_remote_branch
4848
)
4949

50+
from git.repo import Repo
5051

5152
# typing ----------------------------------------------------------------------
5253
from typing import Callable, Dict, Mapping, Sequence, TYPE_CHECKING
@@ -55,7 +56,6 @@
5556
from git.types import Commit_ish, PathLike, TBD
5657

5758
if TYPE_CHECKING:
58-
from git.repo import Repo
5959
from git.index import IndexFile
6060

6161

0 commit comments

Comments
 (0)