diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2021-04-23 21:36:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-23 21:36:48 +0800 |
commit | 4119a576251448793c07ebd080534948cad2f170 (patch) | |
tree | 7bffff60a75770882832eec5ff2efcac9741139f /git/compat.py | |
parent | 9f12c8c34371a7c46dad6788a48cf092042027ec (diff) | |
parent | 043e15fe140cfff8725d4f615f42fa1c55779402 (diff) | |
download | gitpython-4119a576251448793c07ebd080534948cad2f170.tar.gz |
Merge pull request #1226 from muggenhor/testing
ci: check types with mypy
Diffstat (limited to 'git/compat.py')
-rw-r--r-- | git/compat.py | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/git/compat.py b/git/compat.py index c9b83ba4..c4bd2aa3 100644 --- a/git/compat.py +++ b/git/compat.py @@ -18,7 +18,16 @@ from gitdb.utils.encoding import ( # typing -------------------------------------------------------------------- -from typing import IO, Any, AnyStr, Dict, Optional, Type, Union +from typing import ( + Any, + AnyStr, + Dict, + IO, + Optional, + Type, + Union, + overload, +) from git.types import TBD # --------------------------------------------------------------------------- @@ -30,6 +39,12 @@ is_darwin = (os.name == 'darwin') defenc = sys.getfilesystemencoding() +@overload +def safe_decode(s: None) -> None: ... + +@overload +def safe_decode(s: Union[IO[str], AnyStr]) -> str: ... + def safe_decode(s: Union[IO[str], AnyStr, None]) -> Optional[str]: """Safely decodes a binary string to unicode""" if isinstance(s, str): @@ -42,6 +57,12 @@ def safe_decode(s: Union[IO[str], AnyStr, None]) -> Optional[str]: raise TypeError('Expected bytes or text, but got %r' % (s,)) +@overload +def safe_encode(s: None) -> None: ... + +@overload +def safe_encode(s: AnyStr) -> bytes: ... + def safe_encode(s: Optional[AnyStr]) -> Optional[bytes]: """Safely encodes a binary string to unicode""" if isinstance(s, str): @@ -54,6 +75,12 @@ def safe_encode(s: Optional[AnyStr]) -> Optional[bytes]: raise TypeError('Expected bytes or text, but got %r' % (s,)) +@overload +def win_encode(s: None) -> None: ... + +@overload +def win_encode(s: AnyStr) -> bytes: ... + def win_encode(s: Optional[AnyStr]) -> Optional[bytes]: """Encode unicodes for process arguments on Windows.""" if isinstance(s, str): @@ -65,7 +92,6 @@ def win_encode(s: Optional[AnyStr]) -> Optional[bytes]: return None - def with_metaclass(meta: Type[Any], *bases: Any) -> 'metaclass': # type: ignore ## mypy cannot understand dynamic class creation """copied from https://github.com/Byron/bcore/blob/master/src/python/butility/future.py#L15""" |