From 5f4b4dbff46fae4c899f5573aea5a7266a41eeeb Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Mon, 20 Sep 2021 13:53:42 -0700 Subject: Fix typing issues with delete_head and Remote.add delete_head and Head.delete historically accept either Head objects or a str name of a head. Adjust the typing to match. This unfortunately requires suppressing type warnings in the signature of RemoteReference.delete, since it inherits from Head but does not accept str (since it needs access to the richer data of RemoteReference). Using assignment to make add an alias for create unfortunately confuses mypy, since it loses track of the fact that it's a classmethod and starts treating it like a staticmethod. Replace with a stub wrapper instead. --- git/refs/remote.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'git/refs/remote.py') diff --git a/git/refs/remote.py b/git/refs/remote.py index 9b74d87f..1b416bd0 100644 --- a/git/refs/remote.py +++ b/git/refs/remote.py @@ -37,8 +37,13 @@ class RemoteReference(Head): # 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: -- cgit v1.2.1