Skip to content

Commit efe6833

Browse files
committedMay 8, 2021
Add types to config.py CONFIG_LEVELS, MetaParserBuilder.__new__() .needs_values() .set_dirty_and_flush_changes()
1 parent 37cef23 commit efe6833

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed
 

‎git/config.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131

3232
# typing-------------------------------------------------------
3333

34-
from typing import TYPE_CHECKING, Tuple
34+
from typing import Any, Callable, Mapping, TYPE_CHECKING, Tuple
3535

36-
from git.types import Literal
36+
from git.types import Literal, Lit_config_levels, TBD
3737

3838
if TYPE_CHECKING:
3939
pass
@@ -59,7 +59,7 @@
5959
class MetaParserBuilder(abc.ABCMeta):
6060

6161
"""Utlity class wrapping base-class methods into decorators that assure read-only properties"""
62-
def __new__(cls, name, bases, clsdict):
62+
def __new__(cls, name: str, bases: TBD, clsdict: Mapping[str, Any]) -> TBD:
6363
"""
6464
Equip all base-class methods with a needs_values decorator, and all non-const methods
6565
with a set_dirty_and_flush_changes decorator in addition to that."""
@@ -85,23 +85,23 @@ def __new__(cls, name, bases, clsdict):
8585
return new_type
8686

8787

88-
def needs_values(func):
88+
def needs_values(func: Callable) -> Callable:
8989
"""Returns method assuring we read values (on demand) before we try to access them"""
9090

9191
@wraps(func)
92-
def assure_data_present(self, *args, **kwargs):
92+
def assure_data_present(self, *args: Any, **kwargs: Any) -> Any:
9393
self.read()
9494
return func(self, *args, **kwargs)
9595
# END wrapper method
9696
return assure_data_present
9797

9898

99-
def set_dirty_and_flush_changes(non_const_func):
99+
def set_dirty_and_flush_changes(non_const_func: Callable) -> Callable:
100100
"""Return method that checks whether given non constant function may be called.
101101
If so, the instance will be set dirty.
102102
Additionally, we flush the changes right to disk"""
103103

104-
def flush_changes(self, *args, **kwargs):
104+
def flush_changes(self, *args: Any, **kwargs: Any) -> Any:
105105
rval = non_const_func(self, *args, **kwargs)
106106
self._dirty = True
107107
self.write()
@@ -206,7 +206,7 @@ def items_all(self):
206206
return [(k, self.getall(k)) for k in self]
207207

208208

209-
def get_config_path(config_level: Literal['system', 'global', 'user', 'repository']) -> str:
209+
def get_config_path(config_level: Lit_config_levels) -> str:
210210

211211
# we do not support an absolute path of the gitconfig on windows ,
212212
# use the global config instead

‎git/repo/base.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
# typing ------------------------------------------------------
3636

37-
from git.types import TBD, PathLike, Literal
37+
from git.types import TBD, PathLike, Lit_config_levels
3838
from typing import (Any, BinaryIO, Callable, Dict,
3939
Iterator, List, Mapping, Optional,
4040
TextIO, Tuple, Type, Union,
@@ -45,7 +45,6 @@
4545
from git.refs.symbolic import SymbolicReference
4646
from git.objects import TagObject, Blob, Tree # NOQA: F401
4747

48-
Lit_config_levels = Literal['system', 'global', 'user', 'repository']
4948

5049
# -----------------------------------------------------------
5150

‎git/types.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
from typing_extensions import Final, Literal # noqa: F401
1313

1414

15-
TBD = Any
16-
1715
if sys.version_info[:2] < (3, 6):
1816
# os.PathLike (PEP-519) only got introduced with Python 3.6
1917
PathLike = str
@@ -23,3 +21,7 @@
2321
elif sys.version_info[:2] >= (3, 9):
2422
# os.PathLike only becomes subscriptable from Python 3.9 onwards
2523
PathLike = Union[str, os.PathLike[str]]
24+
25+
TBD = Any
26+
27+
Lit_config_levels = Literal['system', 'global', 'user', 'repository']

‎mypy.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[mypy]
33

44
# TODO: enable when we've fully annotated everything
5-
# disallow_untyped_defs = True
5+
disallow_untyped_defs = True
66

77
# TODO: remove when 'gitdb' is fully annotated
88
[mypy-gitdb.*]

0 commit comments

Comments
 (0)
Please sign in to comment.