From fb09bfacd449ac7b5d2f20b9dbe123d61d004cde Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 14:39:28 +0100 Subject: Improve types of diff.py --- git/diff.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'git/diff.py') diff --git a/git/diff.py b/git/diff.py index 346a2ca7..21b66640 100644 --- a/git/diff.py +++ b/git/diff.py @@ -16,7 +16,7 @@ from .objects.util import mode_str_to_int # typing ------------------------------------------------------------------ from typing import Any, Iterator, List, Match, Optional, Tuple, Type, Union, TYPE_CHECKING -from git.types import PathLike, TBD, Literal +from git.types import PathLike, TBD, Literal, TypeGuard if TYPE_CHECKING: from .objects.tree import Tree @@ -200,7 +200,8 @@ class DiffIndex(list): if change_type not in self.change_type: raise ValueError("Invalid change type: %s" % change_type) - for diff in self: # type: 'Diff' + # diff: 'Diff' + for diff in self: if diff.change_type == change_type: yield diff elif change_type == "A" and diff.new_file: @@ -281,7 +282,8 @@ class Diff(object): a_mode: Union[bytes, str, None], b_mode: Union[bytes, str, None], new_file: bool, deleted_file: bool, copied_file: bool, raw_rename_from: Optional[bytes], raw_rename_to: Optional[bytes], - diff: Union[str, bytes, None], change_type: Optional[str], score: Optional[int]) -> None: + diff: Union[str, bytes, None], change_type: Union[Lit_change_type, None], + score: Optional[int]) -> None: assert a_rawpath is None or isinstance(a_rawpath, bytes) assert b_rawpath is None or isinstance(b_rawpath, bytes) @@ -498,12 +500,18 @@ class Diff(object): for line in lines.split(':')[1:]: meta, _, path = line.partition('\x00') path = path.rstrip('\x00') - a_blob_id, b_blob_id = None, None # Type: Optional[str] + a_blob_id: Union[str, None] + b_blob_id: Union[str, None] old_mode, new_mode, a_blob_id, b_blob_id, _change_type = meta.split(None, 4) # Change type can be R100 # R: status letter # 100: score (in case of copy and rename) - change_type = _change_type[0] + + def is_change_type(inp: str) -> TypeGuard[Lit_change_type]: + return inp in Lit_change_type.__args__ # type: ignore + + assert is_change_type(_change_type[0]) + change_type: 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() @@ -518,7 +526,7 @@ class Diff(object): # NOTE: We cannot conclude from the existence of a blob to change type # as diffs with the working do not have blobs yet if change_type == 'D': - b_blob_id = None # Optional[str] + b_blob_id = None deleted_file = True elif change_type == 'A': a_blob_id = None -- cgit v1.2.1 From 2a6a2e2e44b6220f4cbc7d1672e0cfb1c13926c2 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 14:45:30 +0100 Subject: Improve types of diff.py --- git/diff.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'git/diff.py') diff --git a/git/diff.py b/git/diff.py index 21b66640..f07bd93a 100644 --- a/git/diff.py +++ b/git/diff.py @@ -26,8 +26,13 @@ if TYPE_CHECKING: Lit_change_type = Literal['A', 'D', 'M', 'R', 'T'] + +def is_change_type(inp: str) -> TypeGuard[Lit_change_type]: + return inp in Lit_change_type.__args__ # type: ignore + # ------------------------------------------------------------------------ + __all__ = ('Diffable', 'DiffIndex', 'Diff', 'NULL_TREE') # Special object to compare against the empty tree in diffs @@ -503,13 +508,10 @@ class Diff(object): a_blob_id: Union[str, None] b_blob_id: Union[str, None] old_mode, new_mode, a_blob_id, b_blob_id, _change_type = meta.split(None, 4) - # Change type can be R100 + # _Change_type can be R100 # R: status letter # 100: score (in case of copy and rename) - def is_change_type(inp: str) -> TypeGuard[Lit_change_type]: - return inp in Lit_change_type.__args__ # type: ignore - assert is_change_type(_change_type[0]) change_type: Lit_change_type = _change_type[0] score_str = ''.join(_change_type[1:]) -- cgit v1.2.1 From 1bcccd55e78d1412903c2af59ccc895cca85e153 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 15:01:15 +0100 Subject: Fix Literal Typeguards --- git/diff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/diff.py') diff --git a/git/diff.py b/git/diff.py index f07bd93a..611194a8 100644 --- a/git/diff.py +++ b/git/diff.py @@ -28,7 +28,7 @@ Lit_change_type = Literal['A', 'D', 'M', 'R', 'T'] def is_change_type(inp: str) -> TypeGuard[Lit_change_type]: - return inp in Lit_change_type.__args__ # type: ignore + return inp in ('A', 'D', 'M', 'R', 'T') # ------------------------------------------------------------------------ -- cgit v1.2.1 From deafa6a0ab837dffb8f78177f7c22d21ac65bf62 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 15:40:06 +0100 Subject: Fix for mrepo2 --- git/diff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/diff.py') diff --git a/git/diff.py b/git/diff.py index 611194a8..c5e231b2 100644 --- a/git/diff.py +++ b/git/diff.py @@ -512,7 +512,7 @@ class Diff(object): # R: status letter # 100: score (in case of copy and rename) - assert is_change_type(_change_type[0]) + assert is_change_type(_change_type[0]), "Unexpected _change_type recieved in Diff" change_type: Lit_change_type = _change_type[0] score_str = ''.join(_change_type[1:]) score = int(score_str) if score_str.isdigit() else None -- cgit v1.2.1 From c0ab23e5d0afce4a85a8af7ec2a360bf6c71c4ac Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 16:04:06 +0100 Subject: Rmv submodule types2 --- git/diff.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'git/diff.py') diff --git a/git/diff.py b/git/diff.py index c5e231b2..ac744999 100644 --- a/git/diff.py +++ b/git/diff.py @@ -24,11 +24,11 @@ if TYPE_CHECKING: from subprocess import Popen -Lit_change_type = Literal['A', 'D', 'M', 'R', 'T'] +Lit_change_type = Literal['A', 'C', 'D', 'M', 'R', 'T'] def is_change_type(inp: str) -> TypeGuard[Lit_change_type]: - return inp in ('A', 'D', 'M', 'R', 'T') + return inp in ('A', 'D', 'C', 'M', 'R', 'T') # ------------------------------------------------------------------------ -- cgit v1.2.1 From 8d2a7703259967f0438a18b5cbc80ee060e15866 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 16:16:35 +0100 Subject: Rmv diff typeguard --- git/diff.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'git/diff.py') diff --git a/git/diff.py b/git/diff.py index ac744999..879d5b55 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, Union, TYPE_CHECKING -from git.types import PathLike, TBD, Literal, TypeGuard +from typing import Any, Iterator, List, Match, Optional, Tuple, Type, Union, TYPE_CHECKING, cast +from git.types import PathLike, TBD, Literal if TYPE_CHECKING: from .objects.tree import Tree @@ -24,15 +24,10 @@ if TYPE_CHECKING: from subprocess import Popen -Lit_change_type = Literal['A', 'C', 'D', 'M', 'R', 'T'] - - -def is_change_type(inp: str) -> TypeGuard[Lit_change_type]: - return inp in ('A', 'D', 'C', 'M', 'R', 'T') +Lit_change_type = Literal['A', 'D', 'C', 'M', 'R', 'T'] # ------------------------------------------------------------------------ - __all__ = ('Diffable', 'DiffIndex', 'Diff', 'NULL_TREE') # Special object to compare against the empty tree in diffs @@ -205,8 +200,8 @@ class DiffIndex(list): if change_type not in self.change_type: raise ValueError("Invalid change type: %s" % change_type) - # diff: 'Diff' for diff in self: + diff = cast('Diff', diff) if diff.change_type == change_type: yield diff elif change_type == "A" and diff.new_file: @@ -287,8 +282,7 @@ class Diff(object): a_mode: Union[bytes, str, None], b_mode: Union[bytes, str, None], new_file: bool, deleted_file: bool, copied_file: bool, raw_rename_from: Optional[bytes], raw_rename_to: Optional[bytes], - diff: Union[str, bytes, None], change_type: Union[Lit_change_type, None], - score: Optional[int]) -> None: + diff: Union[str, bytes, None], change_type: Optional[str], score: Optional[int]) -> None: assert a_rawpath is None or isinstance(a_rawpath, bytes) assert b_rawpath is None or isinstance(b_rawpath, bytes) @@ -505,15 +499,13 @@ class Diff(object): for line in lines.split(':')[1:]: meta, _, path = line.partition('\x00') path = path.rstrip('\x00') - a_blob_id: Union[str, None] - b_blob_id: Union[str, None] + a_blob_id: Optional[str] + b_blob_id: Optional[str] old_mode, new_mode, a_blob_id, b_blob_id, _change_type = meta.split(None, 4) - # _Change_type can be R100 + # Change type can be R100 # R: status letter # 100: score (in case of copy and rename) - - assert is_change_type(_change_type[0]), "Unexpected _change_type recieved in Diff" - change_type: Lit_change_type = _change_type[0] + change_type: Lit_change_type = _change_type[0] # type: ignore score_str = ''.join(_change_type[1:]) score = int(score_str) if score_str.isdigit() else None path = path.strip() @@ -528,7 +520,7 @@ class Diff(object): # NOTE: We cannot conclude from the existence of a blob to change type # as diffs with the working do not have blobs yet if change_type == 'D': - b_blob_id = None + b_blob_id = None # Optional[str] deleted_file = True elif change_type == 'A': a_blob_id = None -- cgit v1.2.1 From 215abfda39c34aa125f9405d9bb848eb45ee7ac6 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 16:36:16 +0100 Subject: Readd typeguard to Diff.py --- git/diff.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'git/diff.py') diff --git a/git/diff.py b/git/diff.py index 879d5b55..a90b7758 100644 --- a/git/diff.py +++ b/git/diff.py @@ -16,7 +16,7 @@ from .objects.util import mode_str_to_int # typing ------------------------------------------------------------------ from typing import Any, Iterator, List, Match, Optional, Tuple, Type, Union, TYPE_CHECKING, cast -from git.types import PathLike, TBD, Literal +from git.types import PathLike, TBD, Literal, TypeGuard if TYPE_CHECKING: from .objects.tree import Tree @@ -26,8 +26,13 @@ if TYPE_CHECKING: Lit_change_type = Literal['A', 'D', 'C', 'M', 'R', 'T'] + +def is_change_type(inp: str) -> TypeGuard[Lit_change_type]: + return inp in ['A', 'D', 'C', 'M', 'R', 'T'] + # ------------------------------------------------------------------------ + __all__ = ('Diffable', 'DiffIndex', 'Diff', 'NULL_TREE') # Special object to compare against the empty tree in diffs @@ -202,6 +207,7 @@ class DiffIndex(list): for diff in self: diff = cast('Diff', diff) + if diff.change_type == change_type: yield diff elif change_type == "A" and diff.new_file: @@ -505,7 +511,8 @@ class Diff(object): # Change type can be R100 # R: status letter # 100: score (in case of copy and rename) - change_type: Lit_change_type = _change_type[0] # type: ignore + assert is_change_type(_change_type[0]) + change_type: 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() -- cgit v1.2.1 From 94c2ae405ba635e801ff7a1ea00300e51f3a70db Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 16:41:14 +0100 Subject: Readd submodule.base.py types --- git/diff.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'git/diff.py') diff --git a/git/diff.py b/git/diff.py index a90b7758..7de4276a 100644 --- a/git/diff.py +++ b/git/diff.py @@ -28,7 +28,8 @@ Lit_change_type = Literal['A', 'D', 'C', 'M', 'R', 'T'] def is_change_type(inp: str) -> TypeGuard[Lit_change_type]: - return inp in ['A', 'D', 'C', 'M', 'R', 'T'] + return True + # return inp in ['A', 'D', 'C', 'M', 'R', 'T'] # ------------------------------------------------------------------------ @@ -511,7 +512,7 @@ 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]) + 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] score_str = ''.join(_change_type[1:]) score = int(score_str) if score_str.isdigit() else None -- cgit v1.2.1 From 1d0e666ebfdbe7eeb80b3d859f7e3823d36256e3 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 17:19:02 +0100 Subject: Check change_levels (should fail) --- git/diff.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'git/diff.py') diff --git a/git/diff.py b/git/diff.py index 7de4276a..14f823a1 100644 --- a/git/diff.py +++ b/git/diff.py @@ -28,8 +28,8 @@ Lit_change_type = Literal['A', 'D', 'C', 'M', 'R', 'T'] def is_change_type(inp: str) -> TypeGuard[Lit_change_type]: - return True - # return inp in ['A', 'D', 'C', 'M', 'R', 'T'] + # return True + return inp in ['A', 'D', 'C', 'M', 'R', 'T'] # ------------------------------------------------------------------------ -- cgit v1.2.1 From e9858513addf8a4ee69890d46f58c5ef2528a6ab Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 17:22:37 +0100 Subject: Add 'U' to change_levels (should pass) --- git/diff.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'git/diff.py') diff --git a/git/diff.py b/git/diff.py index 14f823a1..6c34a871 100644 --- a/git/diff.py +++ b/git/diff.py @@ -24,12 +24,12 @@ if TYPE_CHECKING: from subprocess import Popen -Lit_change_type = Literal['A', 'D', 'C', 'M', 'R', 'T'] +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'] + return inp in ['A', 'D', 'C', 'M', 'R', 'T', 'U'] # ------------------------------------------------------------------------ -- cgit v1.2.1 From 873ebe61431c50bb39afd5cafff498b3e1879342 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 17:56:24 +0100 Subject: Make diff.DiffIndex generic List['Diff'] --- git/diff.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'git/diff.py') diff --git a/git/diff.py b/git/diff.py index 6c34a871..d3b18652 100644 --- a/git/diff.py +++ b/git/diff.py @@ -15,12 +15,13 @@ from .objects.util import mode_str_to_int # typing ------------------------------------------------------------------ -from typing import Any, Iterator, List, Match, Optional, Tuple, Type, Union, TYPE_CHECKING, cast +from typing import Any, Iterator, List, Match, Optional, Tuple, Type, TypeVar, Union, TYPE_CHECKING from git.types import PathLike, TBD, Literal, TypeGuard if TYPE_CHECKING: from .objects.tree import Tree from git.repo.base import Repo + from git.objects.base import IndexObject from subprocess import Popen @@ -175,7 +176,10 @@ class Diffable(object): return index -class DiffIndex(list): +T_Diff = TypeVar('T_Diff', bound='Diff') + + +class DiffIndex(List[T_Diff]): """Implements an Index for diffs, allowing a list of Diffs to be queried by the diff properties. @@ -189,7 +193,7 @@ class DiffIndex(list): # T = Changed in the type change_type = ("A", "C", "D", "R", "M", "T") - def iter_change_type(self, change_type: Lit_change_type) -> Iterator['Diff']: + def iter_change_type(self, change_type: Lit_change_type) -> Iterator[T_Diff]: """ :return: iterator yielding Diff instances that match the given change_type @@ -207,8 +211,6 @@ class DiffIndex(list): raise ValueError("Invalid change type: %s" % change_type) for diff in self: - diff = cast('Diff', diff) - if diff.change_type == change_type: yield diff elif change_type == "A" and diff.new_file: @@ -289,7 +291,7 @@ class Diff(object): a_mode: Union[bytes, str, None], b_mode: Union[bytes, str, None], new_file: bool, deleted_file: bool, copied_file: bool, raw_rename_from: Optional[bytes], raw_rename_to: Optional[bytes], - diff: Union[str, bytes, None], change_type: Optional[str], score: Optional[int]) -> None: + diff: Union[str, bytes, None], change_type: Optional[Lit_change_type], score: Optional[int]) -> None: assert a_rawpath is None or isinstance(a_rawpath, bytes) assert b_rawpath is None or isinstance(b_rawpath, bytes) @@ -308,19 +310,21 @@ class Diff(object): repo = submodule.module() break + self.a_blob: Union['IndexObject', None] if a_blob_id is None or a_blob_id == self.NULL_HEX_SHA: self.a_blob = None else: self.a_blob = Blob(repo, hex_to_bin(a_blob_id), mode=self.a_mode, path=self.a_path) + self.b_blob: Union['IndexObject', None] if b_blob_id is None or b_blob_id == self.NULL_HEX_SHA: self.b_blob = None else: self.b_blob = Blob(repo, hex_to_bin(b_blob_id), mode=self.b_mode, path=self.b_path) - self.new_file = new_file - self.deleted_file = deleted_file - self.copied_file = copied_file + self.new_file: bool = new_file + self.deleted_file: bool = deleted_file + self.copied_file: bool = copied_file # be clear and use None instead of empty strings assert raw_rename_from is None or isinstance(raw_rename_from, bytes) @@ -329,7 +333,7 @@ class Diff(object): self.raw_rename_to = raw_rename_to or None self.diff = diff - self.change_type = change_type + self.change_type: Union[Lit_change_type, None] = change_type self.score = score def __eq__(self, other: object) -> bool: @@ -449,7 +453,7 @@ class Diff(object): # for now, we have to bake the stream text = b''.join(text_list) - index = DiffIndex() + index: 'DiffIndex' = DiffIndex() previous_header = None header = None a_path, b_path = None, None # for mypy @@ -560,7 +564,7 @@ class Diff(object): # handles # :100644 100644 687099101... 37c5e30c8... M .gitignore - index = DiffIndex() + index: 'DiffIndex' = DiffIndex() handle_process_output(proc, lambda byt: cls._handle_diff_line(byt, repo, index), None, finalize_process, decode_streams=False) -- cgit v1.2.1 From 937746291cfdaa40938de03db305b1137c391907 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Fri, 9 Jul 2021 11:40:32 +0100 Subject: Make has_repo protocol runtime checkable and use in Diffable --- git/diff.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'git/diff.py') diff --git a/git/diff.py b/git/diff.py index d3b18652..cb216299 100644 --- a/git/diff.py +++ b/git/diff.py @@ -16,7 +16,7 @@ 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 git.types import Has_Repo, PathLike, TBD, Literal, TypeGuard if TYPE_CHECKING: from .objects.tree import Tree @@ -141,8 +141,10 @@ class Diffable(object): if paths is not None and not isinstance(paths, (tuple, list)): paths = [paths] - if hasattr(self, 'repo'): # else raise Error? - self.repo = self.repo # type: 'Repo' + if isinstance(self, Has_Repo): + self.repo: Repo = self.repo + else: + raise AttributeError("No repo member found, cannot create DiffIndex") diff_cmd = self.repo.git.diff if other is self.Index: -- cgit v1.2.1 From 7c6ae2b94cfd1593c12366b6abc0cd5bbb6e07b2 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Fri, 9 Jul 2021 15:07:50 +0100 Subject: Try to distinguation git.diff module from diff.Diff.diff and diff.Daffable.diff() --- git/diff.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'git/diff.py') diff --git a/git/diff.py b/git/diff.py index cb216299..71bbdf75 100644 --- a/git/diff.py +++ b/git/diff.py @@ -212,19 +212,19 @@ class DiffIndex(List[T_Diff]): if change_type not in self.change_type: raise ValueError("Invalid change type: %s" % change_type) - for diff in self: - if diff.change_type == change_type: - yield diff - elif change_type == "A" and diff.new_file: - yield diff - elif change_type == "D" and diff.deleted_file: - yield diff - elif change_type == "C" and diff.copied_file: - yield diff - elif change_type == "R" and diff.renamed: - yield diff - elif change_type == "M" and diff.a_blob and diff.b_blob and diff.a_blob != diff.b_blob: - yield diff + for diffidx in self: + if diffidx.change_type == change_type: + yield diffidx + elif change_type == "A" and diffidx.new_file: + yield diffidx + elif change_type == "D" and diffidx.deleted_file: + yield diffidx + elif change_type == "C" and diffidx.copied_file: + yield diffidx + elif change_type == "R" and diffidx.renamed: + yield diffidx + elif change_type == "M" and diffidx.a_blob and diffidx.b_blob and diffidx.a_blob != diffidx.b_blob: + yield diffidx # END for each diff -- cgit v1.2.1 From f916c148ea956655837a98817778abe685bf7ee7 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Fri, 9 Jul 2021 15:40:14 +0100 Subject: Improve Diffable method typing --- git/diff.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'git/diff.py') diff --git a/git/diff.py b/git/diff.py index 71bbdf75..4024776d 100644 --- a/git/diff.py +++ b/git/diff.py @@ -16,13 +16,12 @@ 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 Has_Repo, PathLike, TBD, Literal, TypeGuard +from git.types import PathLike, TBD, Literal, TypeGuard if TYPE_CHECKING: from .objects.tree import Tree from git.repo.base import Repo from git.objects.base import IndexObject - from subprocess import Popen Lit_change_type = Literal['A', 'D', 'C', 'M', 'R', 'T', 'U'] @@ -82,7 +81,8 @@ class Diffable(object): class Index(object): pass - def _process_diff_args(self, args: List[Union[str, 'Diffable', object]]) -> List[Union[str, 'Diffable', object]]: + def _process_diff_args(self, args: List[Union[PathLike, 'Diffable', Type['Diffable.Index']]] + ) -> List[Union[PathLike, 'Diffable', Type['Diffable.Index']]]: """ :return: possibly altered version of the given args list. @@ -90,7 +90,7 @@ class Diffable(object): Subclasses can use it to alter the behaviour of the superclass""" return args - def diff(self, other: Union[Type[Index], Type['Tree'], object, None, str] = Index, + def diff(self, other: Union[Type['Index'], 'Tree', None, str] = Index, paths: Union[PathLike, List[PathLike], Tuple[PathLike, ...], None] = None, create_patch: bool = False, **kwargs: Any) -> 'DiffIndex': """Creates diffs between two items being trees, trees and index or an @@ -123,7 +123,7 @@ class Diffable(object): :note: On a bare repository, 'other' needs to be provided as Index or as as Tree/Commit, or a git command error will occur""" - args = [] # type: List[Union[str, Diffable, object]] + args: List[Union[PathLike, Diffable, Type['Diffable.Index']]] = [] args.append("--abbrev=40") # we need full shas args.append("--full-index") # get full index paths, not only filenames @@ -141,7 +141,7 @@ class Diffable(object): if paths is not None and not isinstance(paths, (tuple, list)): paths = [paths] - if isinstance(self, Has_Repo): + if hasattr(self, 'Has_Repo'): self.repo: Repo = self.repo else: raise AttributeError("No repo member found, cannot create DiffIndex") @@ -400,36 +400,36 @@ class Diff(object): # end return res - @property + @ property def a_path(self) -> Optional[str]: return self.a_rawpath.decode(defenc, 'replace') if self.a_rawpath else None - @property + @ property def b_path(self) -> Optional[str]: return self.b_rawpath.decode(defenc, 'replace') if self.b_rawpath else None - @property + @ property def rename_from(self) -> Optional[str]: return self.raw_rename_from.decode(defenc, 'replace') if self.raw_rename_from else None - @property + @ property def rename_to(self) -> Optional[str]: return self.raw_rename_to.decode(defenc, 'replace') if self.raw_rename_to else None - @property + @ property def renamed(self) -> bool: """:returns: True if the blob of our diff has been renamed :note: This property is deprecated, please use ``renamed_file`` instead. """ return self.renamed_file - @property + @ property def renamed_file(self) -> bool: """:returns: True if the blob of our diff has been renamed """ return self.rename_from != self.rename_to - @classmethod + @ classmethod def _pick_best_path(cls, path_match: bytes, rename_match: bytes, path_fallback_match: bytes) -> Optional[bytes]: if path_match: return decode_path(path_match) @@ -442,7 +442,7 @@ class Diff(object): return None - @classmethod + @ classmethod def _index_from_patch_format(cls, repo: 'Repo', proc: TBD) -> DiffIndex: """Create a new DiffIndex from the given text which must be in patch format :param repo: is the repository we are operating on - it is required @@ -505,7 +505,7 @@ class Diff(object): return index - @staticmethod + @ staticmethod def _handle_diff_line(lines_bytes: bytes, repo: 'Repo', index: DiffIndex) -> None: lines = lines_bytes.decode(defenc) @@ -559,7 +559,7 @@ class Diff(object): '', change_type, score) index.append(diff) - @classmethod + @ classmethod def _index_from_raw_format(cls, repo: 'Repo', proc: 'Popen') -> 'DiffIndex': """Create a new DiffIndex from the given stream which must be in raw format. :return: git.DiffIndex""" -- cgit v1.2.1 From e7b685db1bf4d9d6aa3f95f4df3fda5992dab14c Mon Sep 17 00:00:00 2001 From: Yobmod Date: Fri, 9 Jul 2021 15:49:32 +0100 Subject: Rmv Diffable assert, add Remoote.url property --- git/diff.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'git/diff.py') diff --git a/git/diff.py b/git/diff.py index 4024776d..1e2ee740 100644 --- a/git/diff.py +++ b/git/diff.py @@ -143,8 +143,6 @@ class Diffable(object): if hasattr(self, 'Has_Repo'): self.repo: Repo = self.repo - else: - raise AttributeError("No repo member found, cannot create DiffIndex") diff_cmd = self.repo.git.diff if other is self.Index: -- cgit v1.2.1 From 797e962fc1811ddc5a5a34308bd243953eb77135 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Fri, 9 Jul 2021 16:27:34 +0100 Subject: Make IndexFile and Diffable .diff() types agree --- git/diff.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'git/diff.py') diff --git a/git/diff.py b/git/diff.py index 1e2ee740..7ca98ec3 100644 --- a/git/diff.py +++ b/git/diff.py @@ -20,6 +20,7 @@ from git.types import PathLike, TBD, Literal, TypeGuard if TYPE_CHECKING: from .objects.tree import Tree + from .objects import Commit from git.repo.base import Repo from git.objects.base import IndexObject from subprocess import Popen @@ -90,7 +91,7 @@ class Diffable(object): Subclasses can use it to alter the behaviour of the superclass""" return args - def diff(self, other: Union[Type['Index'], 'Tree', None, str] = Index, + def diff(self, other: Union[Type['Index'], 'Tree', 'Commit', None, str] = Index, # object for git.NULL_TREE paths: Union[PathLike, List[PathLike], Tuple[PathLike, ...], None] = None, create_patch: bool = False, **kwargs: Any) -> 'DiffIndex': """Creates diffs between two items being trees, trees and index or an -- cgit v1.2.1 From 09053c565915d114384b1c20af8eecfed98c8069 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Fri, 9 Jul 2021 22:58:02 +0100 Subject: Improve IndexFile_process_diff_args() to get checks to rerun --- git/diff.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'git/diff.py') diff --git a/git/diff.py b/git/diff.py index 7ca98ec3..51dac390 100644 --- a/git/diff.py +++ b/git/diff.py @@ -82,8 +82,8 @@ class Diffable(object): class Index(object): pass - def _process_diff_args(self, args: List[Union[PathLike, 'Diffable', Type['Diffable.Index']]] - ) -> List[Union[PathLike, 'Diffable', Type['Diffable.Index']]]: + def _process_diff_args(self, args: List[Union[str, 'Diffable', Type['Diffable.Index'], object]] + ) -> List[Union[str, 'Diffable', Type['Diffable.Index'], object]]: """ :return: possibly altered version of the given args list. @@ -91,7 +91,7 @@ class Diffable(object): Subclasses can use it to alter the behaviour of the superclass""" return args - def diff(self, other: Union[Type['Index'], 'Tree', 'Commit', None, str] = Index, # object for git.NULL_TREE + def diff(self, other: Union[Type['Index'], 'Tree', 'Commit', None, str, object] = Index, paths: Union[PathLike, List[PathLike], Tuple[PathLike, ...], None] = None, create_patch: bool = False, **kwargs: Any) -> 'DiffIndex': """Creates diffs between two items being trees, trees and index or an @@ -124,7 +124,7 @@ class Diffable(object): :note: On a bare repository, 'other' needs to be provided as Index or as as Tree/Commit, or a git command error will occur""" - args: List[Union[PathLike, Diffable, Type['Diffable.Index']]] = [] + args: List[Union[PathLike, Diffable, Type['Diffable.Index'], object]] = [] args.append("--abbrev=40") # we need full shas args.append("--full-index") # get full index paths, not only filenames -- cgit v1.2.1