From 16f0607ed29f20c09e89f2cacc0e28e982309d60 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Mon, 5 Jul 2021 12:31:00 +0100 Subject: Improve typing of config_levels, add assert_never() --- git/objects/submodule/util.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'git/objects/submodule/util.py') diff --git a/git/objects/submodule/util.py b/git/objects/submodule/util.py index 5290000b..1db473df 100644 --- a/git/objects/submodule/util.py +++ b/git/objects/submodule/util.py @@ -5,11 +5,18 @@ from io import BytesIO import weakref +# typing ----------------------------------------------------------------------- + from typing import Any, TYPE_CHECKING, Union +from git.types import PathLike + if TYPE_CHECKING: from .base import Submodule from weakref import ReferenceType + from git.repo import Repo + from git.refs import Head + __all__ = ('sm_section', 'sm_name', 'mkhead', 'find_first_remote_branch', 'SubmoduleConfigParser') @@ -28,7 +35,7 @@ def sm_name(section): return section[11:-1] -def mkhead(repo, path): +def mkhead(repo: 'Repo', path: PathLike) -> 'Head': """:return: New branch/head instance""" return git.Head(repo, git.Head.to_full_path(path)) -- cgit v1.2.1 From 23b5d6b434551e1df1c954ab5d2c0166f080fba8 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Mon, 5 Jul 2021 15:42:46 +0100 Subject: Add types to submodule.util.py --- git/objects/submodule/util.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'git/objects/submodule/util.py') 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 -- cgit v1.2.1 From 6aebb73bb818d91c275b94b6052d8ce4ddc113c6 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 16:01:18 +0100 Subject: Rmv submodule types --- git/objects/submodule/util.py | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'git/objects/submodule/util.py') diff --git a/git/objects/submodule/util.py b/git/objects/submodule/util.py index cde18d08..5290000b 100644 --- a/git/objects/submodule/util.py +++ b/git/objects/submodule/util.py @@ -5,20 +5,11 @@ from io import BytesIO import weakref -# typing ----------------------------------------------------------------------- - -from typing import Any, Sequence, TYPE_CHECKING, Union - -from git.types import PathLike +from typing import Any, TYPE_CHECKING, Union if TYPE_CHECKING: from .base import Submodule 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', 'SubmoduleConfigParser') @@ -26,23 +17,23 @@ __all__ = ('sm_section', 'sm_name', 'mkhead', 'find_first_remote_branch', #{ Utilities -def sm_section(name: str) -> str: +def sm_section(name): """:return: section title used in .gitmodules configuration file""" - return f'submodule {name}' + return 'submodule "%s"' % name -def sm_name(section: str) -> str: +def sm_name(section): """:return: name of the submodule as parsed from the section name""" section = section.strip() return section[11:-1] -def mkhead(repo: 'Repo', path: PathLike) -> 'Head': +def mkhead(repo, path): """:return: New branch/head instance""" return git.Head(repo, git.Head.to_full_path(path)) -def find_first_remote_branch(remotes: Sequence['Remote'], branch_name: str) -> 'RemoteReference': +def find_first_remote_branch(remotes, branch_name): """Find the remote branch matching the name of the given branch or raise InvalidGitRepositoryError""" for remote in remotes: try: @@ -101,7 +92,7 @@ class SubmoduleConfigParser(GitConfigParser): #{ Overridden Methods def write(self) -> None: - rval: None = super(SubmoduleConfigParser, self).write() + rval = super(SubmoduleConfigParser, self).write() self.flush_to_index() return rval # END overridden methods -- cgit v1.2.1 From 1fd9e8c43cadb6459438a9405cd993c005689f53 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 16:20:52 +0100 Subject: Re-add submodule.util.py types --- git/objects/submodule/util.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'git/objects/submodule/util.py') diff --git a/git/objects/submodule/util.py b/git/objects/submodule/util.py index 5290000b..cde18d08 100644 --- a/git/objects/submodule/util.py +++ b/git/objects/submodule/util.py @@ -5,11 +5,20 @@ from io import BytesIO import weakref -from typing import Any, TYPE_CHECKING, Union +# typing ----------------------------------------------------------------------- + +from typing import Any, Sequence, TYPE_CHECKING, Union + +from git.types import PathLike if TYPE_CHECKING: from .base import Submodule 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', 'SubmoduleConfigParser') @@ -17,23 +26,23 @@ __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] -def mkhead(repo, path): +def mkhead(repo: 'Repo', path: PathLike) -> 'Head': """:return: New branch/head instance""" 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: @@ -92,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 -- cgit v1.2.1 From 1eceb8938ec98fad3a3aa2b8ffae5be8b7653976 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Tue, 6 Jul 2021 16:29:02 +0100 Subject: Fix submodule.util.py types --- git/objects/submodule/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/objects/submodule/util.py') diff --git a/git/objects/submodule/util.py b/git/objects/submodule/util.py index cde18d08..a776af88 100644 --- a/git/objects/submodule/util.py +++ b/git/objects/submodule/util.py @@ -28,7 +28,7 @@ __all__ = ('sm_section', 'sm_name', 'mkhead', 'find_first_remote_branch', def sm_section(name: str) -> str: """:return: section title used in .gitmodules configuration file""" - return f'submodule {name}' + return f'submodule "{name}"' def sm_name(section: str) -> str: -- cgit v1.2.1