summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--git/config.py16
-rw-r--r--git/repo/base.py3
-rw-r--r--git/types.py6
-rw-r--r--mypy.ini2
4 files changed, 14 insertions, 13 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
diff --git a/git/repo/base.py b/git/repo/base.py
index 94c6e30b..ce5f6bd0 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -34,7 +34,7 @@ import gitdb
# typing ------------------------------------------------------
-from git.types import TBD, PathLike, Literal
+from git.types import TBD, PathLike, Lit_config_levels
from typing import (Any, BinaryIO, Callable, Dict,
Iterator, List, Mapping, Optional,
TextIO, Tuple, Type, Union,
@@ -45,7 +45,6 @@ if TYPE_CHECKING: # only needed for types
from git.refs.symbolic import SymbolicReference
from git.objects import TagObject, Blob, Tree # NOQA: F401
-Lit_config_levels = Literal['system', 'global', 'user', 'repository']
# -----------------------------------------------------------
diff --git a/git/types.py b/git/types.py
index 40d4f788..6454bf0f 100644
--- a/git/types.py
+++ b/git/types.py
@@ -12,8 +12,6 @@ else:
from typing_extensions import Final, Literal # noqa: F401
-TBD = Any
-
if sys.version_info[:2] < (3, 6):
# os.PathLike (PEP-519) only got introduced with Python 3.6
PathLike = str
@@ -23,3 +21,7 @@ elif sys.version_info[:2] < (3, 9):
elif sys.version_info[:2] >= (3, 9):
# os.PathLike only becomes subscriptable from Python 3.9 onwards
PathLike = Union[str, os.PathLike[str]]
+
+TBD = Any
+
+Lit_config_levels = Literal['system', 'global', 'user', 'repository']
diff --git a/mypy.ini b/mypy.ini
index 8f86a6af..d55d2164 100644
--- a/mypy.ini
+++ b/mypy.ini
@@ -2,7 +2,7 @@
[mypy]
# TODO: enable when we've fully annotated everything
-# disallow_untyped_defs = True
+disallow_untyped_defs = True
# TODO: remove when 'gitdb' is fully annotated
[mypy-gitdb.*]