Skip to content

Commit 18c777b

Browse files
authored
Merge pull request #1282 from Yobmod/main
Start adding types to Submodule, add py.typed to manifest
2 parents 8ad4f59 + d4a9eab commit 18c777b

20 files changed

+19128
-203
lines changed

Diff for: MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ include README.md
66
include VERSION
77
include requirements.txt
88
include test-requirements.txt
9+
include git/py.typed
910

1011
recursive-include doc *
1112
recursive-exclude test *

Diff for: git/cmd.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,11 @@ def polish_url(cls, url: str, is_cygwin: Literal[False] = ...) -> str:
342342

343343
@overload
344344
@classmethod
345-
def polish_url(cls, url: PathLike, is_cygwin: Union[None, bool] = None) -> str:
345+
def polish_url(cls, url: str, is_cygwin: Union[None, bool] = None) -> str:
346346
...
347347

348348
@classmethod
349-
def polish_url(cls, url: PathLike, is_cygwin: Union[None, bool] = None) -> PathLike:
349+
def polish_url(cls, url: str, is_cygwin: Union[None, bool] = None) -> PathLike:
350350
if is_cygwin is None:
351351
is_cygwin = cls.is_cygwin()
352352

Diff for: git/config.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
import configparser as cp
3131

32-
from pathlib import Path
33-
3432
# typing-------------------------------------------------------
3533

3634
from typing import Any, Callable, IO, List, Dict, Sequence, TYPE_CHECKING, Tuple, Union, cast, overload
@@ -330,7 +328,7 @@ def _acquire_lock(self) -> None:
330328
"Write-ConfigParsers can operate on a single file only, multiple files have been passed")
331329
# END single file check
332330

333-
if isinstance(self._file_or_files, (str, Path)): # cannot narrow by os._pathlike until 3.5 dropped
331+
if isinstance(self._file_or_files, (str, os.PathLike)):
334332
file_or_files = self._file_or_files
335333
else:
336334
file_or_files = cast(IO, self._file_or_files).name
@@ -696,6 +694,16 @@ def read_only(self) -> bool:
696694
""":return: True if this instance may change the configuration file"""
697695
return self._read_only
698696

697+
@overload
698+
def get_value(self, section: str, option: str, default: str
699+
) -> str:
700+
...
701+
702+
@overload
703+
def get_value(self, section: str, option: str, default: float
704+
) -> float:
705+
...
706+
699707
def get_value(self, section: str, option: str, default: Union[int, float, str, bool, None] = None
700708
) -> Union[int, float, str, bool]:
701709
# can default or return type include bool?

Diff for: git/index/base.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
6-
from git.refs.reference import Reference
6+
77
import glob
88
from io import BytesIO
99
import os
@@ -74,6 +74,8 @@
7474
if TYPE_CHECKING:
7575
from subprocess import Popen
7676
from git.repo import Repo
77+
from git.refs.reference import Reference
78+
from git.util import Actor
7779

7880

7981
StageType = int
@@ -966,8 +968,8 @@ def move(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, Submodule]]
966968

967969
return out
968970

969-
def commit(self, message: str, parent_commits=None, head: bool = True, author: str = None,
970-
committer: str = None, author_date: str = None, commit_date: str = None,
971+
def commit(self, message: str, parent_commits=None, head: bool = True, author: Union[None, 'Actor'] = None,
972+
committer: Union[None, 'Actor'] = None, author_date: str = None, commit_date: str = None,
971973
skip_hooks: bool = False) -> Commit:
972974
"""Commit the current default index file, creating a commit object.
973975
For more information on the arguments, see tree.commit.
@@ -1191,7 +1193,7 @@ def handle_stderr(proc: 'Popen[bytes]', iter_checked_out_files: Iterable[PathLik
11911193
assert "Should not reach this point"
11921194

11931195
@default_index
1194-
def reset(self, commit: Union[Commit, Reference, str] = 'HEAD', working_tree: bool = False,
1196+
def reset(self, commit: Union[Commit, 'Reference', str] = 'HEAD', working_tree: bool = False,
11951197
paths: Union[None, Iterable[PathLike]] = None,
11961198
head: bool = False, **kwargs: Any) -> 'IndexFile':
11971199
"""Reset the index to reflect the tree at the given commit. This will not

Diff for: git/objects/base.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717

1818
from typing import Any, TYPE_CHECKING, Optional, Union
1919

20-
from git.types import PathLike
20+
from git.types import PathLike, Commit_ish
2121

2222
if TYPE_CHECKING:
2323
from git.repo import Repo
2424
from gitdb.base import OStream
2525
from .tree import Tree
2626
from .blob import Blob
27-
from .tag import TagObject
28-
from .commit import Commit
27+
from .submodule.base import Submodule
28+
29+
IndexObjUnion = Union['Tree', 'Blob', 'Submodule']
2930

3031
# --------------------------------------------------------------------------
3132

@@ -71,7 +72,7 @@ def new(cls, repo: 'Repo', id): # @ReservedAssignment
7172
return repo.rev_parse(str(id))
7273

7374
@classmethod
74-
def new_from_sha(cls, repo: 'Repo', sha1: bytes) -> Union['Commit', 'TagObject', 'Tree', 'Blob']:
75+
def new_from_sha(cls, repo: 'Repo', sha1: bytes) -> Commit_ish:
7576
"""
7677
:return: new object instance of a type appropriate to represent the given
7778
binary sha1

0 commit comments

Comments
 (0)