| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,6 @@ | |||
| 15 | 15 | PIPE | |
| 16 | 16 | ) | |
| 17 | 17 | import subprocess | |
| 18 | - import sys | ||
| 19 | 18 | import threading | |
| 20 | 19 | from textwrap import dedent | |
| 21 | 20 | ||
@@ -539,7 +538,7 @@ def __iter__(self) -> 'Git.CatFileContentStream': | |||
| 539 | 538 | return self | |
| 540 | 539 | ||
| 541 | 540 | def __next__(self) -> bytes: | |
| 542 | - return self.next() | ||
| 541 | + return next(self) | ||
| 543 | 542 | ||
| 544 | 543 | def next(self) -> bytes: | |
| 545 | 544 | line = self.readline() | |
@@ -799,10 +798,7 @@ def execute(self, | |||
| 799 | 798 | if kill_after_timeout: | |
| 800 | 799 | raise GitCommandError(redacted_command, '"kill_after_timeout" feature is not supported on Windows.') | |
| 801 | 800 | else: | |
| 802 | - if sys.version_info[0] > 2: | ||
| 803 | - cmd_not_found_exception = FileNotFoundError # NOQA # exists, flake8 unknown @UndefinedVariable | ||
| 804 | - else: | ||
| 805 | - cmd_not_found_exception = OSError | ||
| 801 | + cmd_not_found_exception = FileNotFoundError # NOQA # exists, flake8 unknown @UndefinedVariable | ||
| 806 | 802 | # end handle | |
| 807 | 803 | ||
| 808 | 804 | stdout_sink = (PIPE | |
@@ -1070,8 +1066,8 @@ def _call_process(self, method: str, *args: Any, **kwargs: Any | |||
| 1070 | 1066 | It contains key-values for the following: | |
| 1071 | 1067 | - the :meth:`execute()` kwds, as listed in :var:`execute_kwargs`; | |
| 1072 | 1068 | - "command options" to be converted by :meth:`transform_kwargs()`; | |
| 1073 | - - the `'insert_kwargs_after'` key which its value must match one of ``*args``, | ||
| 1074 | - and any cmd-options will be appended after the matched arg. | ||
| 1069 | + - the `'insert_kwargs_after'` key which its value must match one of ``*args`` | ||
| 1070 | + and any cmd-options will be appended after the matched arg. | ||
| 1075 | 1071 | ||
| 1076 | 1072 | Examples:: | |
| 1077 | 1073 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -238,7 +238,7 @@ def get_config_path(config_level: Lit_config_levels) -> str: | |||
| 238 | 238 | assert_never(config_level, ValueError(f"Invalid configuration level: {config_level!r}")) | |
| 239 | 239 | ||
| 240 | 240 | ||
| 241 | - class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, object)): # type: ignore ## mypy does not understand dynamic class creation # noqa: E501 | ||
| 241 | + class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser)): # type: ignore ## mypy does not understand dynamic class creation # noqa: E501 | ||
| 242 | 242 | ||
| 243 | 243 | """Implements specifics required to read git style configuration files. | |
| 244 | 244 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,7 @@ | |||
| 17 | 17 | ||
| 18 | 18 | if TYPE_CHECKING: | |
| 19 | 19 | from git.cmd import Git | |
| 20 | - | ||
| 20 | + | ||
| 21 | 21 | ||
| 22 | 22 | # -------------------------------------------------------- | |
| 23 | 23 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -143,7 +143,7 @@ def diff(self, other: Union[Type['Index'], 'Tree', 'Commit', None, str, object] | |||
| 143 | 143 | paths = [paths] | |
| 144 | 144 | ||
| 145 | 145 | if hasattr(self, 'Has_Repo'): | |
| 146 | - self.repo: Repo = self.repo | ||
| 146 | + self.repo: 'Repo' = self.repo | ||
| 147 | 147 | ||
| 148 | 148 | diff_cmd = self.repo.git.diff | |
| 149 | 149 | if other is self.Index: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,9 +36,10 @@ | |||
| 36 | 36 | ||
| 37 | 37 | # typing------------------------------------------------------- | |
| 38 | 38 | ||
| 39 | - from typing import Any, Callable, Dict, Iterator, List, Optional, Sequence, TYPE_CHECKING, Union, overload | ||
| 39 | + from typing import (Any, Callable, Dict, Iterator, List, NoReturn, Optional, Sequence, # NOQA[TC002] | ||
| 40 | + TYPE_CHECKING, Type, Union, overload) | ||
| 40 | 41 | ||
| 41 | - from git.types import PathLike, Literal, TBD, TypeGuard, Commit_ish | ||
| 42 | + from git.types import PathLike, Literal, TBD, TypeGuard, Commit_ish # NOQA[TC002] | ||
| 42 | 43 | ||
| 43 | 44 | if TYPE_CHECKING: | |
| 44 | 45 | from git.repo.base import Repo | |
@@ -83,17 +84,17 @@ def add_progress(kwargs: Any, git: Git, | |||
| 83 | 84 | #} END utilities | |
| 84 | 85 | ||
| 85 | 86 | ||
| 86 | - @overload | ||
| 87 | + @ overload | ||
| 87 | 88 | def to_progress_instance(progress: None) -> RemoteProgress: | |
| 88 | 89 | ... | |
| 89 | 90 | ||
| 90 | 91 | ||
| 91 | - @overload | ||
| 92 | + @ overload | ||
| 92 | 93 | def to_progress_instance(progress: Callable[..., Any]) -> CallableRemoteProgress: | |
| 93 | 94 | ... | |
| 94 | 95 | ||
| 95 | 96 | ||
| 96 | - @overload | ||
| 97 | + @ overload | ||
| 97 | 98 | def to_progress_instance(progress: RemoteProgress) -> RemoteProgress: | |
| 98 | 99 | ... | |
| 99 | 100 | ||
@@ -155,11 +156,11 @@ def __init__(self, flags: int, local_ref: Union[SymbolicReference, None], remote | |||
| 155 | 156 | self._old_commit_sha = old_commit | |
| 156 | 157 | self.summary = summary | |
| 157 | 158 | ||
| 158 | - @property | ||
| 159 | - def old_commit(self) -> Union[str, SymbolicReference, 'Commit_ish', None]: | ||
| 159 | + @ property | ||
| 160 | + def old_commit(self) -> Union[str, SymbolicReference, Commit_ish, None]: | ||
| 160 | 161 | return self._old_commit_sha and self._remote.repo.commit(self._old_commit_sha) or None | |
| 161 | 162 | ||
| 162 | - @property | ||
| 163 | + @ property | ||
| 163 | 164 | def remote_ref(self) -> Union[RemoteReference, TagReference]: | |
| 164 | 165 | """ | |
| 165 | 166 | :return: | |
@@ -175,7 +176,7 @@ def remote_ref(self) -> Union[RemoteReference, TagReference]: | |||
| 175 | 176 | raise ValueError("Could not handle remote ref: %r" % self.remote_ref_string) | |
| 176 | 177 | # END | |
| 177 | 178 | ||
| 178 | - @classmethod | ||
| 179 | + @ classmethod | ||
| 179 | 180 | def _from_line(cls, remote: 'Remote', line: str) -> 'PushInfo': | |
| 180 | 181 | """Create a new PushInfo instance as parsed from line which is expected to be like | |
| 181 | 182 | refs/heads/master:refs/heads/master 05d2687..1d0568e as bytes""" | |
@@ -228,6 +229,11 @@ def _from_line(cls, remote: 'Remote', line: str) -> 'PushInfo': | |||
| 228 | 229 | ||
| 229 | 230 | return PushInfo(flags, from_ref, to_ref_string, remote, old_commit, summary) | |
| 230 | 231 | ||
| 232 | + @ classmethod | ||
| 233 | + def iter_items(cls, repo: 'Repo', *args: Any, **kwargs: Any | ||
| 234 | + ) -> NoReturn: # -> Iterator['PushInfo']: | ||
| 235 | + raise NotImplementedError | ||
| 236 | + | ||
| 231 | 237 | ||
| 232 | 238 | class FetchInfo(IterableObj, object): | |
| 233 | 239 | ||
@@ -262,7 +268,7 @@ class FetchInfo(IterableObj, object): | |||
| 262 | 268 | '-': TAG_UPDATE, | |
| 263 | 269 | } # type: Dict[flagKeyLiteral, int] | |
| 264 | 270 | ||
| 265 | - @classmethod | ||
| 271 | + @ classmethod | ||
| 266 | 272 | def refresh(cls) -> Literal[True]: | |
| 267 | 273 | """This gets called by the refresh function (see the top level | |
| 268 | 274 | __init__). | |
@@ -301,25 +307,25 @@ def __init__(self, ref: SymbolicReference, flags: int, note: str = '', | |||
| 301 | 307 | def __str__(self) -> str: | |
| 302 | 308 | return self.name | |
| 303 | 309 | ||
| 304 | - @property | ||
| 310 | + @ property | ||
| 305 | 311 | def name(self) -> str: | |
| 306 | 312 | """:return: Name of our remote ref""" | |
| 307 | 313 | return self.ref.name | |
| 308 | 314 | ||
| 309 | - @property | ||
| 315 | + @ property | ||
| 310 | 316 | def commit(self) -> Commit_ish: | |
| 311 | 317 | """:return: Commit of our remote ref""" | |
| 312 | 318 | return self.ref.commit | |
| 313 | 319 | ||
| 314 | - @classmethod | ||
| 320 | + @ classmethod | ||
| 315 | 321 | def _from_line(cls, repo: 'Repo', line: str, fetch_line: str) -> 'FetchInfo': | |
| 316 | 322 | """Parse information from the given line as returned by git-fetch -v | |
| 317 | 323 | and return a new FetchInfo object representing this information. | |
| 318 | 324 | ||
| 319 | - We can handle a line as follows | ||
| 320 | - "%c %-*s %-*s -> %s%s" | ||
| 325 | + We can handle a line as follows: | ||
| 326 | + "%c %-\\*s %-\\*s -> %s%s" | ||
| 321 | 327 | ||
| 322 | - Where c is either ' ', !, +, -, *, or = | ||
| 328 | + Where c is either ' ', !, +, -, \\*, or = | ||
| 323 | 329 | ! means error | |
| 324 | 330 | + means success forcing update | |
| 325 | 331 | - means a tag was updated | |
@@ -334,6 +340,7 @@ def _from_line(cls, repo: 'Repo', line: str, fetch_line: str) -> 'FetchInfo': | |||
| 334 | 340 | raise ValueError("Failed to parse line: %r" % line) | |
| 335 | 341 | ||
| 336 | 342 | # parse lines | |
| 343 | + remote_local_ref_str: str | ||
| 337 | 344 | control_character, operation, local_remote_ref, remote_local_ref_str, note = match.groups() | |
| 338 | 345 | assert is_flagKeyLiteral(control_character), f"{control_character}" | |
| 339 | 346 | ||
@@ -375,7 +382,7 @@ def _from_line(cls, repo: 'Repo', line: str, fetch_line: str) -> 'FetchInfo': | |||
| 375 | 382 | # If we do not specify a target branch like master:refs/remotes/origin/master, | |
| 376 | 383 | # the fetch result is stored in FETCH_HEAD which destroys the rule we usually | |
| 377 | 384 | # have. In that case we use a symbolic reference which is detached | |
| 378 | - ref_type = None | ||
| 385 | + ref_type: Optional[Type[SymbolicReference]] = None | ||
| 379 | 386 | if remote_local_ref_str == "FETCH_HEAD": | |
| 380 | 387 | ref_type = SymbolicReference | |
| 381 | 388 | elif ref_type_name == "tag" or is_tag_operation: | |
@@ -404,14 +411,15 @@ def _from_line(cls, repo: 'Repo', line: str, fetch_line: str) -> 'FetchInfo': | |||
| 404 | 411 | # by the 'ref/' prefix. Otherwise even a tag could be in refs/remotes, which is when it will have the | |
| 405 | 412 | # 'tags/' subdirectory in its path. | |
| 406 | 413 | # We don't want to test for actual existence, but try to figure everything out analytically. | |
| 407 | - ref_path = None # type: Optional[PathLike] | ||
| 414 | + ref_path: Optional[PathLike] = None | ||
| 408 | 415 | remote_local_ref_str = remote_local_ref_str.strip() | |
| 416 | + | ||
| 409 | 417 | if remote_local_ref_str.startswith(Reference._common_path_default + "/"): | |
| 410 | 418 | # always use actual type if we get absolute paths | |
| 411 | 419 | # Will always be the case if something is fetched outside of refs/remotes (if its not a tag) | |
| 412 | 420 | ref_path = remote_local_ref_str | |
| 413 | 421 | if ref_type is not TagReference and not \ | |
| 414 | - remote_local_ref_str.startswith(RemoteReference._common_path_default + "/"): | ||
| 422 | + remote_local_ref_str.startswith(RemoteReference._common_path_default + "/"): | ||
| 415 | 423 | ref_type = Reference | |
| 416 | 424 | # END downgrade remote reference | |
| 417 | 425 | elif ref_type is TagReference and 'tags/' in remote_local_ref_str: | |
@@ -430,6 +438,11 @@ def _from_line(cls, repo: 'Repo', line: str, fetch_line: str) -> 'FetchInfo': | |||
| 430 | 438 | ||
| 431 | 439 | return cls(remote_local_ref, flags, note, old_commit, local_remote_ref) | |
| 432 | 440 | ||
| 441 | + @ classmethod | ||
| 442 | + def iter_items(cls, repo: 'Repo', *args: Any, **kwargs: Any | ||
| 443 | + ) -> NoReturn: # -> Iterator['FetchInfo']: | ||
| 444 | + raise NotImplementedError | ||
| 445 | + | ||
| 433 | 446 | ||
| 434 | 447 | class Remote(LazyMixin, IterableObj): | |
| 435 | 448 | ||
@@ -507,7 +520,7 @@ def exists(self) -> bool: | |||
| 507 | 520 | return False | |
| 508 | 521 | # end | |
| 509 | 522 | ||
| 510 | - @classmethod | ||
| 523 | + @ classmethod | ||
| 511 | 524 | def iter_items(cls, repo: 'Repo', *args: Any, **kwargs: Any) -> Iterator['Remote']: | |
| 512 | 525 | """:return: Iterator yielding Remote objects of the given repository""" | |
| 513 | 526 | for section in repo.config_reader("repository").sections(): | |
@@ -897,7 +910,7 @@ def push(self, refspec: Union[str, List[str], None] = None, | |||
| 897 | 910 | universal_newlines=True, **kwargs) | |
| 898 | 911 | return self._get_push_info(proc, progress) | |
| 899 | 912 | ||
| 900 | - @property | ||
| 913 | + @ property | ||
| 901 | 914 | def config_reader(self) -> SectionConstraint: | |
| 902 | 915 | """ | |
| 903 | 916 | :return: | |
@@ -912,7 +925,7 @@ def _clear_cache(self) -> None: | |||
| 912 | 925 | pass | |
| 913 | 926 | # END handle exception | |
| 914 | 927 | ||
| 915 | - @property | ||
| 928 | + @ property | ||
| 916 | 929 | def config_writer(self) -> SectionConstraint: | |
| 917 | 930 | """ | |
| 918 | 931 | :return: GitConfigParser compatible object able to write options for this remote. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ | |||
| 4 | 4 | # This module is part of GitPython and is released under | |
| 5 | 5 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php | |
| 6 | 6 | ||
| 7 | + from abc import abstractmethod | ||
| 7 | 8 | from .exc import InvalidGitRepositoryError | |
| 8 | 9 | import os.path as osp | |
| 9 | 10 | from .compat import is_win | |
@@ -28,7 +29,8 @@ | |||
| 28 | 29 | # typing --------------------------------------------------------- | |
| 29 | 30 | ||
| 30 | 31 | from typing import (Any, AnyStr, BinaryIO, Callable, Dict, Generator, IO, Iterator, List, | |
| 31 | - Optional, Pattern, Sequence, Tuple, TypeVar, Union, cast, TYPE_CHECKING, overload) | ||
| 32 | + Optional, Pattern, Sequence, Tuple, TypeVar, Union, cast, | ||
| 33 | + TYPE_CHECKING, overload, ) | ||
| 32 | 34 | ||
| 33 | 35 | import pathlib | |
| 34 | 36 | ||
@@ -39,8 +41,8 @@ | |||
| 39 | 41 | # from git.objects.base import IndexObject | |
| 40 | 42 | ||
| 41 | 43 | ||
| 42 | - from .types import (Literal, SupportsIndex, # because behind py version guards | ||
| 43 | - PathLike, HSH_TD, Total_TD, Files_TD, # aliases | ||
| 44 | + from .types import (Literal, SupportsIndex, Protocol, runtime_checkable, # because behind py version guards | ||
| 45 | + PathLike, HSH_TD, Total_TD, Files_TD, # aliases | ||
| 44 | 46 | Has_id_attribute) | |
| 45 | 47 | ||
| 46 | 48 | T_IterableObj = TypeVar('T_IterableObj', bound=Union['IterableObj', 'Has_id_attribute'], covariant=True) | |
@@ -471,7 +473,7 @@ def _parse_progress_line(self, line: AnyStr) -> None: | |||
| 471 | 473 | ||
| 472 | 474 | - Lines that do not contain progress info are stored in :attr:`other_lines`. | |
| 473 | 475 | - Lines that seem to contain an error (i.e. start with error: or fatal:) are stored | |
| 474 | - in :attr:`error_lines`.""" | ||
| 476 | + in :attr:`error_lines`.""" | ||
| 475 | 477 | # handle | |
| 476 | 478 | # Counting objects: 4, done. | |
| 477 | 479 | # Compressing objects: 50% (1/2) | |
@@ -993,7 +995,7 @@ def __getattr__(self, attr: str) -> T_IterableObj: | |||
| 993 | 995 | # END for each item | |
| 994 | 996 | return list.__getattribute__(self, attr) | |
| 995 | 997 | ||
| 996 | - def __getitem__(self, index: Union[SupportsIndex, int, slice, str]) -> 'T_IterableObj': # type: ignore | ||
| 998 | + def __getitem__(self, index: Union[SupportsIndex, int, slice, str]) -> T_IterableObj: # type: ignore | ||
| 997 | 999 | ||
| 998 | 1000 | assert isinstance(index, (int, str, slice)), "Index of IterableList should be an int or str" | |
| 999 | 1001 | ||
@@ -1030,23 +1032,24 @@ def __delitem__(self, index: Union[SupportsIndex, int, slice, str]) -> None: | |||
| 1030 | 1032 | ||
| 1031 | 1033 | ||
| 1032 | 1034 | class IterableClassWatcher(type): | |
| 1035 | + """ Metaclass that watches """ | ||
| 1033 | 1036 | def __init__(cls, name, bases, clsdict): | |
| 1034 | 1037 | for base in bases: | |
| 1035 | 1038 | if type(base) == IterableClassWatcher: | |
| 1036 | 1039 | warnings.warn(f"GitPython Iterable subclassed by {name}. " | |
| 1037 | - "Iterable is deprecated due to naming clash, " | ||
| 1040 | + "Iterable is deprecated due to naming clash since v3.1.18" | ||
| 1041 | + " and will be removed in 3.1.20, " | ||
| 1038 | 1042 | "Use IterableObj instead \n", | |
| 1039 | 1043 | DeprecationWarning, | |
| 1040 | 1044 | stacklevel=2) | |
| 1041 | 1045 | ||
| 1042 | 1046 | ||
| 1043 | - class Iterable(object): | ||
| 1047 | + class Iterable(metaclass=IterableClassWatcher): | ||
| 1044 | 1048 | ||
| 1045 | 1049 | """Defines an interface for iterable items which is to assure a uniform | |
| 1046 | 1050 | way to retrieve and iterate items within the git repository""" | |
| 1047 | 1051 | __slots__ = () | |
| 1048 | 1052 | _id_attribute_ = "attribute that most suitably identifies your instance" | |
| 1049 | - __metaclass__ = IterableClassWatcher | ||
| 1050 | 1053 | ||
| 1051 | 1054 | @classmethod | |
| 1052 | 1055 | def list_items(cls, repo, *args, **kwargs): | |
@@ -1064,14 +1067,15 @@ def list_items(cls, repo, *args, **kwargs): | |||
| 1064 | 1067 | return out_list | |
| 1065 | 1068 | ||
| 1066 | 1069 | @classmethod | |
| 1067 | - def iter_items(cls, repo: 'Repo', *args: Any, **kwargs: Any): | ||
| 1070 | + def iter_items(cls, repo: 'Repo', *args: Any, **kwargs: Any) -> Any: | ||
| 1068 | 1071 | # return typed to be compatible with subtypes e.g. Remote | |
| 1069 | 1072 | """For more information about the arguments, see list_items | |
| 1070 | 1073 | :return: iterator yielding Items""" | |
| 1071 | 1074 | raise NotImplementedError("To be implemented by Subclass") | |
| 1072 | 1075 | ||
| 1073 | 1076 | ||
| 1074 | - class IterableObj(): | ||
| 1077 | + @runtime_checkable | ||
| 1078 | + class IterableObj(Protocol): | ||
| 1075 | 1079 | """Defines an interface for iterable items which is to assure a uniform | |
| 1076 | 1080 | way to retrieve and iterate items within the git repository | |
| 1077 | 1081 | ||
@@ -1095,11 +1099,12 @@ def list_items(cls, repo: 'Repo', *args: Any, **kwargs: Any) -> IterableList[T_I | |||
| 1095 | 1099 | return out_list | |
| 1096 | 1100 | ||
| 1097 | 1101 | @classmethod | |
| 1102 | + @abstractmethod | ||
| 1098 | 1103 | def iter_items(cls, repo: 'Repo', *args: Any, **kwargs: Any | |
| 1099 | - ) -> Iterator[T_IterableObj]: | ||
| 1104 | + ) -> Iterator[T_IterableObj]: # Iterator[T_IterableObj]: | ||
| 1100 | 1105 | # return typed to be compatible with subtypes e.g. Remote | |
| 1101 | 1106 | """For more information about the arguments, see list_items | |
| 1102 | - :return: iterator yielding Items""" | ||
| 1107 | + :return: iterator yielding Items""" | ||
| 1103 | 1108 | raise NotImplementedError("To be implemented by Subclass") | |
| 1104 | 1109 | ||
| 1105 | 1110 | # } END classes | |
| Back | FazBrowse Home | New Git URL |
0 commit comments