Skip to content

Commit 38f5157

Browse files
committed
add type check to conf_encoding (in thoery could be bool or int)
1 parent 9d844a6 commit 38f5157

File tree

4 files changed

+6
-959
lines changed

4 files changed

+6
-959
lines changed

git/cmd.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,16 @@ def pump_stream(cmdline: List[str], name: str, stream: Union[BinaryIO, TextIO],
109109
else:
110110
handler(line)
111111
except Exception as ex:
112-
log.error(f"Pumping {name!r} of cmd({remove_password_if_present(cmdline)})} failed due to: {ex!r}")
112+
log.error(f"Pumping {name!r} of cmd({remove_password_if_present(cmdline)}) failed due to: {ex!r}")
113113
raise CommandError([f'<{name}-pump>'] + remove_password_if_present(cmdline), ex) from ex
114114
finally:
115115
stream.close()
116116

117-
118-
119117
if hasattr(process, 'proc'):
120118
process = cast('Git.AutoInterrupt', process)
121119
cmdline: str | Tuple[str, ...] | List[str] = getattr(process.proc, 'args', '')
122-
p_stdout = process.proc.stdout
123-
p_stderr = process.proc.stderr
120+
p_stdout = process.proc.stdout if process.proc else None
121+
p_stderr = process.proc.stderr if process.proc else None
124122
else:
125123
process = cast(Popen, process)
126124
cmdline = getattr(process, 'args', '')

git/config.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# typing-------------------------------------------------------
3232

3333
from typing import (Any, Callable, Generic, IO, List, Dict, Sequence,
34-
TYPE_CHECKING, Tuple, TypeVar, Union, cast, overload)
34+
TYPE_CHECKING, Tuple, TypeVar, Union, cast)
3535

3636
from git.types import Lit_config_levels, ConfigLevels_Tup, PathLike, assert_never, _T
3737

@@ -709,15 +709,6 @@ def read_only(self) -> bool:
709709
""":return: True if this instance may change the configuration file"""
710710
return self._read_only
711711

712-
@overload
713-
def get_value(self, section: str, option: str, default: None = None) -> Union[int, float, str, bool]: ...
714-
715-
@overload
716-
def get_value(self, section: str, option: str, default: str) -> str: ...
717-
718-
@overload
719-
def get_value(self, section: str, option: str, default: float) -> float: ...
720-
721712
def get_value(self, section: str, option: str, default: Union[int, float, str, bool, None] = None
722713
) -> Union[int, float, str, bool]:
723714
# can default or return type include bool?

git/objects/commit.py

+2
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ def create_from_tree(cls, repo: 'Repo', tree: Union[Tree, str], message: str,
446446
# assume utf8 encoding
447447
enc_section, enc_option = cls.conf_encoding.split('.')
448448
conf_encoding = cr.get_value(enc_section, enc_option, cls.default_encoding)
449+
if not isinstance(conf_encoding, str):
450+
raise TypeError("conf_encoding could not be coerced to str")
449451

450452
# if the tree is no object, make sure we create one - otherwise
451453
# the created commit object is invalid

0 commit comments

Comments
 (0)