summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--git/compat.py16
-rw-r--r--git/config.py3
2 files changed, 18 insertions, 1 deletions
diff --git a/git/compat.py b/git/compat.py
index b3b6ab81..7a0a15d2 100644
--- a/git/compat.py
+++ b/git/compat.py
@@ -97,3 +97,19 @@ def win_encode(s: Optional[AnyStr]) -> Optional[bytes]:
elif s is not None:
raise TypeError('Expected bytes or text, but got %r' % (s,))
return None
+
+
+# type: ignore ## mypy cannot understand dynamic class creation
+def with_metaclass(meta: Type[Any], *bases: Any) -> TBD:
+ """copied from https://github.com/Byron/bcore/blob/master/src/python/butility/future.py#L15"""
+
+ class metaclass(meta): # type: ignore
+ __call__ = type.__call__
+ __init__ = type.__init__ # type: ignore
+
+ def __new__(cls, name: str, nbases: Optional[Tuple[int, ...]], d: Dict[str, Any]) -> TBD:
+ if nbases is None:
+ return type.__new__(cls, name, (), d)
+ return meta(name, bases, d)
+
+ return metaclass(meta.__name__ + 'Helper', None, {}) # type: ignore
diff --git a/git/config.py b/git/config.py
index 76200f31..b0ac8ff5 100644
--- a/git/config.py
+++ b/git/config.py
@@ -19,6 +19,7 @@ from git.compat import (
defenc,
force_text,
is_win,
+ with_metaclass,
)
from git.util import LockFile
@@ -228,7 +229,7 @@ def get_config_path(config_level: Lit_config_levels) -> str:
assert_never(config_level, ValueError(f"Invalid configuration level: {config_level!r}"))
-class GitConfigParser(cp.RawConfigParser, metaclass=MetaParserBuilder):
+class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser)): # type: ignore ## mypy does not understand dynamic class creation # noqa: E501
"""Implements specifics required to read git style configuration files.