| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,7 @@ enable-extensions = TC, TC2 # only needed for extensions not enabled by default | |||
| 19 | 19 | ignore = E265,E266,E731,E704, | |
| 20 | 20 | W293, W504, | |
| 21 | 21 | ANN0 ANN1 ANN2, | |
| 22 | - TC0, TC1, TC2 | ||
| 22 | + # TC0, TC1, TC2 | ||
| 23 | 23 | # B, | |
| 24 | 24 | A, | |
| 25 | 25 | D, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -565,11 +565,11 @@ def __init__(self, working_dir: Union[None, PathLike] = None): | |||
| 565 | 565 | .git directory in case of bare repositories.""" | |
| 566 | 566 | super(Git, self).__init__() | |
| 567 | 567 | self._working_dir = expand_path(working_dir) | |
| 568 | - self._git_options = () # type: Union[List[str], Tuple[str, ...]] | ||
| 569 | - self._persistent_git_options = [] # type: List[str] | ||
| 568 | + self._git_options: Union[List[str], Tuple[str, ...]] = () | ||
| 569 | + self._persistent_git_options: List[str] = [] | ||
| 570 | 570 | ||
| 571 | 571 | # Extra environment variables to pass to git commands | |
| 572 | - self._environment = {} # type: Dict[str, str] | ||
| 572 | + self._environment: Dict[str, str] = {} | ||
| 573 | 573 | ||
| 574 | 574 | # cached command slots | |
| 575 | 575 | self.cat_file_header = None | |
@@ -603,9 +603,9 @@ def _set_cache_(self, attr: str) -> None: | |||
| 603 | 603 | process_version = self._call_process('version') # should be as default *args and **kwargs used | |
| 604 | 604 | version_numbers = process_version.split(' ')[2] | |
| 605 | 605 | ||
| 606 | - self._version_info = tuple( | ||
| 606 | + self._version_info: Tuple[int, int, int, int] = tuple( | ||
| 607 | 607 | int(n) for n in version_numbers.split('.')[:4] if n.isdigit() | |
| 608 | - ) # type: Tuple[int, int, int, int] # type: ignore | ||
| 608 | + ) # type: ignore # use typeguard here | ||
| 609 | 609 | else: | |
| 610 | 610 | super(Git, self)._set_cache_(attr) | |
| 611 | 611 | # END handle version info | |
@@ -868,8 +868,8 @@ def _kill_process(pid: int) -> None: | |||
| 868 | 868 | ||
| 869 | 869 | # Wait for the process to return | |
| 870 | 870 | status = 0 | |
| 871 | - stdout_value = b'' # type: Union[str, bytes] | ||
| 872 | - stderr_value = b'' # type: Union[str, bytes] | ||
| 871 | + stdout_value: Union[str, bytes] = b'' | ||
| 872 | + stderr_value: Union[str, bytes] = b'' | ||
| 873 | 873 | newline = "\n" if universal_newlines else b"\n" | |
| 874 | 874 | try: | |
| 875 | 875 | if output_stream is None: | |
@@ -1145,7 +1145,7 @@ def _prepare_ref(self, ref: AnyStr) -> bytes: | |||
| 1145 | 1145 | # required for command to separate refs on stdin, as bytes | |
| 1146 | 1146 | if isinstance(ref, bytes): | |
| 1147 | 1147 | # Assume 40 bytes hexsha - bin-to-ascii for some reason returns bytes, not text | |
| 1148 | - refstr = ref.decode('ascii') # type: str | ||
| 1148 | + refstr: str = ref.decode('ascii') | ||
| 1149 | 1149 | elif not isinstance(ref, str): | |
| 1150 | 1150 | refstr = str(ref) # could be ref-object | |
| 1151 | 1151 | else: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,7 +34,7 @@ | |||
| 34 | 34 | # --------------------------------------------------------------------------- | |
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | - is_win = (os.name == 'nt') # type: bool | ||
| 37 | + is_win: bool = (os.name == 'nt') | ||
| 38 | 38 | is_posix = (os.name == 'posix') | |
| 39 | 39 | is_darwin = (os.name == 'darwin') | |
| 40 | 40 | defenc = sys.getfilesystemencoding() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -208,7 +208,7 @@ def get(self, key: str, default: Union[Any, None] = None) -> Union[Any, None]: | |||
| 208 | 208 | def getall(self, key: str) -> Any: | |
| 209 | 209 | return super(_OMD, self).__getitem__(key) | |
| 210 | 210 | ||
| 211 | - def items(self) -> List[Tuple[str, Any]]: # type: ignore ## mypy doesn't like overwriting supertype signitures | ||
| 211 | + def items(self) -> List[Tuple[str, Any]]: # type: ignore[override] | ||
| 212 | 212 | """List of (key, last value for key).""" | |
| 213 | 213 | return [(k, self[k]) for k in self] | |
| 214 | 214 | ||
@@ -322,7 +322,7 @@ def __init__(self, file_or_files: Union[None, PathLike, 'BytesIO', Sequence[Unio | |||
| 322 | 322 | self._is_initialized = False | |
| 323 | 323 | self._merge_includes = merge_includes | |
| 324 | 324 | self._repo = repo | |
| 325 | - self._lock = None # type: Union['LockFile', None] | ||
| 325 | + self._lock: Union['LockFile', None] = None | ||
| 326 | 326 | self._acquire_lock() | |
| 327 | 327 | ||
| 328 | 328 | def _acquire_lock(self) -> None: | |
@@ -545,13 +545,15 @@ def read(self) -> None: | |||
| 545 | 545 | return None | |
| 546 | 546 | self._is_initialized = True | |
| 547 | 547 | ||
| 548 | - files_to_read = [""] # type: List[Union[PathLike, IO]] ## just for types until 3.5 dropped | ||
| 549 | - if isinstance(self._file_or_files, (str)): # replace with PathLike once 3.5 dropped | ||
| 550 | - files_to_read = [self._file_or_files] # for str, as str is a type of Sequence | ||
| 548 | + files_to_read: List[Union[PathLike, IO]] = [""] | ||
| 549 | + if isinstance(self._file_or_files, (str, os.PathLike)): | ||
| 550 | + # for str or Path, as str is a type of Sequence | ||
| 551 | + files_to_read = [self._file_or_files] | ||
| 551 | 552 | elif not isinstance(self._file_or_files, (tuple, list, Sequence)): | |
| 552 | - files_to_read = [self._file_or_files] # for IO or Path | ||
| 553 | - else: | ||
| 554 | - files_to_read = list(self._file_or_files) # for lists or tuples | ||
| 553 | + # could merge with above isinstance once runtime type known | ||
| 554 | + files_to_read = [self._file_or_files] | ||
| 555 | + else: # for lists or tuples | ||
| 556 | + files_to_read = list(self._file_or_files) | ||
| 555 | 557 | # end assure we have a copy of the paths to handle | |
| 556 | 558 | ||
| 557 | 559 | seen = set(files_to_read) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -351,13 +351,13 @@ def __hash__(self) -> int: | |||
| 351 | 351 | return hash(tuple(getattr(self, n) for n in self.__slots__)) | |
| 352 | 352 | ||
| 353 | 353 | def __str__(self) -> str: | |
| 354 | - h = "%s" # type: str | ||
| 354 | + h: str = "%s" | ||
| 355 | 355 | if self.a_blob: | |
| 356 | 356 | h %= self.a_blob.path | |
| 357 | 357 | elif self.b_blob: | |
| 358 | 358 | h %= self.b_blob.path | |
| 359 | 359 | ||
| 360 | - msg = '' # type: str | ||
| 360 | + msg: str = '' | ||
| 361 | 361 | line = None # temp line | |
| 362 | 362 | line_length = 0 # line length | |
| 363 | 363 | for b, n in zip((self.a_blob, self.b_blob), ('lhs', 'rhs')): | |
@@ -449,7 +449,7 @@ def _index_from_patch_format(cls, repo: 'Repo', proc: TBD) -> DiffIndex: | |||
| 449 | 449 | :return: git.DiffIndex """ | |
| 450 | 450 | ||
| 451 | 451 | ## FIXME: Here SLURPING raw, need to re-phrase header-regexes linewise. | |
| 452 | - text_list = [] # type: List[bytes] | ||
| 452 | + text_list: List[bytes] = [] | ||
| 453 | 453 | handle_process_output(proc, text_list.append, None, finalize_process, decode_streams=False) | |
| 454 | 454 | ||
| 455 | 455 | # for now, we have to bake the stream | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -123,7 +123,7 @@ def __init__(self, repo: 'Repo', file_path: Union[PathLike, None] = None) -> Non | |||
| 123 | 123 | self.repo = repo | |
| 124 | 124 | self.version = self._VERSION | |
| 125 | 125 | self._extension_data = b'' | |
| 126 | - self._file_path = file_path or self._index_path() # type: PathLike | ||
| 126 | + self._file_path: PathLike = file_path or self._index_path() | ||
| 127 | 127 | ||
| 128 | 128 | def _set_cache_(self, attr: str) -> None: | |
| 129 | 129 | if attr == "entries": | |
@@ -136,7 +136,7 @@ def _set_cache_(self, attr: str) -> None: | |||
| 136 | 136 | ok = True | |
| 137 | 137 | except OSError: | |
| 138 | 138 | # in new repositories, there may be no index, which means we are empty | |
| 139 | - self.entries = {} # type: Dict[Tuple[PathLike, StageType], IndexEntry] | ||
| 139 | + self.entries: Dict[Tuple[PathLike, StageType], IndexEntry] = {} | ||
| 140 | 140 | return None | |
| 141 | 141 | finally: | |
| 142 | 142 | if not ok: | |
@@ -266,7 +266,7 @@ def merge_tree(self, rhs: Treeish, base: Union[None, Treeish] = None) -> 'IndexF | |||
| 266 | 266 | # -i : ignore working tree status | |
| 267 | 267 | # --aggressive : handle more merge cases | |
| 268 | 268 | # -m : do an actual merge | |
| 269 | - args = ["--aggressive", "-i", "-m"] # type: List[Union[Treeish, str]] | ||
| 269 | + args: List[Union[Treeish, str]] = ["--aggressive", "-i", "-m"] | ||
| 270 | 270 | if base is not None: | |
| 271 | 271 | args.append(base) | |
| 272 | 272 | args.append(rhs) | |
@@ -288,14 +288,14 @@ def new(cls, repo: 'Repo', *tree_sha: Union[str, Tree]) -> 'IndexFile': | |||
| 288 | 288 | New IndexFile instance. Its path will be undefined. | |
| 289 | 289 | If you intend to write such a merged Index, supply an alternate file_path | |
| 290 | 290 | to its 'write' method.""" | |
| 291 | - tree_sha_bytes = [to_bin_sha(str(t)) for t in tree_sha] # List[bytes] | ||
| 291 | + tree_sha_bytes: List[bytes] = [to_bin_sha(str(t)) for t in tree_sha] | ||
| 292 | 292 | base_entries = aggressive_tree_merge(repo.odb, tree_sha_bytes) | |
| 293 | 293 | ||
| 294 | 294 | inst = cls(repo) | |
| 295 | 295 | # convert to entries dict | |
| 296 | - entries = dict(zip( | ||
| 296 | + entries: Dict[Tuple[PathLike, int], IndexEntry] = dict(zip( | ||
| 297 | 297 | ((e.path, e.stage) for e in base_entries), | |
| 298 | - (IndexEntry.from_base(e) for e in base_entries))) # type: Dict[Tuple[PathLike, int], IndexEntry] | ||
| 298 | + (IndexEntry.from_base(e) for e in base_entries))) | ||
| 299 | 299 | ||
| 300 | 300 | inst.entries = entries | |
| 301 | 301 | return inst | |
@@ -338,7 +338,7 @@ def from_tree(cls, repo: 'Repo', *treeish: Treeish, **kwargs: Any) -> 'IndexFile | |||
| 338 | 338 | if len(treeish) == 0 or len(treeish) > 3: | |
| 339 | 339 | raise ValueError("Please specify between 1 and 3 treeish, got %i" % len(treeish)) | |
| 340 | 340 | ||
| 341 | - arg_list = [] # type: List[Union[Treeish, str]] | ||
| 341 | + arg_list: List[Union[Treeish, str]] = [] | ||
| 342 | 342 | # ignore that working tree and index possibly are out of date | |
| 343 | 343 | if len(treeish) > 1: | |
| 344 | 344 | # drop unmerged entries when reading our index and merging | |
@@ -445,7 +445,7 @@ def _write_path_to_stdin(self, proc: 'Popen', filepath: PathLike, item: TBD, fma | |||
| 445 | 445 | we will close stdin to break the pipe.""" | |
| 446 | 446 | ||
| 447 | 447 | fprogress(filepath, False, item) | |
| 448 | - rval = None # type: Union[None, str] | ||
| 448 | + rval: Union[None, str] = None | ||
| 449 | 449 | ||
| 450 | 450 | if proc.stdin is not None: | |
| 451 | 451 | try: | |
@@ -492,7 +492,7 @@ def unmerged_blobs(self) -> Dict[PathLike, List[Tuple[StageType, Blob]]]: | |||
| 492 | 492 | are at stage 3 will not have a stage 3 entry. | |
| 493 | 493 | """ | |
| 494 | 494 | is_unmerged_blob = lambda t: t[0] != 0 | |
| 495 | - path_map = {} # type: Dict[PathLike, List[Tuple[TBD, Blob]]] | ||
| 495 | + path_map: Dict[PathLike, List[Tuple[TBD, Blob]]] = {} | ||
| 496 | 496 | for stage, blob in self.iter_blobs(is_unmerged_blob): | |
| 497 | 497 | path_map.setdefault(blob.path, []).append((stage, blob)) | |
| 498 | 498 | # END for each unmerged blob | |
@@ -624,8 +624,8 @@ def _store_path(self, filepath: PathLike, fprogress: Callable) -> BaseIndexEntry | |||
| 624 | 624 | st = os.lstat(filepath) # handles non-symlinks as well | |
| 625 | 625 | if S_ISLNK(st.st_mode): | |
| 626 | 626 | # in PY3, readlink is string, but we need bytes. In PY2, it's just OS encoded bytes, we assume UTF-8 | |
| 627 | - open_stream = lambda: BytesIO(force_bytes(os.readlink(filepath), | ||
| 628 | - encoding=defenc)) # type: Callable[[], BinaryIO] | ||
| 627 | + open_stream: Callable[[], BinaryIO] = lambda: BytesIO(force_bytes(os.readlink(filepath), | ||
| 628 | + encoding=defenc)) | ||
| 629 | 629 | else: | |
| 630 | 630 | open_stream = lambda: open(filepath, 'rb') | |
| 631 | 631 | with open_stream() as stream: | |
@@ -1160,7 +1160,7 @@ def handle_stderr(proc: 'Popen[bytes]', iter_checked_out_files: Iterable[PathLik | |||
| 1160 | 1160 | proc = self.repo.git.checkout_index(args, **kwargs) | |
| 1161 | 1161 | # FIXME: Reading from GIL! | |
| 1162 | 1162 | make_exc = lambda: GitCommandError(("git-checkout-index",) + tuple(args), 128, proc.stderr.read()) | |
| 1163 | - checked_out_files = [] # type: List[PathLike] | ||
| 1163 | + checked_out_files: List[PathLike] = [] | ||
| 1164 | 1164 | ||
| 1165 | 1165 | for path in paths: | |
| 1166 | 1166 | co_path = to_native_path_linux(self._to_relative_path(path)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -99,8 +99,8 @@ def run_commit_hook(name: str, index: 'IndexFile', *args: str) -> None: | |||
| 99 | 99 | except Exception as ex: | |
| 100 | 100 | raise HookExecutionError(hp, ex) from ex | |
| 101 | 101 | else: | |
| 102 | - stdout_list = [] # type: List[str] | ||
| 103 | - stderr_list = [] # type: List[str] | ||
| 102 | + stdout_list: List[str] = [] | ||
| 103 | + stderr_list: List[str] = [] | ||
| 104 | 104 | handle_process_output(cmd, stdout_list.append, stderr_list.append, finalize_process) | |
| 105 | 105 | stdout = ''.join(stdout_list) | |
| 106 | 106 | stderr = ''.join(stderr_list) | |
@@ -151,8 +151,8 @@ def write_cache(entries: Sequence[Union[BaseIndexEntry, 'IndexEntry']], stream: | |||
| 151 | 151 | beginoffset = tell() | |
| 152 | 152 | write(entry[4]) # ctime | |
| 153 | 153 | write(entry[5]) # mtime | |
| 154 | - path_str = entry[3] # type: str | ||
| 155 | - path = force_bytes(path_str, encoding=defenc) | ||
| 154 | + path_str: str = entry[3] | ||
| 155 | + path: bytes = force_bytes(path_str, encoding=defenc) | ||
| 156 | 156 | plen = len(path) & CE_NAMEMASK # path length | |
| 157 | 157 | assert plen == len(path), "Path %s too long to fit into index" % entry[3] | |
| 158 | 158 | flags = plen | (entry[2] & CE_NAMEMASK_INV) # clear possible previous values | |
@@ -210,7 +210,7 @@ def read_cache(stream: IO[bytes]) -> Tuple[int, Dict[Tuple[PathLike, int], 'Inde | |||
| 210 | 210 | * content_sha is a 20 byte sha on all cache file contents""" | |
| 211 | 211 | version, num_entries = read_header(stream) | |
| 212 | 212 | count = 0 | |
| 213 | - entries = {} # type: Dict[Tuple[PathLike, int], 'IndexEntry'] | ||
| 213 | + entries: Dict[Tuple[PathLike, int], 'IndexEntry'] = {} | ||
| 214 | 214 | ||
| 215 | 215 | read = stream.read | |
| 216 | 216 | tell = stream.tell | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -475,7 +475,8 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No | |||
| 475 | 475 | sm._branch_path = br.path | |
| 476 | 476 | ||
| 477 | 477 | # we deliberately assume that our head matches our index ! | |
| 478 | - sm.binsha = mrepo.head.commit.binsha # type: ignore | ||
| 478 | + if mrepo: | ||
| 479 | + sm.binsha = mrepo.head.commit.binsha | ||
| 479 | 480 | index.add([sm], write=True) | |
| 480 | 481 | ||
| 481 | 482 | return sm | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,7 +51,7 @@ def __init__(self, repo: 'Repo', binsha: bytes, | |||
| 51 | 51 | authored_date is in, in a format similar to time.altzone""" | |
| 52 | 52 | super(TagObject, self).__init__(repo, binsha) | |
| 53 | 53 | if object is not None: | |
| 54 | - self.object = object # type: Union['Commit', 'Blob', 'Tree', 'TagObject'] | ||
| 54 | + self.object: Union['Commit', 'Blob', 'Tree', 'TagObject'] = object | ||
| 55 | 55 | if tag is not None: | |
| 56 | 56 | self.tag = tag | |
| 57 | 57 | if tagger is not None: | |
@@ -67,7 +67,7 @@ def _set_cache_(self, attr: str) -> None: | |||
| 67 | 67 | """Cache all our attributes at once""" | |
| 68 | 68 | if attr in TagObject.__slots__: | |
| 69 | 69 | ostream = self.repo.odb.stream(self.binsha) | |
| 70 | - lines = ostream.read().decode(defenc, 'replace').splitlines() # type: List[str] | ||
| 70 | + lines: List[str] = ostream.read().decode(defenc, 'replace').splitlines() | ||
| 71 | 71 | ||
| 72 | 72 | _obj, hexsha = lines[0].split(" ") | |
| 73 | 73 | _type_token, type_name = lines[1].split(" ") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -298,7 +298,7 @@ def cache(self) -> TreeModifier: | |||
| 298 | 298 | See the ``TreeModifier`` for more information on how to alter the cache""" | |
| 299 | 299 | return TreeModifier(self._cache) | |
| 300 | 300 | ||
| 301 | - def traverse(self, # type: ignore # overrides super() | ||
| 301 | + def traverse(self, # type: ignore[override] | ||
| 302 | 302 | predicate: Callable[[Union[IndexObjUnion, TraversedTreeTup], int], bool] = lambda i, d: True, | |
| 303 | 303 | prune: Callable[[Union[IndexObjUnion, TraversedTreeTup], int], bool] = lambda i, d: False, | |
| 304 | 304 | depth: int = -1, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments