Skip to content

Commit

Permalink
Readd with_metaclass shim
Browse files Browse the repository at this point in the history
  • Loading branch information
Yobmod committed Jul 24, 2021
1 parent d812818 commit cb5688d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 16 additions & 0 deletions git/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
defenc,
force_text,
is_win,
with_metaclass,
)

from git.util import LockFile
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit cb5688d

Please sign in to comment.