Skip to content

Commit 8d2a770

Browse files
committed
Rmv diff typeguard
1 parent c0ab23e commit 8d2a770

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

git/diff.py

+10-18
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,19 @@
1515

1616
# typing ------------------------------------------------------------------
1717

18-
from typing import Any, Iterator, List, Match, Optional, Tuple, Type, Union, TYPE_CHECKING
19-
from git.types import PathLike, TBD, Literal, TypeGuard
18+
from typing import Any, Iterator, List, Match, Optional, Tuple, Type, Union, TYPE_CHECKING, cast
19+
from git.types import PathLike, TBD, Literal
2020

2121
if TYPE_CHECKING:
2222
from .objects.tree import Tree
2323
from git.repo.base import Repo
2424

2525
from subprocess import Popen
2626

27-
Lit_change_type = Literal['A', 'C', 'D', 'M', 'R', 'T']
28-
29-
30-
def is_change_type(inp: str) -> TypeGuard[Lit_change_type]:
31-
return inp in ('A', 'D', 'C', 'M', 'R', 'T')
27+
Lit_change_type = Literal['A', 'D', 'C', 'M', 'R', 'T']
3228

3329
# ------------------------------------------------------------------------
3430

35-
3631
__all__ = ('Diffable', 'DiffIndex', 'Diff', 'NULL_TREE')
3732

3833
# Special object to compare against the empty tree in diffs
@@ -205,8 +200,8 @@ def iter_change_type(self, change_type: Lit_change_type) -> Iterator['Diff']:
205200
if change_type not in self.change_type:
206201
raise ValueError("Invalid change type: %s" % change_type)
207202

208-
# diff: 'Diff'
209203
for diff in self:
204+
diff = cast('Diff', diff)
210205
if diff.change_type == change_type:
211206
yield diff
212207
elif change_type == "A" and diff.new_file:
@@ -287,8 +282,7 @@ def __init__(self, repo: 'Repo',
287282
a_mode: Union[bytes, str, None], b_mode: Union[bytes, str, None],
288283
new_file: bool, deleted_file: bool, copied_file: bool,
289284
raw_rename_from: Optional[bytes], raw_rename_to: Optional[bytes],
290-
diff: Union[str, bytes, None], change_type: Union[Lit_change_type, None],
291-
score: Optional[int]) -> None:
285+
diff: Union[str, bytes, None], change_type: Optional[str], score: Optional[int]) -> None:
292286

293287
assert a_rawpath is None or isinstance(a_rawpath, bytes)
294288
assert b_rawpath is None or isinstance(b_rawpath, bytes)
@@ -505,15 +499,13 @@ def _handle_diff_line(lines_bytes: bytes, repo: 'Repo', index: DiffIndex) -> Non
505499
for line in lines.split(':')[1:]:
506500
meta, _, path = line.partition('\x00')
507501
path = path.rstrip('\x00')
508-
a_blob_id: Union[str, None]
509-
b_blob_id: Union[str, None]
502+
a_blob_id: Optional[str]
503+
b_blob_id: Optional[str]
510504
old_mode, new_mode, a_blob_id, b_blob_id, _change_type = meta.split(None, 4)
511-
# _Change_type can be R100
505+
# Change type can be R100
512506
# R: status letter
513507
# 100: score (in case of copy and rename)
514-
515-
assert is_change_type(_change_type[0]), "Unexpected _change_type recieved in Diff"
516-
change_type: Lit_change_type = _change_type[0]
508+
change_type: Lit_change_type = _change_type[0] # type: ignore
517509
score_str = ''.join(_change_type[1:])
518510
score = int(score_str) if score_str.isdigit() else None
519511
path = path.strip()
@@ -528,7 +520,7 @@ def _handle_diff_line(lines_bytes: bytes, repo: 'Repo', index: DiffIndex) -> Non
528520
# NOTE: We cannot conclude from the existence of a blob to change type
529521
# as diffs with the working do not have blobs yet
530522
if change_type == 'D':
531-
b_blob_id = None
523+
b_blob_id = None # Optional[str]
532524
deleted_file = True
533525
elif change_type == 'A':
534526
a_blob_id = None

git/objects/submodule/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No
391391
if sm.exists():
392392
# reretrieve submodule from tree
393393
try:
394-
sm = repo.head.commit.tree[path] # type: ignore
394+
sm = repo.head.commit.tree[path] # type: ignore
395395
sm._name = name
396396
return sm
397397
except KeyError:

0 commit comments

Comments
 (0)