Skip to content

Commit e08390d

Browse files
committed
add types to Remote
1 parent 58270d3 commit e08390d

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

pygit2/_pygit2.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ class RemoteCollection:
696696
def __len__(self) -> int: ...
697697
def __iter__(self): ...
698698
def __getitem__(self, name: str | int) -> Remote: ...
699-
def names(self) -> Generator[str, None, None]: ...
699+
def names(self) -> Generator[str | None, None, None]: ...
700700
def create(self, name: str, url: str, fetch: str | None = None) -> Remote: ...
701701
def create_anonymous(self, url: str) -> Remote: ...
702702
def rename(self, name: str, new_name: str) -> list[str]: ...

pygit2/remotes.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from __future__ import annotations
2727

28-
from typing import TYPE_CHECKING, Any, TypedDict
28+
from typing import TYPE_CHECKING, Any, Literal, TypedDict
2929

3030
# Import from pygit2
3131
from pygit2 import RemoteCallbacks
@@ -46,6 +46,7 @@
4646

4747
# Need BaseRepository for type hints, but don't let it cause a circular dependency
4848
if TYPE_CHECKING:
49+
from ._libgit2.ffi import GitRemoteC
4950
from .repository import BaseRepository
5051

5152

@@ -92,34 +93,39 @@ def __init__(self, tp: Any) -> None:
9293

9394

9495
class Remote:
95-
def __init__(self, repo: BaseRepository, ptr):
96+
def __init__(self, repo: BaseRepository, ptr: 'GitRemoteC') -> None:
9697
"""The constructor is for internal use only."""
9798
self._repo = repo
9899
self._remote = ptr
99100
self._stored_exception = None
100101

101-
def __del__(self):
102+
def __del__(self) -> None:
102103
C.git_remote_free(self._remote)
103104

104105
@property
105-
def name(self):
106+
def name(self) -> str | None:
106107
"""Name of the remote"""
107108

108109
return maybe_string(C.git_remote_name(self._remote))
109110

110111
@property
111-
def url(self):
112+
def url(self) -> str | None:
112113
"""Url of the remote"""
113114

114115
return maybe_string(C.git_remote_url(self._remote))
115116

116117
@property
117-
def push_url(self):
118+
def push_url(self) -> str | None:
118119
"""Push url of the remote"""
119120

120121
return maybe_string(C.git_remote_pushurl(self._remote))
121122

122-
def connect(self, callbacks=None, direction=C.GIT_DIRECTION_FETCH, proxy=None):
123+
def connect(
124+
self,
125+
callbacks: RemoteCallbacks | None = None,
126+
direction: int = C.GIT_DIRECTION_FETCH,
127+
proxy: None | bool | str = None,
128+
) -> None:
123129
"""Connect to the remote.
124130
125131
Parameters:
@@ -144,13 +150,13 @@ def connect(self, callbacks=None, direction=C.GIT_DIRECTION_FETCH, proxy=None):
144150

145151
def fetch(
146152
self,
147-
refspecs=None,
148-
message=None,
149-
callbacks=None,
153+
refspecs: list[str] | None = None,
154+
message: str | None = None,
155+
callbacks: RemoteCallbacks | None = None,
150156
prune: FetchPrune = FetchPrune.UNSPECIFIED,
151-
proxy=None,
152-
depth=0,
153-
):
157+
proxy: None | Literal[True] | str = None,
158+
depth: int = 0,
159+
) -> TransferProgress:
154160
"""Perform a fetch against this remote. Returns a <TransferProgress>
155161
object.
156162
@@ -241,7 +247,7 @@ def prune(self, callbacks: RemoteCallbacks | None = None) -> None:
241247
payload.check_error(err)
242248

243249
@property
244-
def refspec_count(self):
250+
def refspec_count(self) -> int:
245251
"""Total number of refspecs in this remote"""
246252

247253
return C.git_remote_refspec_count(self._remote)
@@ -252,7 +258,7 @@ def get_refspec(self, n: int) -> Refspec:
252258
return Refspec(self, spec)
253259

254260
@property
255-
def fetch_refspecs(self):
261+
def fetch_refspecs(self) -> list[str]:
256262
"""Refspecs that will be used for fetching"""
257263

258264
specs = ffi.new('git_strarray *')
@@ -261,7 +267,7 @@ def fetch_refspecs(self):
261267
return strarray_to_strings(specs)
262268

263269
@property
264-
def push_refspecs(self):
270+
def push_refspecs(self) -> list[str]:
265271
"""Refspecs that will be used for pushing"""
266272

267273
specs = ffi.new('git_strarray *')

pygit2/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from ._libgit2.ffi import ArrayC, GitStrrayC, char, char_pointer
4646

4747

48-
def maybe_string(ptr: char_pointer) -> str | None:
48+
def maybe_string(ptr: 'char_pointer') -> str | None:
4949
if not ptr:
5050
return None
5151

0 commit comments

Comments
 (0)