diff options
-rw-r--r-- | git/config.py | 18 | ||||
-rw-r--r-- | git/util.py | 8 | ||||
-rw-r--r-- | pyproject.toml | 2 |
3 files changed, 16 insertions, 12 deletions
diff --git a/git/config.py b/git/config.py index ad02b437..a3f41c60 100644 --- a/git/config.py +++ b/git/config.py @@ -40,6 +40,7 @@ if TYPE_CHECKING: from io import BytesIO T_ConfigParser = TypeVar('T_ConfigParser', bound='GitConfigParser') +T_OMD_value = TypeVar('T_OMD_value', str, bytes, int, float, bool) if sys.version_info[:3] < (3, 7, 2): # typing.Ordereddict not added until py 3.7.2 @@ -47,7 +48,7 @@ if sys.version_info[:3] < (3, 7, 2): OrderedDict_OMD = OrderedDict # type: ignore # until 3.6 dropped else: from typing import OrderedDict # type: ignore # until 3.6 dropped - OrderedDict_OMD = OrderedDict[str, List[_T]] # type: ignore[assignment, misc] + OrderedDict_OMD = OrderedDict[str, List[T_OMD_value]] # type: ignore[assignment, misc] # ------------------------------------------------------------- @@ -97,23 +98,23 @@ class MetaParserBuilder(abc.ABCMeta): return new_type -def needs_values(func: Callable) -> Callable: +def needs_values(func: Callable[..., _T]) -> Callable[..., _T]: """Returns method assuring we read values (on demand) before we try to access them""" @wraps(func) - def assure_data_present(self, *args: Any, **kwargs: Any) -> Any: + def assure_data_present(self: GitConfigParser, *args: Any, **kwargs: Any) -> _T: self.read() return func(self, *args, **kwargs) # END wrapper method return assure_data_present -def set_dirty_and_flush_changes(non_const_func: Callable) -> Callable: +def set_dirty_and_flush_changes(non_const_func: Callable[..., _T]) -> Callable[..., _T]: """Return method that checks whether given non constant function may be called. If so, the instance will be set dirty. Additionally, we flush the changes right to disk""" - def flush_changes(self, *args: Any, **kwargs: Any) -> Any: + def flush_changes(self: GitConfigParser, *args: Any, **kwargs: Any) -> _T: rval = non_const_func(self, *args, **kwargs) self._dirty = True self.write() @@ -356,7 +357,7 @@ class GitConfigParser(cp.RawConfigParser, metaclass=MetaParserBuilder): self._acquire_lock() return self - def __exit__(self, exception_type, exception_value, traceback) -> None: + def __exit__(self, *args: Any) -> None: self.release() def release(self) -> None: @@ -613,12 +614,15 @@ class GitConfigParser(cp.RawConfigParser, metaclass=MetaParserBuilder): def _write(self, fp: IO) -> None: """Write an .ini-format representation of the configuration state in git compatible format""" - def write_section(name, section_dict): + def write_section(name: str, section_dict: _OMD) -> None: fp.write(("[%s]\n" % name).encode(defenc)) + + values: Sequence[Union[str, bytes, int, float, bool]] for (key, values) in section_dict.items_all(): if key == "__name__": continue + v: Union[str, bytes, int, float, bool] for v in values: fp.write(("\t%s = %s\n" % (key, self._value_to_string(v).replace('\n', '\n\t'))).encode(defenc)) # END if key is not __name__ diff --git a/git/util.py b/git/util.py index c0c0ecb7..92d95379 100644 --- a/git/util.py +++ b/git/util.py @@ -408,7 +408,7 @@ def expand_path(p: Union[None, PathLike], expand_vars: bool = True) -> Optional[ return None -def remove_password_if_present(cmdline): +def remove_password_if_present(cmdline: Sequence[str]) -> List[str]: """ Parse any command line argument and if on of the element is an URL with a password, replace it by stars (in-place). @@ -1033,7 +1033,7 @@ class IterableList(List[T_IterableObj]): class IterableClassWatcher(type): """ Metaclass that watches """ - def __init__(cls, name, bases, clsdict): + def __init__(cls, name: str, bases: List, clsdict: Dict) -> None: for base in bases: if type(base) == IterableClassWatcher: warnings.warn(f"GitPython Iterable subclassed by {name}. " @@ -1052,7 +1052,7 @@ class Iterable(metaclass=IterableClassWatcher): _id_attribute_ = "attribute that most suitably identifies your instance" @classmethod - def list_items(cls, repo, *args, **kwargs): + def list_items(cls, repo: 'Repo', *args: Any, **kwargs: Any) -> Any: """ Deprecated, use IterableObj instead. Find all items of this type - subclasses can specify args and kwargs differently. @@ -1062,7 +1062,7 @@ class Iterable(metaclass=IterableClassWatcher): :note: Favor the iter_items method as it will :return:list(Item,...) list of item instances""" - out_list = IterableList(cls._id_attribute_) + out_list: Any = IterableList(cls._id_attribute_) out_list.extend(cls.iter_items(repo, *args, **kwargs)) return out_list diff --git a/pyproject.toml b/pyproject.toml index ccf5c165..6437a719 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ filterwarnings = 'ignore::DeprecationWarning' # filterwarnings ignore::WarningType # ignores those warnings [tool.mypy] -#disallow_untyped_defs = true +# disallow_untyped_defs = true no_implicit_optional = true warn_redundant_casts = true # warn_unused_ignores = True |