diff options
Diffstat (limited to 'git')
-rw-r--r-- | git/config.py | 9 | ||||
-rw-r--r-- | git/objects/submodule/util.py | 14 |
2 files changed, 13 insertions, 10 deletions
diff --git a/git/config.py b/git/config.py index 6931dd12..bfdfd916 100644 --- a/git/config.py +++ b/git/config.py @@ -38,6 +38,7 @@ from git.types import Lit_config_levels, ConfigLevels_Tup, PathLike, TBD, assert if TYPE_CHECKING: from git.repo.base import Repo + from io import BytesIO # ------------------------------------------------------------- @@ -274,7 +275,7 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje # list of RawConfigParser methods able to change the instance _mutating_methods_ = ("add_section", "remove_section", "remove_option", "set") - def __init__(self, file_or_files: Union[None, PathLike, IO, Sequence[Union[PathLike, IO]]] = None, + def __init__(self, file_or_files: Union[None, PathLike, BytesIO, Sequence[Union[PathLike, BytesIO]]] = None, read_only: bool = True, merge_includes: bool = True, config_level: Union[Lit_config_levels, None] = None, repo: Union['Repo', None] = None) -> None: @@ -303,7 +304,7 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje self._proxies = self._dict() if file_or_files is not None: - self._file_or_files: Union[PathLike, IO, Sequence[Union[PathLike, IO]]] = file_or_files + self._file_or_files: Union[PathLike, 'BytesIO', Sequence[Union[PathLike, 'BytesIO']]] = file_or_files else: if config_level is None: if read_only: @@ -650,7 +651,7 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje a file lock""" self._assure_writable("write") if not self._dirty: - return + return None if isinstance(self._file_or_files, (list, tuple)): raise AssertionError("Cannot write back if there is not exactly a single file to write to, have %i files" @@ -675,7 +676,7 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje with open(fp, "wb") as fp_open: self._write(fp_open) else: - fp = cast(IO, fp) + fp = cast(BytesIO, fp) fp.seek(0) # make sure we do not overwrite into an existing file if hasattr(fp, 'truncate'): diff --git a/git/objects/submodule/util.py b/git/objects/submodule/util.py index 1db473df..cde18d08 100644 --- a/git/objects/submodule/util.py +++ b/git/objects/submodule/util.py @@ -7,7 +7,7 @@ import weakref # typing ----------------------------------------------------------------------- -from typing import Any, TYPE_CHECKING, Union +from typing import Any, Sequence, TYPE_CHECKING, Union from git.types import PathLike @@ -16,6 +16,8 @@ if TYPE_CHECKING: from weakref import ReferenceType from git.repo import Repo from git.refs import Head + from git import Remote + from git.refs import RemoteReference __all__ = ('sm_section', 'sm_name', 'mkhead', 'find_first_remote_branch', @@ -24,12 +26,12 @@ __all__ = ('sm_section', 'sm_name', 'mkhead', 'find_first_remote_branch', #{ Utilities -def sm_section(name): +def sm_section(name: str) -> str: """:return: section title used in .gitmodules configuration file""" - return 'submodule "%s"' % name + return f'submodule {name}' -def sm_name(section): +def sm_name(section: str) -> str: """:return: name of the submodule as parsed from the section name""" section = section.strip() return section[11:-1] @@ -40,7 +42,7 @@ def mkhead(repo: 'Repo', path: PathLike) -> 'Head': return git.Head(repo, git.Head.to_full_path(path)) -def find_first_remote_branch(remotes, branch_name): +def find_first_remote_branch(remotes: Sequence['Remote'], branch_name: str) -> 'RemoteReference': """Find the remote branch matching the name of the given branch or raise InvalidGitRepositoryError""" for remote in remotes: try: @@ -99,7 +101,7 @@ class SubmoduleConfigParser(GitConfigParser): #{ Overridden Methods def write(self) -> None: - rval = super(SubmoduleConfigParser, self).write() + rval: None = super(SubmoduleConfigParser, self).write() self.flush_to_index() return rval # END overridden methods |