Skip to content

Fix typing issues with delete_head and Remote.add #1346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion git/refs/head.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class Head(Reference):
k_config_remote_ref = "merge" # branch to merge from remote

@classmethod
def delete(cls, repo: 'Repo', *heads: 'Head', force: bool = False, **kwargs: Any) -> None:
def delete(cls, repo: 'Repo', *heads: 'Union[Head, str]', force: bool = False, **kwargs: Any) -> None:
"""Delete the given heads
:param force:
Expand Down
7 changes: 6 additions & 1 deletion git/refs/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ def iter_items(cls, repo: 'Repo', common_path: Union[PathLike, None] = None,
# super is Reference
return super(RemoteReference, cls).iter_items(repo, common_path)

# The Head implementation of delete also accepts strs, but this
# implementation does not. mypy doesn't have a way of representing
# tightening the types of arguments in subclasses and recommends Any or
# "type: ignore". (See https://github.com/python/typing/issues/241)
@ classmethod
def delete(cls, repo: 'Repo', *refs: 'RemoteReference', **kwargs: Any) -> None:
def delete(cls, repo: 'Repo', *refs: 'RemoteReference', # type: ignore
**kwargs: Any) -> None:
"""Delete the given remote references
:note:
Expand Down
4 changes: 3 additions & 1 deletion git/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,9 @@ def create(cls, repo: 'Repo', name: str, url: str, **kwargs: Any) -> 'Remote':
return cls(repo, name)

# add is an alias
add = create
@ classmethod
def add(cls, repo: 'Repo', name: str, url: str, **kwargs: Any) -> 'Remote':
return cls.create(repo, name, url, **kwargs)

@ classmethod
def remove(cls, repo: 'Repo', name: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def create_head(self, path: PathLike, commit: str = 'HEAD',
:return: newly created Head Reference"""
return Head.create(self, path, commit, logmsg, force)

def delete_head(self, *heads: 'Head', **kwargs: Any) -> None:
def delete_head(self, *heads: 'Union[str, Head]', **kwargs: Any) -> None:
"""Delete the given heads
:param kwargs: Additional keyword arguments to be passed to git-branch"""
Expand Down