Skip to content

Commit 46c8425

Browse files
committed
move types for RemoteCollection to implementation
1 parent e08390d commit 46c8425

File tree

2 files changed

+22
-37
lines changed

2 files changed

+22
-37
lines changed

pygit2/_pygit2.pyi

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ from .filter import Filter
6262
from .index import MergeFileResult
6363
from .packbuilder import PackBuilder
6464
from .references import References
65-
from .remotes import Remote
65+
from .remotes import RemoteCollection
6666
from .repository import BaseRepository
6767
from .submodules import SubmoduleCollection
6868

@@ -691,21 +691,6 @@ class _LsRemotesDict(TypedDict):
691691
symref_target: str | None
692692
oid: Oid
693693

694-
class RemoteCollection:
695-
def __init__(self, repo: BaseRepository) -> None: ...
696-
def __len__(self) -> int: ...
697-
def __iter__(self): ...
698-
def __getitem__(self, name: str | int) -> Remote: ...
699-
def names(self) -> Generator[str | None, None, None]: ...
700-
def create(self, name: str, url: str, fetch: str | None = None) -> Remote: ...
701-
def create_anonymous(self, url: str) -> Remote: ...
702-
def rename(self, name: str, new_name: str) -> list[str]: ...
703-
def delete(self, name: str) -> None: ...
704-
def set_url(self, name: str, url: str) -> None: ...
705-
def set_push_url(self, name: str, url: str) -> None: ...
706-
def add_fetch(self, name: str, refspec: str) -> None: ...
707-
def add_push(self, name: str, refspec: str) -> None: ...
708-
709694
class Branches:
710695
local: 'Branches'
711696
remote: 'Branches'

pygit2/remotes.py

Lines changed: 21 additions & 21 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, Literal, TypedDict
28+
from typing import TYPE_CHECKING, Any, Generator, Iterator, Literal, TypedDict
2929

3030
# Import from pygit2
3131
from pygit2 import RemoteCallbacks
@@ -340,24 +340,24 @@ class RemoteCollection:
340340
>>> repo.remotes["origin"]
341341
"""
342342

343-
def __init__(self, repo: BaseRepository):
343+
def __init__(self, repo: BaseRepository) -> None:
344344
self._repo = repo
345345

346-
def __len__(self):
346+
def __len__(self) -> int:
347347
with utils.new_git_strarray() as names:
348348
err = C.git_remote_list(names, self._repo._repo)
349349
check_error(err)
350350
return names.count
351351

352-
def __iter__(self):
352+
def __iter__(self) -> Iterator[Remote]:
353353
cremote = ffi.new('git_remote **')
354354
for name in self._ffi_names():
355355
err = C.git_remote_lookup(cremote, self._repo._repo, name)
356356
check_error(err)
357357

358358
yield Remote(self._repo, cremote[0])
359359

360-
def __getitem__(self, name):
360+
def __getitem__(self, name: str | int) -> Remote:
361361
if isinstance(name, int):
362362
return list(self)[name]
363363

@@ -374,12 +374,12 @@ def _ffi_names(self):
374374
for i in range(names.count):
375375
yield names.strings[i]
376376

377-
def names(self):
377+
def names(self) -> Generator[str | None, None, None]:
378378
"""An iterator over the names of the available remotes."""
379379
for name in self._ffi_names():
380380
yield maybe_string(name)
381381

382-
def create(self, name, url, fetch=None) -> Remote:
382+
def create(self, name: str, url: str, fetch: str | None = None) -> Remote:
383383
"""Create a new remote with the given name and url. Returns a <Remote>
384384
object.
385385
@@ -388,31 +388,31 @@ def create(self, name, url, fetch=None) -> Remote:
388388
"""
389389
cremote = ffi.new('git_remote **')
390390

391-
name = to_bytes(name)
392-
url = to_bytes(url)
391+
name_bytes = to_bytes(name)
392+
url_bytes = to_bytes(url)
393393
if fetch:
394-
fetch = to_bytes(fetch)
394+
fetch_bytes = to_bytes(fetch)
395395
err = C.git_remote_create_with_fetchspec(
396-
cremote, self._repo._repo, name, url, fetch
396+
cremote, self._repo._repo, name_bytes, url_bytes, fetch_bytes
397397
)
398398
else:
399-
err = C.git_remote_create(cremote, self._repo._repo, name, url)
399+
err = C.git_remote_create(cremote, self._repo._repo, name_bytes, url_bytes)
400400

401401
check_error(err)
402402

403403
return Remote(self._repo, cremote[0])
404404

405-
def create_anonymous(self, url):
405+
def create_anonymous(self, url: str) -> Remote:
406406
"""Create a new anonymous (in-memory only) remote with the given URL.
407407
Returns a <Remote> object.
408408
"""
409409
cremote = ffi.new('git_remote **')
410-
url = to_bytes(url)
411-
err = C.git_remote_create_anonymous(cremote, self._repo._repo, url)
410+
url_bytes = to_bytes(url)
411+
err = C.git_remote_create_anonymous(cremote, self._repo._repo, url_bytes)
412412
check_error(err)
413413
return Remote(self._repo, cremote[0])
414414

415-
def rename(self, name, new_name):
415+
def rename(self, name: str, new_name: str) -> list[str]:
416416
"""Rename a remote in the configuration. The refspecs in standard
417417
format will be renamed.
418418
@@ -433,33 +433,33 @@ def rename(self, name, new_name):
433433
check_error(err)
434434
return strarray_to_strings(problems)
435435

436-
def delete(self, name):
436+
def delete(self, name: str) -> None:
437437
"""Remove a remote from the configuration
438438
439439
All remote-tracking branches and configuration settings for the remote will be removed.
440440
"""
441441
err = C.git_remote_delete(self._repo._repo, to_bytes(name))
442442
check_error(err)
443443

444-
def set_url(self, name, url):
444+
def set_url(self, name: str, url: str) -> None:
445445
"""Set the URL for a remote"""
446446
err = C.git_remote_set_url(self._repo._repo, to_bytes(name), to_bytes(url))
447447
check_error(err)
448448

449-
def set_push_url(self, name, url):
449+
def set_push_url(self, name: str, url: str) -> None:
450450
"""Set the push-URL for a remote"""
451451
err = C.git_remote_set_pushurl(self._repo._repo, to_bytes(name), to_bytes(url))
452452
check_error(err)
453453

454-
def add_fetch(self, name, refspec):
454+
def add_fetch(self, name: str, refspec: str) -> None:
455455
"""Add a fetch refspec (str) to the remote"""
456456

457457
err = C.git_remote_add_fetch(
458458
self._repo._repo, to_bytes(name), to_bytes(refspec)
459459
)
460460
check_error(err)
461461

462-
def add_push(self, name, refspec):
462+
def add_push(self, name: str, refspec: str) -> None:
463463
"""Add a push refspec (str) to the remote"""
464464

465465
err = C.git_remote_add_push(self._repo._repo, to_bytes(name), to_bytes(refspec))

0 commit comments

Comments
 (0)