Skip to content

Drop 3.6, increase type strictness #1311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
39d37d5
replace some TBDs wiht runtime types
Yobmod Jul 31, 2021
c878771
replace more TBDs wiht runtime types
Yobmod Jul 31, 2021
009017e
Merge branch 'gitpython-developers:main' into main
Yobmod Aug 2, 2021
2163322
increase mypy strictness (warn unused ignored)
Yobmod Aug 2, 2021
0525c17
Merge branch 'main' of https://github.com/Yobmod/GitPython
Yobmod Aug 2, 2021
91fce33
increase mypy strictness (warn unused ignored and warn unreachable)
Yobmod Aug 2, 2021
15ace87
rmv 3.6 from CI matrix
Yobmod Aug 2, 2021
bef2182
rmv 3.6 from setup.py
Yobmod Aug 2, 2021
270c3d7
rmv 3.6 README
Yobmod Aug 2, 2021
c3f3501
Add __future__.annotations to cmd.py
Yobmod Aug 2, 2021
829142d
Add __future__.annotations to cmd.py2
Yobmod Aug 2, 2021
13e0730
Fix parse_date typing
Yobmod Aug 2, 2021
730f119
Fix parse_date typing 2
Yobmod Aug 2, 2021
2fe13ca
Fix parse_date typing 3
Yobmod Aug 2, 2021
024b696
Fix parse_date typing 4
Yobmod Aug 2, 2021
e2f8367
Fix parse_date typing 5
Yobmod Aug 2, 2021
d30bc07
Fix parse_date typing 6
Yobmod Aug 2, 2021
6470ad4
Fix parse_date typing 7
Yobmod Aug 2, 2021
481f672
Add __future__.annotations to repo/base.py
Yobmod Aug 2, 2021
9de7310
Minor type fixes
Yobmod Aug 2, 2021
5647d58
Merge branch 'gitpython-developers:main' into main
Yobmod Aug 2, 2021
f34a39f
Test new union syntax (Pep604)
Yobmod Aug 2, 2021
3b53d28
Merge branch 'main' of https://github.com/Yobmod/GitPython
Yobmod Aug 2, 2021
4dd06c3
Test trailing comma in args (>py3.6?)
Yobmod Aug 2, 2021
94ae0c5
Test Dataclass in repo.base.blame()
Yobmod Aug 2, 2021
a3f5b13
Test Dataclass in repo.base.blame() 2
Yobmod Aug 2, 2021
a2a36e0
Test Dataclass in repo.base.blame() 3
Yobmod Aug 2, 2021
ed137cb
Test TypedDict in repo.base.blame() 2
Yobmod Aug 2, 2021
e4761ff
Test TypedDict in repo.base.blame() 1
Yobmod Aug 2, 2021
1aaa704
Test Dataclass in repo.base.blame() 4
Yobmod Aug 2, 2021
bc9bcf5
Test Dataclass in repo.base.blame() 5
Yobmod Aug 2, 2021
ad417ba
Test Dataclass in repo.base.blame() 6
Yobmod Aug 2, 2021
ecb1f79
Choose TypedDict!
Yobmod Aug 2, 2021
5aa8c34
Improve type of repo.blame_incremental()
Yobmod Aug 2, 2021
8b8aa16
Improve type of repo.currently_rebasing_on()
Yobmod Aug 2, 2021
84232f7
Add Typing :: Typed to setup.py
Yobmod Aug 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
replace some TBDs wiht runtime types
  • Loading branch information
Yobmod committed Jul 31, 2021
commit 39d37d550963a6a64e66ba3d6b9f4b077270a3ad
4 changes: 2 additions & 2 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
# Documentation
## @{

def handle_process_output(process: subprocess.Popen,
def handle_process_output(process: Union[subprocess.Popen, 'Git.AutoInterrupt'],
stdout_handler: Union[None,
Callable[[AnyStr], None],
Callable[[List[AnyStr]], None],
Expand All @@ -77,7 +77,7 @@ def handle_process_output(process: subprocess.Popen,
Callable[[AnyStr], None],
Callable[[List[AnyStr]], None]],
finalizer: Union[None,
Callable[[subprocess.Popen], None]] = None,
Callable[[Union[subprocess.Popen, 'Git.AutoInterrupt']], None]] = None,
decode_streams: bool = True) -> None:
"""Registers for notifications to learn that process output is ready to read, and dispatches lines to
the respective line handlers.
Expand Down
18 changes: 0 additions & 18 deletions git/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
Union,
overload,
)
from git.types import TBD

# ---------------------------------------------------------------------------


Expand Down Expand Up @@ -97,19 +95,3 @@ def win_encode(s: Optional[AnyStr]) -> Optional[bytes]:
elif s is not None:
raise TypeError('Expected bytes or text, but got %r' % (s,))
return None


# type: ignore ## mypy cannot understand dynamic class creation
def with_metaclass(meta: Type[Any], *bases: Any) -> TBD:
"""copied from https://github.com/Byron/bcore/blob/master/src/python/butility/future.py#L15"""

class metaclass(meta): # type: ignore
__call__ = type.__call__
__init__ = type.__init__ # type: ignore

def __new__(cls, name: str, nbases: Optional[Tuple[int, ...]], d: Dict[str, Any]) -> TBD:
if nbases is None:
return type.__new__(cls, name, (), d)
return meta(name, bases, d)

return metaclass(meta.__name__ + 'Helper', None, {}) # type: ignore
5 changes: 3 additions & 2 deletions git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
# typing ------------------------------------------------------------------

from typing import Any, Iterator, List, Match, Optional, Tuple, Type, TypeVar, Union, TYPE_CHECKING, cast
from git.types import PathLike, TBD, Literal
from git.types import PathLike, Literal

if TYPE_CHECKING:
from .objects.tree import Tree
from .objects import Commit
from git.repo.base import Repo
from git.objects.base import IndexObject
from subprocess import Popen
from git import Git

Lit_change_type = Literal['A', 'D', 'C', 'M', 'R', 'T', 'U']

Expand Down Expand Up @@ -442,7 +443,7 @@ def _pick_best_path(cls, path_match: bytes, rename_match: bytes, path_fallback_m
return None

@ classmethod
def _index_from_patch_format(cls, repo: 'Repo', proc: TBD) -> DiffIndex:
def _index_from_patch_format(cls, repo: 'Repo', proc: Union['Popen', 'Git.AutoInterrupt']) -> DiffIndex:
"""Create a new DiffIndex from the given text which must be in patch format
:param repo: is the repository we are operating on - it is required
:param stream: result of 'git diff' as a stream (supporting file protocol)
Expand Down
11 changes: 6 additions & 5 deletions git/index/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
from typing import (Any, BinaryIO, Callable, Dict, IO, Iterable, Iterator, List, NoReturn,
Sequence, TYPE_CHECKING, Tuple, Type, Union)

from git.types import Commit_ish, PathLike, TBD
from git.types import Commit_ish, PathLike

if TYPE_CHECKING:
from subprocess import Popen
Expand Down Expand Up @@ -181,7 +181,7 @@ def _deserialize(self, stream: IO) -> 'IndexFile':
self.version, self.entries, self._extension_data, _conten_sha = read_cache(stream)
return self

def _entries_sorted(self) -> List[TBD]:
def _entries_sorted(self) -> List[IndexEntry]:
""":return: list of entries, in a sorted fashion, first by path, then by stage"""
return sorted(self.entries.values(), key=lambda e: (e.path, e.stage))

Expand Down Expand Up @@ -427,8 +427,8 @@ def raise_exc(e: Exception) -> NoReturn:
# END path exception handling
# END for each path

def _write_path_to_stdin(self, proc: 'Popen', filepath: PathLike, item: TBD, fmakeexc: Callable[..., GitError],
fprogress: Callable[[PathLike, bool, TBD], None],
def _write_path_to_stdin(self, proc: 'Popen', filepath: PathLike, item: PathLike, fmakeexc: Callable[..., GitError],
fprogress: Callable[[PathLike, bool, PathLike], None],
read_from_stdout: bool = True) -> Union[None, str]:
"""Write path to proc.stdin and make sure it processes the item, including progress.

Expand Down Expand Up @@ -492,12 +492,13 @@ def unmerged_blobs(self) -> Dict[PathLike, List[Tuple[StageType, Blob]]]:
are at stage 3 will not have a stage 3 entry.
"""
is_unmerged_blob = lambda t: t[0] != 0
path_map: Dict[PathLike, List[Tuple[TBD, Blob]]] = {}
path_map: Dict[PathLike, List[Tuple[StageType, Blob]]] = {}
for stage, blob in self.iter_blobs(is_unmerged_blob):
path_map.setdefault(blob.path, []).append((stage, blob))
# END for each unmerged blob
for line in path_map.values():
line.sort()

return path_map

@ classmethod
Expand Down
3 changes: 2 additions & 1 deletion git/objects/submodule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No
:return: The newly created submodule instance
:note: works atomically, such that no change will be done if the repository
update fails for instance"""

if repo.bare:
raise InvalidGitRepositoryError("Cannot add submodules to bare repositories")
# END handle bare repos
Expand Down Expand Up @@ -434,7 +435,7 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No
url = urls[0]
else:
# clone new repo
kwargs: Dict[str, Union[bool, int, Sequence[TBD]]] = {'n': no_checkout}
kwargs: Dict[str, Union[bool, int, str, Sequence[TBD]]] = {'n': no_checkout}
if not branch_is_default:
kwargs['b'] = br.name
# END setup checkout-branch
Expand Down
2 changes: 1 addition & 1 deletion git/refs/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# typing ------------------------------------------------------------------

from typing import Any, Callable, Iterator, Type, Union, TYPE_CHECKING # NOQA
from git.types import Commit_ish, PathLike, TBD, Literal, _T # NOQA
from git.types import Commit_ish, PathLike, _T # NOQA

if TYPE_CHECKING:
from git.repo import Repo
Expand Down
4 changes: 2 additions & 2 deletions git/refs/symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

# typing ------------------------------------------------------------------

from typing import Any, Iterator, List, Match, Optional, Tuple, Type, TypeVar, Union, TYPE_CHECKING, cast # NOQA
from git.types import Commit_ish, PathLike, TBD, Literal # NOQA
from typing import Any, Iterator, List, Tuple, Type, TypeVar, Union, TYPE_CHECKING, cast # NOQA
from git.types import Commit_ish, PathLike # NOQA

if TYPE_CHECKING:
from git.repo import Repo
Expand Down
5 changes: 3 additions & 2 deletions git/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from git.remote import Remote
from git.repo.base import Repo
from git.config import GitConfigParser, SectionConstraint
from git import Git
# from git.objects.base import IndexObject


Expand Down Expand Up @@ -379,7 +380,7 @@ def get_user_id() -> str:
return "%s@%s" % (getpass.getuser(), platform.node())


def finalize_process(proc: subprocess.Popen, **kwargs: Any) -> None:
def finalize_process(proc: Union[subprocess.Popen, 'Git.AutoInterrupt'], **kwargs: Any) -> None:
"""Wait for the process (clone, fetch, pull or push) and handle its errors accordingly"""
# TODO: No close proc-streams??
proc.wait(**kwargs)
Expand Down Expand Up @@ -1033,7 +1034,7 @@ def __delitem__(self, index: Union[SupportsIndex, int, slice, str]) -> None:

class IterableClassWatcher(type):
""" Metaclass that watches """
def __init__(cls, name: str, bases: List, clsdict: Dict) -> None:
def __init__(cls, name: str, bases: Tuple, clsdict: Dict) -> None:
for base in bases:
if type(base) == IterableClassWatcher:
warnings.warn(f"GitPython Iterable subclassed by {name}. "
Expand Down