summaryrefslogtreecommitdiff
path: root/git/config.py
diff options
context:
space:
mode:
authorDominic <yobmod@gmail.com>2021-08-03 16:40:48 +0100
committerGitHub <noreply@github.com>2021-08-03 16:40:48 +0100
commitfe54118ec07a68d5dc6f6108510cffc55dfca643 (patch)
tree3025974ca54ef607ee3d4660da4dc242e184f8ea /git/config.py
parentd8a639865d02a6bb3f93a233d3caa928d18bc622 (diff)
parent84232f7c71e41e56636f203eb26763a03ab6e945 (diff)
downloadgitpython-fe54118ec07a68d5dc6f6108510cffc55dfca643.tar.gz
Merge pull request #1311 from Yobmod/main
Drop 3.6, increase type strictness
Diffstat (limited to 'git/config.py')
-rw-r--r--git/config.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/git/config.py b/git/config.py
index 011d0e0b..293281d2 100644
--- a/git/config.py
+++ b/git/config.py
@@ -33,7 +33,7 @@ import configparser as cp
from typing import (Any, Callable, Generic, IO, List, Dict, Sequence,
TYPE_CHECKING, Tuple, TypeVar, Union, cast, overload)
-from git.types import Lit_config_levels, ConfigLevels_Tup, PathLike, TBD, assert_never, _T
+from git.types import Lit_config_levels, ConfigLevels_Tup, PathLike, assert_never, _T
if TYPE_CHECKING:
from git.repo.base import Repo
@@ -44,10 +44,10 @@ 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
- from collections import OrderedDict # type: ignore # until 3.6 dropped
- OrderedDict_OMD = OrderedDict # type: ignore # until 3.6 dropped
+ from collections import OrderedDict
+ OrderedDict_OMD = OrderedDict
else:
- from typing import OrderedDict # type: ignore # until 3.6 dropped
+ from typing import OrderedDict
OrderedDict_OMD = OrderedDict[str, List[T_OMD_value]] # type: ignore[assignment, misc]
# -------------------------------------------------------------
@@ -72,7 +72,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: str, bases: TBD, clsdict: Dict[str, Any]) -> TBD:
+ def __new__(cls, name: str, bases: Tuple, clsdict: Dict[str, Any]) -> 'MetaParserBuilder':
"""
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."""
@@ -177,7 +177,7 @@ class SectionConstraint(Generic[T_ConfigParser]):
class _OMD(OrderedDict_OMD):
"""Ordered multi-dict."""
- def __setitem__(self, key: str, value: _T) -> None: # type: ignore[override]
+ def __setitem__(self, key: str, value: _T) -> None:
super(_OMD, self).__setitem__(key, [value])
def add(self, key: str, value: Any) -> None:
@@ -203,8 +203,8 @@ class _OMD(OrderedDict_OMD):
prior = super(_OMD, self).__getitem__(key)
prior[-1] = value
- def get(self, key: str, default: Union[_T, None] = None) -> Union[_T, None]: # type: ignore
- return super(_OMD, self).get(key, [default])[-1] # type: ignore
+ def get(self, key: str, default: Union[_T, None] = None) -> Union[_T, None]:
+ return super(_OMD, self).get(key, [default])[-1]
def getall(self, key: str) -> List[_T]:
return super(_OMD, self).__getitem__(key)
@@ -236,7 +236,8 @@ def get_config_path(config_level: Lit_config_levels) -> str:
raise ValueError("No repo to get repository configuration from. Use Repo._get_config_path")
else:
# Should not reach here. Will raise ValueError if does. Static typing will warn missing elifs
- assert_never(config_level, ValueError(f"Invalid configuration level: {config_level!r}"))
+ assert_never(config_level, # type: ignore[unreachable]
+ ValueError(f"Invalid configuration level: {config_level!r}"))
class GitConfigParser(cp.RawConfigParser, metaclass=MetaParserBuilder):
@@ -299,10 +300,10 @@ class GitConfigParser(cp.RawConfigParser, metaclass=MetaParserBuilder):
:param repo: Reference to repository to use if [includeIf] sections are found in configuration files.
"""
- cp.RawConfigParser.__init__(self, dict_type=_OMD) # type: ignore[arg-type]
- self._dict: Callable[..., _OMD] # type: ignore[assignment] # mypy/typeshed bug
- self._defaults: _OMD # type: ignore[assignment] # mypy/typeshed bug
- self._sections: _OMD # type: ignore[assignment] # mypy/typeshed bug
+ cp.RawConfigParser.__init__(self, dict_type=_OMD)
+ self._dict: Callable[..., _OMD] # type: ignore # mypy/typeshed bug?
+ self._defaults: _OMD
+ self._sections: _OMD # type: ignore # mypy/typeshed bug?
# Used in python 3, needs to stay in sync with sections for underlying implementation to work
if not hasattr(self, '_proxies'):
@@ -617,12 +618,12 @@ class GitConfigParser(cp.RawConfigParser, metaclass=MetaParserBuilder):
def write_section(name: str, section_dict: _OMD) -> None:
fp.write(("[%s]\n" % name).encode(defenc))
- values: Sequence[Union[str, bytes, int, float, bool]]
+ values: Sequence[str] # runtime only gets str in tests, but should be whatever _OMD stores
+ v: str
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__
@@ -630,7 +631,8 @@ class GitConfigParser(cp.RawConfigParser, metaclass=MetaParserBuilder):
if self._defaults:
write_section(cp.DEFAULTSECT, self._defaults)
- value: TBD
+ value: _OMD
+
for name, value in self._sections.items():
write_section(name, value)