Skip to content

Commit 4b9ca92

Browse files
committed
Add types to refs/remote.py
1 parent 8dd3d0d commit 4b9ca92

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

‎git/refs/remote.py

+22-9
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,43 @@
22

33
from git.util import join_path
44

5-
import os.path as osp
6-
75
from .head import Head
86

97

108
__all__ = ["RemoteReference"]
119

10+
# typing ------------------------------------------------------------------
11+
12+
from typing import Any, NoReturn, Union, TYPE_CHECKING
13+
from git.types import PathLike
14+
15+
16+
if TYPE_CHECKING:
17+
from git.repo import Repo
18+
from git import Remote
19+
20+
# ------------------------------------------------------------------------------
21+
1222

1323
class RemoteReference(Head):
1424

1525
"""Represents a reference pointing to a remote head."""
1626
_common_path_default = Head._remote_common_path_default
1727

1828
@classmethod
19-
def iter_items(cls, repo, common_path=None, remote=None):
29+
def iter_items(cls, repo: 'Repo', common_path: Union[PathLike, None] = None,
30+
remote: Union['Remote', None] = None, *args: Any, **kwargs: Any
31+
) -> 'RemoteReference':
2032
"""Iterate remote references, and if given, constrain them to the given remote"""
2133
common_path = common_path or cls._common_path_default
2234
if remote is not None:
2335
common_path = join_path(common_path, str(remote))
2436
# END handle remote constraint
37+
# super is Reference
2538
return super(RemoteReference, cls).iter_items(repo, common_path)
2639

27-
@classmethod
28-
def delete(cls, repo, *refs, **kwargs):
40+
@ classmethod
41+
def delete(cls, repo: 'Repo', *refs: 'RemoteReference', **kwargs: Any) -> None:
2942
"""Delete the given remote references
3043
3144
:note:
@@ -37,16 +50,16 @@ def delete(cls, repo, *refs, **kwargs):
3750
# and delete remainders manually
3851
for ref in refs:
3952
try:
40-
os.remove(osp.join(repo.common_dir, ref.path))
53+
os.remove(os.path.join(repo.common_dir, ref.path))
4154
except OSError:
4255
pass
4356
try:
44-
os.remove(osp.join(repo.git_dir, ref.path))
57+
os.remove(os.path.join(repo.git_dir, ref.path))
4558
except OSError:
4659
pass
4760
# END for each ref
4861

49-
@classmethod
50-
def create(cls, *args, **kwargs):
62+
@ classmethod
63+
def create(cls, *args: Any, **kwargs: Any) -> NoReturn:
5164
"""Used to disable this method"""
5265
raise TypeError("Cannot explicitly create remote references")

0 commit comments

Comments
 (0)