Skip to content

Commit f40d129

Browse files
committed
improve types according to test/test_archive.py
1 parent 7528441 commit f40d129

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

pygit2/_pygit2.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Iterator, Literal, Optional, overload, Type, TypedDict
22
from io import IOBase, DEFAULT_BUFFER_SIZE
33
from queue import Queue
4+
import tarfile
45
from threading import Event
56
from . import Index
67
from .enums import (
@@ -290,6 +291,7 @@ class Object:
290291
type: 'Literal[GIT_OBJ_COMMIT] | Literal[GIT_OBJ_TREE] | Literal[GIT_OBJ_TAG] | Literal[GIT_OBJ_BLOB]'
291292
type_str: "Literal['commit'] | Literal['tree'] | Literal['tag'] | Literal['blob']"
292293
author: Signature
294+
committer: Signature
293295
tree: Tree
294296
@overload
295297
def peel(
@@ -838,6 +840,13 @@ class Repository:
838840
def walk(
839841
self, oid: _OidArg | None, sort_mode: SortMode = SortMode.NONE
840842
) -> Walker: ...
843+
def write_archive(
844+
self,
845+
treeish: str | Tree | Object | Oid,
846+
archive: tarfile.TarFile,
847+
timestamp: int | None = None,
848+
prefix: str = '',
849+
) -> None: ...
841850

842851
class RevSpec:
843852
flags: int

pygit2/index.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Index:
4242
# a proper implementation in some places: e.g. checking the index type
4343
# from C code (see Tree_diff_to_index)
4444

45-
def __init__(self, path=None):
45+
def __init__(self, path: str | None = None) -> None:
4646
"""Create a new Index
4747
4848
If path is supplied, the read and write methods will use that path
@@ -69,13 +69,13 @@ def from_c(cls, repo, ptr):
6969
def _pointer(self):
7070
return bytes(ffi.buffer(self._cindex)[:])
7171

72-
def __del__(self):
72+
def __del__(self) -> None:
7373
C.git_index_free(self._index)
7474

75-
def __len__(self):
75+
def __len__(self) -> int:
7676
return C.git_index_entrycount(self._index)
7777

78-
def __contains__(self, path):
78+
def __contains__(self, path) -> bool:
7979
err = C.git_index_find(ffi.NULL, self._index, to_bytes(path))
8080
if err == C.GIT_ENOTFOUND:
8181
return False

test/test_archive.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@
2626
from pathlib import Path
2727
import tarfile
2828

29-
from pygit2 import Index, Oid, Tree, Object
29+
from pygit2 import Index, Oid, Tree, Object, Repository
3030

3131

3232
TREE_HASH = 'fd937514cb799514d4b81bb24c5fcfeb6472b245'
3333
COMMIT_HASH = '2be5719152d4f82c7302b1c0932d8e5f0a4a0e98'
3434

3535

36-
def check_writing(repo, treeish, timestamp=None):
36+
def check_writing(
37+
repo: Repository, treeish: str | Tree | Oid | Object, timestamp: int | None = None
38+
) -> None:
3739
archive = tarfile.open('foo.tar', mode='w')
3840
repo.write_archive(treeish, archive)
3941

@@ -55,13 +57,13 @@ def check_writing(repo, treeish, timestamp=None):
5557
path.unlink()
5658

5759

58-
def test_write_tree(testrepo):
60+
def test_write_tree(testrepo: Repository) -> None:
5961
check_writing(testrepo, TREE_HASH)
6062
check_writing(testrepo, Oid(hex=TREE_HASH))
6163
check_writing(testrepo, testrepo[TREE_HASH])
6264

6365

64-
def test_write_commit(testrepo):
66+
def test_write_commit(testrepo: Repository) -> None:
6567
commit_timestamp = testrepo[COMMIT_HASH].committer.time
6668
check_writing(testrepo, COMMIT_HASH, commit_timestamp)
6769
check_writing(testrepo, Oid(hex=COMMIT_HASH), commit_timestamp)

0 commit comments

Comments
 (0)