| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,7 +42,7 @@ | |||
| 42 | 42 | from typing import (Any, AnyStr, BinaryIO, Callable, Dict, IO, Iterator, List, Mapping, | |
| 43 | 43 | Sequence, TYPE_CHECKING, TextIO, Tuple, Union, cast, overload) | |
| 44 | 44 | ||
| 45 | - from git.types import PathLike, Literal | ||
| 45 | + from git.types import PathLike, Literal, TBD | ||
| 46 | 46 | ||
| 47 | 47 | if TYPE_CHECKING: | |
| 48 | 48 | from git.repo.base import Repo | |
@@ -575,8 +575,8 @@ def __init__(self, working_dir: Union[None, PathLike] = None): | |||
| 575 | 575 | self._environment: Dict[str, str] = {} | |
| 576 | 576 | ||
| 577 | 577 | # cached command slots | |
| 578 | - self.cat_file_header = None | ||
| 579 | - self.cat_file_all = None | ||
| 578 | + self.cat_file_header: Union[None, TBD] = None | ||
| 579 | + self.cat_file_all: Union[None, TBD] = None | ||
| 580 | 580 | ||
| 581 | 581 | def __getattr__(self, name: str) -> Any: | |
| 582 | 582 | """A convenience method as it allows to call the command as if it was | |
@@ -1012,8 +1012,6 @@ def transform_kwargs(self, split_single_char_options: bool = True, **kwargs: Any | |||
| 1012 | 1012 | ||
| 1013 | 1013 | @classmethod | |
| 1014 | 1014 | def __unpack_args(cls, arg_list: Sequence[str]) -> List[str]: | |
| 1015 | - if not isinstance(arg_list, (list, tuple)): | ||
| 1016 | - return [str(arg_list)] | ||
| 1017 | 1015 | ||
| 1018 | 1016 | outlist = [] | |
| 1019 | 1017 | for arg in arg_list: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -236,7 +236,8 @@ def get_config_path(config_level: Lit_config_levels) -> str: | |||
| 236 | 236 | raise ValueError("No repo to get repository configuration from. Use Repo._get_config_path") | |
| 237 | 237 | else: | |
| 238 | 238 | # Should not reach here. Will raise ValueError if does. Static typing will warn missing elifs | |
| 239 | - assert_never(config_level, ValueError(f"Invalid configuration level: {config_level!r}")) | ||
| 239 | + assert_never(config_level, # type: ignore[unreachable] | ||
| 240 | + ValueError(f"Invalid configuration level: {config_level!r}")) | ||
| 240 | 241 | ||
| 241 | 242 | ||
| 242 | 243 | class GitConfigParser(cp.RawConfigParser, metaclass=MetaParserBuilder): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -456,8 +456,8 @@ def _index_from_patch_format(cls, repo: 'Repo', proc: Union['Popen', 'Git.AutoIn | |||
| 456 | 456 | # for now, we have to bake the stream | |
| 457 | 457 | text = b''.join(text_list) | |
| 458 | 458 | index: 'DiffIndex' = DiffIndex() | |
| 459 | - previous_header = None | ||
| 460 | - header = None | ||
| 459 | + previous_header: Union[Match[bytes], None] = None | ||
| 460 | + header: Union[Match[bytes], None] = None | ||
| 461 | 461 | a_path, b_path = None, None # for mypy | |
| 462 | 462 | a_mode, b_mode = None, None # for mypy | |
| 463 | 463 | for _header in cls.re_header.finditer(text): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1202,7 +1202,6 @@ def handle_stderr(proc: 'Popen[bytes]', iter_checked_out_files: Iterable[PathLik | |||
| 1202 | 1202 | handle_stderr(proc, checked_out_files) | |
| 1203 | 1203 | return checked_out_files | |
| 1204 | 1204 | # END paths handling | |
| 1205 | - assert "Should not reach this point" | ||
| 1206 | 1205 | ||
| 1207 | 1206 | @ default_index | |
| 1208 | 1207 | def reset(self, commit: Union[Commit, 'Reference', str] = 'HEAD', working_tree: bool = False, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,7 +51,7 @@ def tree_to_stream(entries: Sequence[EntryTup], write: Callable[['ReadableBuffer | |||
| 51 | 51 | if isinstance(name, str): | |
| 52 | 52 | name_bytes = name.encode(defenc) | |
| 53 | 53 | else: | |
| 54 | - name_bytes = name | ||
| 54 | + name_bytes = name # type: ignore[unreachable] # check runtime types - is always str? | ||
| 55 | 55 | write(b''.join((mode_str, b' ', name_bytes, b'\0', binsha))) | |
| 56 | 56 | # END for each item | |
| 57 | 57 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -215,7 +215,7 @@ def __init__(self, repo: 'Repo', binsha: bytes, mode: int = tree_id << 12, path: | |||
| 215 | 215 | super(Tree, self).__init__(repo, binsha, mode, path) | |
| 216 | 216 | ||
| 217 | 217 | @ classmethod | |
| 218 | - def _get_intermediate_items(cls, index_object: 'Tree', | ||
| 218 | + def _get_intermediate_items(cls, index_object: IndexObjUnion, | ||
| 219 | 219 | ) -> Union[Tuple['Tree', ...], Tuple[()]]: | |
| 220 | 220 | if index_object.type == "tree": | |
| 221 | 221 | return tuple(index_object._iter_convert_to_object(index_object._cache)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -167,7 +167,7 @@ def from_timestamp(timestamp: float, tz_offset: float) -> datetime: | |||
| 167 | 167 | return utc_dt | |
| 168 | 168 | ||
| 169 | 169 | ||
| 170 | - def parse_date(string_date: str) -> Tuple[int, int]: | ||
| 170 | + def parse_date(string_date: Union[str, datetime]) -> Tuple[int, int]: | ||
| 171 | 171 | """ | |
| 172 | 172 | Parse the given date as one of the following | |
| 173 | 173 | ||
@@ -182,8 +182,10 @@ def parse_date(string_date: str) -> Tuple[int, int]: | |||
| 182 | 182 | :note: Date can also be YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY. | |
| 183 | 183 | """ | |
| 184 | 184 | if isinstance(string_date, datetime) and string_date.tzinfo: | |
| 185 | - offset = -int(string_date.utcoffset().total_seconds()) | ||
| 185 | + offset = -int(string_date.utcoffset().total_seconds()) # type: ignore[union-attr] | ||
| 186 | 186 | return int(string_date.astimezone(utc).timestamp()), offset | |
| 187 | + else: | ||
| 188 | + assert isinstance(string_date, str) # for mypy | ||
| 187 | 189 | ||
| 188 | 190 | # git time | |
| 189 | 191 | try: | |
@@ -338,7 +340,7 @@ def _list_traverse(self, as_edge: bool = False, *args: Any, **kwargs: Any | |||
| 338 | 340 | """ | |
| 339 | 341 | # Commit and Submodule have id.__attribute__ as IterableObj | |
| 340 | 342 | # Tree has id.__attribute__ inherited from IndexObject | |
| 341 | - if isinstance(self, (TraversableIterableObj, Has_id_attribute)): | ||
| 343 | + if isinstance(self, Has_id_attribute): | ||
| 342 | 344 | id = self._id_attribute_ | |
| 343 | 345 | else: | |
| 344 | 346 | id = "" # shouldn't reach here, unless Traversable subclass created with no _id_attribute_ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -200,7 +200,6 @@ def __init__(self, path: Optional[PathLike] = None, odbt: Type[LooseObjectDB] = | |||
| 200 | 200 | # END while curpath | |
| 201 | 201 | ||
| 202 | 202 | if self.git_dir is None: | |
| 203 | - self.git_dir = cast(PathLike, self.git_dir) | ||
| 204 | 203 | raise InvalidGitRepositoryError(epath) | |
| 205 | 204 | ||
| 206 | 205 | self._bare = False | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,6 @@ | |||
| 1 | 1 | """Package with general repository related functions""" | |
| 2 | + from git.refs.reference import Reference | ||
| 3 | + from git.types import Commit_ish | ||
| 2 | 4 | import os | |
| 3 | 5 | import stat | |
| 4 | 6 | from string import digits | |
@@ -202,7 +204,7 @@ def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']: | |||
| 202 | 204 | raise NotImplementedError("commit by message search ( regex )") | |
| 203 | 205 | # END handle search | |
| 204 | 206 | ||
| 205 | - obj = cast(Object, None) # not ideal. Should use guards | ||
| 207 | + obj: Union[Commit_ish, Reference, None] = None | ||
| 206 | 208 | ref = None | |
| 207 | 209 | output_type = "commit" | |
| 208 | 210 | start = 0 | |
@@ -222,14 +224,16 @@ def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']: | |||
| 222 | 224 | ref = repo.head.ref | |
| 223 | 225 | else: | |
| 224 | 226 | if token == '@': | |
| 225 | - ref = name_to_object(repo, rev[:start], return_ref=True) | ||
| 227 | + ref = cast(Reference, name_to_object(repo, rev[:start], return_ref=True)) | ||
| 226 | 228 | else: | |
| 227 | - obj = name_to_object(repo, rev[:start]) | ||
| 229 | + obj = cast(Commit_ish, name_to_object(repo, rev[:start])) | ||
| 228 | 230 | # END handle token | |
| 229 | 231 | # END handle refname | |
| 232 | + else: | ||
| 233 | + assert obj is not None | ||
| 230 | 234 | ||
| 231 | 235 | if ref is not None: | |
| 232 | - obj = ref.commit | ||
| 236 | + obj = cast(Commit, ref.commit) | ||
| 233 | 237 | # END handle ref | |
| 234 | 238 | # END initialize obj on first token | |
| 235 | 239 | ||
@@ -247,11 +251,13 @@ def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']: | |||
| 247 | 251 | pass # default | |
| 248 | 252 | elif output_type == 'tree': | |
| 249 | 253 | try: | |
| 254 | + obj = cast(Object, obj) | ||
| 250 | 255 | obj = to_commit(obj).tree | |
| 251 | 256 | except (AttributeError, ValueError): | |
| 252 | 257 | pass # error raised later | |
| 253 | 258 | # END exception handling | |
| 254 | 259 | elif output_type in ('', 'blob'): | |
| 260 | + obj = cast(TagObject, obj) | ||
| 255 | 261 | if obj and obj.type == 'tag': | |
| 256 | 262 | obj = deref_tag(obj) | |
| 257 | 263 | else: | |
@@ -280,13 +286,13 @@ def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']: | |||
| 280 | 286 | obj = Object.new_from_sha(repo, hex_to_bin(entry.newhexsha)) | |
| 281 | 287 | ||
| 282 | 288 | # make it pass the following checks | |
| 283 | - output_type = None | ||
| 289 | + output_type = '' | ||
| 284 | 290 | else: | |
| 285 | 291 | raise ValueError("Invalid output type: %s ( in %s )" % (output_type, rev)) | |
| 286 | 292 | # END handle output type | |
| 287 | 293 | ||
| 288 | 294 | # empty output types don't require any specific type, its just about dereferencing tags | |
| 289 | - if output_type and obj.type != output_type: | ||
| 295 | + if output_type and obj and obj.type != output_type: | ||
| 290 | 296 | raise ValueError("Could not accommodate requested object type %r, got %s" % (output_type, obj.type)) | |
| 291 | 297 | # END verify output type | |
| 292 | 298 | ||
@@ -319,6 +325,7 @@ def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']: | |||
| 319 | 325 | parsed_to = start | |
| 320 | 326 | # handle hierarchy walk | |
| 321 | 327 | try: | |
| 328 | + obj = cast(Commit_ish, obj) | ||
| 322 | 329 | if token == "~": | |
| 323 | 330 | obj = to_commit(obj) | |
| 324 | 331 | for _ in range(num): | |
@@ -347,7 +354,7 @@ def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']: | |||
| 347 | 354 | ||
| 348 | 355 | # still no obj ? Its probably a simple name | |
| 349 | 356 | if obj is None: | |
| 350 | - obj = name_to_object(repo, rev) | ||
| 357 | + obj = cast(Commit_ish, name_to_object(repo, rev)) | ||
| 351 | 358 | parsed_to = lr | |
| 352 | 359 | # END handle simple name | |
| 353 | 360 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,7 @@ no_implicit_optional = true | |||
| 24 | 24 | warn_redundant_casts = true | |
| 25 | 25 | implicit_reexport = true | |
| 26 | 26 | warn_unused_ignores = true | |
| 27 | - # warn_unreachable = True | ||
| 27 | + warn_unreachable = true | ||
| 28 | 28 | show_error_codes = true | |
| 29 | 29 | ||
| 30 | 30 | # TODO: remove when 'gitdb' is fully annotated | |
| Back | FazBrowse Home | New Git URL |
0 commit comments