From cb5688d65f4f7bc5735e5403e71094745e9a2a0b Mon Sep 17 00:00:00 2001 From: Yobmod Date: Sat, 24 Jul 2021 22:15:42 +0100 Subject: [PATCH] Readd with_metaclass shim --- git/compat.py | 16 ++++++++++++++++ git/config.py | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/git/compat.py b/git/compat.py index b3b6ab813..7a0a15d23 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 76200f310..b0ac8ff52 100644 --- a/git/config.py +++ b/git/config.py @@ -19,6 +19,7 @@ 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.