| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -831,7 +831,7 @@ def execute(self, | |||
| 831 | 831 | except cmd_not_found_exception as err: | |
| 832 | 832 | raise GitCommandNotFound(redacted_command, err) from err | |
| 833 | 833 | else: | |
| 834 | - proc = cast(Popen, proc) | ||
| 834 | + # replace with a typeguard for Popen[bytes]? | ||
| 835 | 835 | proc.stdout = cast(BinaryIO, proc.stdout) | |
| 836 | 836 | proc.stderr = cast(BinaryIO, proc.stderr) | |
| 837 | 837 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,7 +34,7 @@ | |||
| 34 | 34 | from typing import (Any, Callable, IO, List, Dict, Sequence, | |
| 35 | 35 | TYPE_CHECKING, Tuple, Union, cast, overload) | |
| 36 | 36 | ||
| 37 | - from git.types import Lit_config_levels, ConfigLevels_Tup, PathLike, TBD, assert_never | ||
| 37 | + from git.types import Lit_config_levels, ConfigLevels_Tup, PathLike, TBD, assert_never, is_config_level | ||
| 38 | 38 | ||
| 39 | 39 | if TYPE_CHECKING: | |
| 40 | 40 | from git.repo.base import Repo | |
@@ -54,6 +54,7 @@ | |||
| 54 | 54 | ||
| 55 | 55 | CONFIG_LEVELS: ConfigLevels_Tup = ("system", "user", "global", "repository") | |
| 56 | 56 | ||
| 57 | + | ||
| 57 | 58 | # Section pattern to detect conditional includes. | |
| 58 | 59 | # https://git-scm.com/docs/git-config#_conditional_includes | |
| 59 | 60 | CONDITIONAL_INCLUDE_REGEXP = re.compile(r"(?<=includeIf )\"(gitdir|gitdir/i|onbranch):(.+)\"") | |
@@ -310,7 +311,7 @@ def __init__(self, file_or_files: Union[None, PathLike, 'BytesIO', Sequence[Unio | |||
| 310 | 311 | if read_only: | |
| 311 | 312 | self._file_or_files = [get_config_path(f) | |
| 312 | 313 | for f in CONFIG_LEVELS | |
| 313 | - if f != 'repository'] | ||
| 314 | + if is_config_level(f) and f != 'repository'] | ||
| 314 | 315 | else: | |
| 315 | 316 | raise ValueError("No configuration level or configuration files specified") | |
| 316 | 317 | else: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -113,7 +113,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): | |||
| 113 | 113 | _VERSION = 2 # latest version we support | |
| 114 | 114 | S_IFGITLINK = S_IFGITLINK # a submodule | |
| 115 | 115 | ||
| 116 | - def __init__(self, repo: 'Repo', file_path: PathLike = None) -> None: | ||
| 116 | + def __init__(self, repo: 'Repo', file_path: Union[PathLike, None] = None) -> None: | ||
| 117 | 117 | """Initialize this Index instance, optionally from the given ``file_path``. | |
| 118 | 118 | If no file_path is given, we will be created from the current index file. | |
| 119 | 119 | ||
@@ -665,7 +665,7 @@ def _entries_for_paths(self, paths: List[str], path_rewriter: Callable, fprogres | |||
| 665 | 665 | return entries_added | |
| 666 | 666 | ||
| 667 | 667 | def add(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, 'Submodule']], force: bool = True, | |
| 668 | - fprogress: Callable = lambda *args: None, path_rewriter: Callable = None, | ||
| 668 | + fprogress: Callable = lambda *args: None, path_rewriter: Union[Callable[..., PathLike], None] = None, | ||
| 669 | 669 | write: bool = True, write_extension_data: bool = False) -> List[BaseIndexEntry]: | |
| 670 | 670 | """Add files from the working tree, specific blobs or BaseIndexEntries | |
| 671 | 671 | to the index. | |
@@ -970,7 +970,8 @@ def move(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, 'Submodule' | |||
| 970 | 970 | return out | |
| 971 | 971 | ||
| 972 | 972 | def commit(self, message: str, parent_commits=None, head: bool = True, author: Union[None, 'Actor'] = None, | |
| 973 | - committer: Union[None, 'Actor'] = None, author_date: str = None, commit_date: str = None, | ||
| 973 | + committer: Union[None, 'Actor'] = None, author_date: Union[str, None] = None, | ||
| 974 | + commit_date: Union[str, None] = None, | ||
| 974 | 975 | skip_hooks: bool = False) -> Commit: | |
| 975 | 976 | """Commit the current default index file, creating a commit object. | |
| 976 | 977 | For more information on the arguments, see tree.commit. | |
@@ -1265,7 +1266,8 @@ def reset(self, commit: Union[Commit, 'Reference', str] = 'HEAD', working_tree: | |||
| 1265 | 1266 | ||
| 1266 | 1267 | @ default_index | |
| 1267 | 1268 | def diff(self, other: Union[diff.Diffable.Index, 'IndexFile.Index', Treeish, None, object] = diff.Diffable.Index, | |
| 1268 | - paths: Union[str, List[PathLike], Tuple[PathLike, ...]] = None, create_patch: bool = False, **kwargs: Any | ||
| 1269 | + paths: Union[str, List[PathLike], Tuple[PathLike, ...], None] = None, | ||
| 1270 | + create_patch: bool = False, **kwargs: Any | ||
| 1269 | 1271 | ) -> diff.DiffIndex: | |
| 1270 | 1272 | """Diff this index against the working copy or a Tree or Commit object | |
| 1271 | 1273 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,7 +80,7 @@ class Commit(base.Object, TraversableIterableObj, Diffable, Serializable): | |||
| 80 | 80 | "message", "parents", "encoding", "gpgsig") | |
| 81 | 81 | _id_attribute_ = "hexsha" | |
| 82 | 82 | ||
| 83 | - def __init__(self, repo: 'Repo', binsha: bytes, tree: 'Tree' = None, | ||
| 83 | + def __init__(self, repo: 'Repo', binsha: bytes, tree: Union['Tree', None] = None, | ||
| 84 | 84 | author: Union[Actor, None] = None, | |
| 85 | 85 | authored_date: Union[int, None] = None, | |
| 86 | 86 | author_tz_offset: Union[None, float] = None, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -115,7 +115,7 @@ def __init__(self, repo: 'Repo', binsha: bytes, | |||
| 115 | 115 | path: Union[PathLike, None] = None, | |
| 116 | 116 | name: Union[str, None] = None, | |
| 117 | 117 | parent_commit: Union[Commit_ish, None] = None, | |
| 118 | - url: str = None, | ||
| 118 | + url: Union[str, None] = None, | ||
| 119 | 119 | branch_path: Union[PathLike, None] = None | |
| 120 | 120 | ) -> None: | |
| 121 | 121 | """Initialize this instance with its attributes. We only document the ones | |
@@ -339,7 +339,7 @@ def _write_git_file_and_module_config(cls, working_tree_dir: PathLike, module_ab | |||
| 339 | 339 | @classmethod | |
| 340 | 340 | def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = None, | |
| 341 | 341 | branch: Union[str, None] = None, no_checkout: bool = False, depth: Union[int, None] = None, | |
| 342 | - env: Mapping[str, str] = None, clone_multi_options: Union[Sequence[TBD], None] = None | ||
| 342 | + env: Union[Mapping[str, str], None] = None, clone_multi_options: Union[Sequence[TBD], None] = None | ||
| 343 | 343 | ) -> 'Submodule': | |
| 344 | 344 | """Add a new submodule to the given repository. This will alter the index | |
| 345 | 345 | as well as the .gitmodules file, but will not create a new commit. | |
@@ -481,7 +481,7 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No | |||
| 481 | 481 | ||
| 482 | 482 | def update(self, recursive: bool = False, init: bool = True, to_latest_revision: bool = False, | |
| 483 | 483 | progress: Union['UpdateProgress', None] = None, dry_run: bool = False, | |
| 484 | - force: bool = False, keep_going: bool = False, env: Mapping[str, str] = None, | ||
| 484 | + force: bool = False, keep_going: bool = False, env: Union[Mapping[str, str], None] = None, | ||
| 485 | 485 | clone_multi_options: Union[Sequence[TBD], None] = None): | |
| 486 | 486 | """Update the repository of this submodule to point to the checkout | |
| 487 | 487 | we point at with the binsha of this instance. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -216,7 +216,6 @@ def __init__(self, repo: 'Repo', binsha: bytes, mode: int = tree_id << 12, path: | |||
| 216 | 216 | def _get_intermediate_items(cls, index_object: 'Tree', | |
| 217 | 217 | ) -> Union[Tuple['Tree', ...], Tuple[()]]: | |
| 218 | 218 | if index_object.type == "tree": | |
| 219 | - index_object = cast('Tree', index_object) | ||
| 220 | 219 | return tuple(index_object._iter_convert_to_object(index_object._cache)) | |
| 221 | 220 | return () | |
| 222 | 221 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ | |||
| 36 | 36 | ||
| 37 | 37 | # typing ------------------------------------------------------ | |
| 38 | 38 | ||
| 39 | - from git.types import TBD, PathLike, Lit_config_levels, Commit_ish, Tree_ish | ||
| 39 | + from git.types import TBD, PathLike, Lit_config_levels, Commit_ish, Tree_ish, is_config_level | ||
| 40 | 40 | from typing import (Any, BinaryIO, Callable, Dict, | |
| 41 | 41 | Iterator, List, Mapping, Optional, Sequence, | |
| 42 | 42 | TextIO, Tuple, Type, Union, | |
@@ -498,7 +498,7 @@ def config_reader(self, config_level: Optional[Lit_config_levels] = None) -> Git | |||
| 498 | 498 | unknown, instead the global path will be used.""" | |
| 499 | 499 | files = None | |
| 500 | 500 | if config_level is None: | |
| 501 | - files = [self._get_config_path(f) for f in self.config_level] | ||
| 501 | + files = [self._get_config_path(f) for f in self.config_level if is_config_level(f)] | ||
| 502 | 502 | else: | |
| 503 | 503 | files = [self._get_config_path(config_level)] | |
| 504 | 504 | return GitConfigParser(files, read_only=True, repo=self) | |
@@ -623,7 +623,7 @@ def is_ancestor(self, ancestor_rev: 'Commit', rev: 'Commit') -> bool: | |||
| 623 | 623 | raise | |
| 624 | 624 | return True | |
| 625 | 625 | ||
| 626 | - def is_valid_object(self, sha: str, object_type: str = None) -> bool: | ||
| 626 | + def is_valid_object(self, sha: str, object_type: Union[str, None] = None) -> bool: | ||
| 627 | 627 | try: | |
| 628 | 628 | complete_sha = self.odb.partial_to_complete_sha_hex(sha) | |
| 629 | 629 | object_info = self.odb.info(complete_sha) | |
@@ -976,7 +976,7 @@ def blame(self, rev: TBD, file: TBD, incremental: bool = False, **kwargs: Any | |||
| 976 | 976 | return blames | |
| 977 | 977 | ||
| 978 | 978 | @classmethod | |
| 979 | - def init(cls, path: PathLike = None, mkdir: bool = True, odbt: Type[GitCmdObjectDB] = GitCmdObjectDB, | ||
| 979 | + def init(cls, path: Union[PathLike, None] = None, mkdir: bool = True, odbt: Type[GitCmdObjectDB] = GitCmdObjectDB, | ||
| 980 | 980 | expand_vars: bool = True, **kwargs: Any) -> 'Repo': | |
| 981 | 981 | """Initialize a git repository at the given path if specified | |
| 982 | 982 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,20 +39,11 @@ | |||
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | 41 | def is_config_level(inp: str) -> TypeGuard[Lit_config_levels]: | |
| 42 | - return inp in ('system', 'global', 'user', 'repository') | ||
| 42 | + # return inp in get_args(Lit_config_level) # only py >= 3.8 | ||
| 43 | + return inp in ("system", "user", "global", "repository") | ||
| 43 | 44 | ||
| 44 | 45 | ||
| 45 | - class ConfigLevels_NT(NamedTuple): | ||
| 46 | - """NamedTuple of allowed CONFIG_LEVELS""" | ||
| 47 | - # works for pylance, but not mypy | ||
| 48 | - system: Literal['system'] | ||
| 49 | - user: Literal['user'] | ||
| 50 | - global_: Literal['global'] | ||
| 51 | - repository: Literal['repository'] | ||
| 52 | - | ||
| 53 | - | ||
| 54 | - ConfigLevels_Tup = Tuple[Lit_config_levels, Lit_config_levels, Lit_config_levels, Lit_config_levels] | ||
| 55 | - # Typing this as specific literals breaks for mypy | ||
| 46 | + ConfigLevels_Tup = Tuple[Literal['system'], Literal['user'], Literal['global'], Literal['repository']] | ||
| 56 | 47 | ||
| 57 | 48 | ||
| 58 | 49 | def assert_never(inp: NoReturn, exc: Union[Exception, None] = None) -> NoReturn: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,11 @@ | |||
| 3 | 3 | ||
| 4 | 4 | # TODO: enable when we've fully annotated everything | |
| 5 | 5 | # disallow_untyped_defs = True | |
| 6 | + no_implicit_optional = True | ||
| 7 | + warn_redundant_casts = True | ||
| 8 | + # warn_unused_ignores = True | ||
| 9 | + # warn_unreachable = True | ||
| 10 | + pretty = True | ||
| 6 | 11 | ||
| 7 | 12 | # TODO: remove when 'gitdb' is fully annotated | |
| 8 | 13 | [mypy-gitdb.*] | |
| Back | FazBrowse Home | New Git URL |
0 commit comments