| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,7 @@ | |||
| 19 | 19 | import threading | |
| 20 | 20 | from collections import OrderedDict | |
| 21 | 21 | from textwrap import dedent | |
| 22 | + from typing import Any, Dict, List, Optional | ||
| 22 | 23 | ||
| 23 | 24 | from git.compat import ( | |
| 24 | 25 | defenc, | |
@@ -39,6 +40,8 @@ | |||
| 39 | 40 | stream_copy, | |
| 40 | 41 | ) | |
| 41 | 42 | ||
| 43 | + from .types import PathLike | ||
| 44 | + | ||
| 42 | 45 | execute_kwargs = {'istream', 'with_extended_output', | |
| 43 | 46 | 'with_exceptions', 'as_process', 'stdout_as_string', | |
| 44 | 47 | 'output_stream', 'with_stdout', 'kill_after_timeout', | |
@@ -516,7 +519,7 @@ def __del__(self): | |||
| 516 | 519 | self._stream.read(bytes_left + 1) | |
| 517 | 520 | # END handle incomplete read | |
| 518 | 521 | ||
| 519 | - def __init__(self, working_dir=None): | ||
| 522 | + def __init__(self, working_dir: Optional[PathLike]=None) -> None: | ||
| 520 | 523 | """Initialize this instance with: | |
| 521 | 524 | ||
| 522 | 525 | :param working_dir: | |
@@ -525,12 +528,12 @@ def __init__(self, working_dir=None): | |||
| 525 | 528 | It is meant to be the working tree directory if available, or the | |
| 526 | 529 | .git directory in case of bare repositories.""" | |
| 527 | 530 | super(Git, self).__init__() | |
| 528 | - self._working_dir = expand_path(working_dir) | ||
| 531 | + self._working_dir = expand_path(working_dir) if working_dir is not None else None | ||
| 529 | 532 | self._git_options = () | |
| 530 | - self._persistent_git_options = [] | ||
| 533 | + self._persistent_git_options = [] # type: List[str] | ||
| 531 | 534 | ||
| 532 | 535 | # Extra environment variables to pass to git commands | |
| 533 | - self._environment = {} | ||
| 536 | + self._environment = {} # type: Dict[str, Any] | ||
| 534 | 537 | ||
| 535 | 538 | # cached command slots | |
| 536 | 539 | self.cat_file_header = None | |
@@ -544,7 +547,7 @@ def __getattr__(self, name): | |||
| 544 | 547 | return LazyMixin.__getattr__(self, name) | |
| 545 | 548 | return lambda *args, **kwargs: self._call_process(name, *args, **kwargs) | |
| 546 | 549 | ||
| 547 | - def set_persistent_git_options(self, **kwargs): | ||
| 550 | + def set_persistent_git_options(self, **kwargs) -> None: | ||
| 548 | 551 | """Specify command line options to the git executable | |
| 549 | 552 | for subsequent subcommand calls | |
| 550 | 553 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ | |||
| 10 | 10 | import locale | |
| 11 | 11 | import os | |
| 12 | 12 | import sys | |
| 13 | + from typing import AnyStr, Optional, Type | ||
| 13 | 14 | ||
| 14 | 15 | ||
| 15 | 16 | from gitdb.utils.encoding import ( | |
@@ -18,40 +19,46 @@ | |||
| 18 | 19 | ) | |
| 19 | 20 | ||
| 20 | 21 | ||
| 21 | - is_win = (os.name == 'nt') | ||
| 22 | + is_win = (os.name == 'nt') # type: bool | ||
| 22 | 23 | is_posix = (os.name == 'posix') | |
| 23 | 24 | is_darwin = (os.name == 'darwin') | |
| 24 | 25 | defenc = sys.getfilesystemencoding() | |
| 25 | 26 | ||
| 26 | 27 | ||
| 27 | - def safe_decode(s): | ||
| 28 | + def safe_decode(s: Optional[AnyStr]) -> Optional[str]: | ||
| 28 | 29 | """Safely decodes a binary string to unicode""" | |
| 29 | 30 | if isinstance(s, str): | |
| 30 | 31 | return s | |
| 31 | 32 | elif isinstance(s, bytes): | |
| 32 | 33 | return s.decode(defenc, 'surrogateescape') | |
| 33 | - elif s is not None: | ||
| 34 | + elif s is None: | ||
| 35 | + return None | ||
| 36 | + else: | ||
| 34 | 37 | raise TypeError('Expected bytes or text, but got %r' % (s,)) | |
| 35 | 38 | ||
| 36 | 39 | ||
| 37 | - def safe_encode(s): | ||
| 38 | - """Safely decodes a binary string to unicode""" | ||
| 40 | + | ||
| 41 | + def safe_encode(s: Optional[AnyStr]) -> Optional[bytes]: | ||
| 42 | + """Safely encodes a binary string to unicode""" | ||
| 39 | 43 | if isinstance(s, str): | |
| 40 | 44 | return s.encode(defenc) | |
| 41 | 45 | elif isinstance(s, bytes): | |
| 42 | 46 | return s | |
| 43 | - elif s is not None: | ||
| 47 | + elif s is None: | ||
| 48 | + return None | ||
| 49 | + else: | ||
| 44 | 50 | raise TypeError('Expected bytes or text, but got %r' % (s,)) | |
| 45 | 51 | ||
| 46 | 52 | ||
| 47 | - def win_encode(s): | ||
| 53 | + def win_encode(s: Optional[AnyStr]) -> Optional[bytes]: | ||
| 48 | 54 | """Encode unicodes for process arguments on Windows.""" | |
| 49 | 55 | if isinstance(s, str): | |
| 50 | 56 | return s.encode(locale.getpreferredencoding(False)) | |
| 51 | 57 | elif isinstance(s, bytes): | |
| 52 | 58 | return s | |
| 53 | 59 | elif s is not None: | |
| 54 | 60 | raise TypeError('Expected bytes or text, but got %r' % (s,)) | |
| 61 | + return None | ||
| 55 | 62 | ||
| 56 | 63 | ||
| 57 | 64 | def with_metaclass(meta, *bases): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,8 @@ | |||
| 16 | 16 | import fnmatch | |
| 17 | 17 | from collections import OrderedDict | |
| 18 | 18 | ||
| 19 | + from typing_extensions import Literal | ||
| 20 | + | ||
| 19 | 21 | from git.compat import ( | |
| 20 | 22 | defenc, | |
| 21 | 23 | force_text, | |
@@ -194,7 +196,7 @@ def items_all(self): | |||
| 194 | 196 | return [(k, self.getall(k)) for k in self] | |
| 195 | 197 | ||
| 196 | 198 | ||
| 197 | - def get_config_path(config_level): | ||
| 199 | + def get_config_path(config_level: Literal['system','global','user','repository']) -> str: | ||
| 198 | 200 | ||
| 199 | 201 | # we do not support an absolute path of the gitconfig on windows , | |
| 200 | 202 | # use the global config instead | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -513,7 +513,7 @@ def _create(cls, repo, path, resolve, reference, force, logmsg=None): | |||
| 513 | 513 | return ref | |
| 514 | 514 | ||
| 515 | 515 | @classmethod | |
| 516 | - def create(cls, repo, path, reference='HEAD', force=False, logmsg=None): | ||
| 516 | + def create(cls, repo, path, reference='HEAD', force=False, logmsg=None, **kwargs): | ||
| 517 | 517 | """Create a new symbolic reference, hence a reference pointing to another reference. | |
| 518 | 518 | ||
| 519 | 519 | :param repo: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments