diff options
author | yobmod <yobmod@gmail.com> | 2021-05-08 20:28:23 +0100 |
---|---|---|
committer | yobmod <yobmod@gmail.com> | 2021-05-08 20:28:23 +0100 |
commit | efe68337c513c573dde8fbf58337bed2fa2ca39a (patch) | |
tree | 34e6e5edbba91b23b3f4d39019c8bd6811e6b95b /git/config.py | |
parent | 37cef2340d3e074a226c0e81eaf000b5b90dfa55 (diff) | |
download | gitpython-efe68337c513c573dde8fbf58337bed2fa2ca39a.tar.gz |
Add types to config.py CONFIG_LEVELS, MetaParserBuilder.__new__() .needs_values() .set_dirty_and_flush_changes()
Diffstat (limited to 'git/config.py')
-rw-r--r-- | git/config.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/git/config.py b/git/config.py index ea7302f4..9f4d5ad9 100644 --- a/git/config.py +++ b/git/config.py @@ -31,9 +31,9 @@ import configparser as cp # typing------------------------------------------------------- -from typing import TYPE_CHECKING, Tuple +from typing import Any, Callable, Mapping, TYPE_CHECKING, Tuple -from git.types import Literal +from git.types import Literal, Lit_config_levels, TBD if TYPE_CHECKING: pass @@ -59,7 +59,7 @@ CONDITIONAL_INCLUDE_REGEXP = re.compile(r"(?<=includeIf )\"(gitdir|gitdir/i|onbr class MetaParserBuilder(abc.ABCMeta): """Utlity class wrapping base-class methods into decorators that assure read-only properties""" - def __new__(cls, name, bases, clsdict): + def __new__(cls, name: str, bases: TBD, clsdict: Mapping[str, Any]) -> TBD: """ Equip all base-class methods with a needs_values decorator, and all non-const methods with a set_dirty_and_flush_changes decorator in addition to that.""" @@ -85,23 +85,23 @@ class MetaParserBuilder(abc.ABCMeta): return new_type -def needs_values(func): +def needs_values(func: Callable) -> Callable: """Returns method assuring we read values (on demand) before we try to access them""" @wraps(func) - def assure_data_present(self, *args, **kwargs): + def assure_data_present(self, *args: Any, **kwargs: Any) -> Any: self.read() return func(self, *args, **kwargs) # END wrapper method return assure_data_present -def set_dirty_and_flush_changes(non_const_func): +def set_dirty_and_flush_changes(non_const_func: Callable) -> Callable: """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, **kwargs): + def flush_changes(self, *args: Any, **kwargs: Any) -> Any: rval = non_const_func(self, *args, **kwargs) self._dirty = True self.write() @@ -206,7 +206,7 @@ class _OMD(OrderedDict): return [(k, self.getall(k)) for k in self] -def get_config_path(config_level: Literal['system', 'global', 'user', 'repository']) -> str: +def get_config_path(config_level: Lit_config_levels) -> str: # we do not support an absolute path of the gitconfig on windows , # use the global config instead |