| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,7 @@ | |||
| 16 | 16 | # typing ------------------------------------------------------------------ | |
| 17 | 17 | ||
| 18 | 18 | from typing import Any, Iterator, List, Match, Optional, Tuple, Type, Union, TYPE_CHECKING, cast | |
| 19 | - from git.types import PathLike, TBD, Literal | ||
| 19 | + from git.types import PathLike, TBD, Literal, TypeGuard | ||
| 20 | 20 | ||
| 21 | 21 | if TYPE_CHECKING: | |
| 22 | 22 | from .objects.tree import Tree | |
@@ -26,8 +26,13 @@ | |||
| 26 | 26 | ||
| 27 | 27 | Lit_change_type = Literal['A', 'D', 'C', 'M', 'R', 'T'] | |
| 28 | 28 | ||
| 29 | + | ||
| 30 | + def is_change_type(inp: str) -> TypeGuard[Lit_change_type]: | ||
| 31 | + return inp in ['A', 'D', 'C', 'M', 'R', 'T'] | ||
| 32 | + | ||
| 29 | 33 | # ------------------------------------------------------------------------ | |
| 30 | 34 | ||
| 35 | + | ||
| 31 | 36 | __all__ = ('Diffable', 'DiffIndex', 'Diff', 'NULL_TREE') | |
| 32 | 37 | ||
| 33 | 38 | # Special object to compare against the empty tree in diffs | |
@@ -202,6 +207,7 @@ def iter_change_type(self, change_type: Lit_change_type) -> Iterator['Diff']: | |||
| 202 | 207 | ||
| 203 | 208 | for diff in self: | |
| 204 | 209 | diff = cast('Diff', diff) | |
| 210 | + | ||
| 205 | 211 | if diff.change_type == change_type: | |
| 206 | 212 | yield diff | |
| 207 | 213 | elif change_type == "A" and diff.new_file: | |
@@ -505,7 +511,8 @@ def _handle_diff_line(lines_bytes: bytes, repo: 'Repo', index: DiffIndex) -> Non | |||
| 505 | 511 | # Change type can be R100 | |
| 506 | 512 | # R: status letter | |
| 507 | 513 | # 100: score (in case of copy and rename) | |
| 508 | - change_type: Lit_change_type = _change_type[0] # type: ignore | ||
| 514 | + assert is_change_type(_change_type[0]) | ||
| 515 | + change_type: Lit_change_type = _change_type[0] | ||
| 509 | 516 | score_str = ''.join(_change_type[1:]) | |
| 510 | 517 | score = int(score_str) if score_str.isdigit() else None | |
| 511 | 518 | path = path.strip() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments