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
Prev Previous commit
Next Next commit
replace more TBDs wiht runtime types
  • Loading branch information
Yobmod committed Jul 31, 2021
commit c878771e3a31c983a0c3468396ed33a532f87e98
12 changes: 6 additions & 6 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,27 +421,27 @@ def __getattr__(self, attr: str) -> Any:
return getattr(self.proc, attr)

# TODO: Bad choice to mimic `proc.wait()` but with different args.
def wait(self, stderr: Union[None, bytes] = b'') -> int:
def wait(self, stderr: Union[None, str, bytes] = b'') -> int:
"""Wait for the process and return its status code.

:param stderr: Previously read value of stderr, in case stderr is already closed.
:warn: may deadlock if output or error pipes are used and not handled separately.
:raise GitCommandError: if the return status is not 0"""
if stderr is None:
stderr = b''
stderr = force_bytes(data=stderr, encoding='utf-8')
stderr_b = b''
stderr_b = force_bytes(data=stderr, encoding='utf-8')

if self.proc is not None:
status = self.proc.wait()

def read_all_from_possibly_closed_stream(stream: Union[IO[bytes], None]) -> bytes:
if stream:
try:
return stderr + force_bytes(stream.read())
return stderr_b + force_bytes(stream.read())
except ValueError:
return stderr or b''
return stderr_b or b''
else:
return stderr or b''
return stderr_b or b''

if status != 0:
errstr = read_all_from_possibly_closed_stream(self.proc.stderr)
Expand Down
11 changes: 6 additions & 5 deletions git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from typing import (Any, Callable, Generic, IO, List, Dict, Sequence,
TYPE_CHECKING, Tuple, TypeVar, Union, cast, overload)

from git.types import Lit_config_levels, ConfigLevels_Tup, PathLike, TBD, assert_never, _T
from git.types import Lit_config_levels, ConfigLevels_Tup, PathLike, assert_never, _T

if TYPE_CHECKING:
from git.repo.base import Repo
Expand Down Expand Up @@ -72,7 +72,7 @@

class MetaParserBuilder(abc.ABCMeta):
"""Utlity class wrapping base-class methods into decorators that assure read-only properties"""
def __new__(cls, name: str, bases: TBD, clsdict: Dict[str, Any]) -> TBD:
def __new__(cls, name: str, bases: Tuple, clsdict: Dict[str, Any]) -> 'MetaParserBuilder':
"""
Equip all base-class methods with a needs_values decorator, and all non-const methods
with a set_dirty_and_flush_changes decorator in addition to that."""
Expand Down Expand Up @@ -617,20 +617,21 @@ def _write(self, fp: IO) -> None:
def write_section(name: str, section_dict: _OMD) -> None:
fp.write(("[%s]\n" % name).encode(defenc))

values: Sequence[Union[str, bytes, int, float, bool]]
values: Sequence[str] # runtime only gets str in tests, but should be whatever _OMD stores
v: str
for (key, values) in section_dict.items_all():
if key == "__name__":
continue

v: Union[str, bytes, int, float, bool]
for v in values:
fp.write(("\t%s = %s\n" % (key, self._value_to_string(v).replace('\n', '\n\t'))).encode(defenc))
# END if key is not __name__
# END section writing

if self._defaults:
write_section(cp.DEFAULTSECT, self._defaults)
value: TBD
value: _OMD

for name, value in self._sections.items():
write_section(name, value)

Expand Down
10 changes: 5 additions & 5 deletions git/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@

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

from typing import (Any, Callable, Dict, Iterator, List, NoReturn, Optional, Sequence, # NOQA[TC002]
from typing import (Any, Callable, Dict, Iterator, List, NoReturn, Optional, Sequence,
TYPE_CHECKING, Type, Union, cast, overload)

from git.types import PathLike, Literal, TBD, Commit_ish # NOQA[TC002]
from git.types import PathLike, Literal, Commit_ish

if TYPE_CHECKING:
from git.repo.base import Repo
Expand All @@ -50,7 +50,6 @@

flagKeyLiteral = Literal[' ', '!', '+', '-', '*', '=', 't', '?']


# def is_flagKeyLiteral(inp: str) -> TypeGuard[flagKeyLiteral]:
# return inp in [' ', '!', '+', '-', '=', '*', 't', '?']

Expand Down Expand Up @@ -707,9 +706,10 @@ def update(self, **kwargs: Any) -> 'Remote':
self.repo.git.remote(scmd, self.name, **kwargs)
return self

def _get_fetch_info_from_stderr(self, proc: TBD,
def _get_fetch_info_from_stderr(self, proc: 'Git.AutoInterrupt',
progress: Union[Callable[..., Any], RemoteProgress, None]
) -> IterableList['FetchInfo']:

progress = to_progress_instance(progress)

# skip first line as it is some remote info we are not interested in
Expand Down Expand Up @@ -768,7 +768,7 @@ def _get_fetch_info_from_stderr(self, proc: TBD,
log.warning("Git informed while fetching: %s", err_line.strip())
return output

def _get_push_info(self, proc: TBD,
def _get_push_info(self, proc: 'Git.AutoInterrupt',
progress: Union[Callable[..., Any], RemoteProgress, None]) -> IterableList[PushInfo]:
progress = to_progress_instance(progress)

Expand Down
9 changes: 5 additions & 4 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def __init__(self, path: Optional[PathLike] = None, odbt: Type[LooseObjectDB] =
def __enter__(self) -> 'Repo':
return self

def __exit__(self, exc_type: TBD, exc_value: TBD, traceback: TBD) -> None:
def __exit__(self, *args: Any) -> None:
self.close()

def __del__(self) -> None:
Expand Down Expand Up @@ -445,7 +445,7 @@ def create_tag(self, path: PathLike, ref: str = 'HEAD',
:return: TagReference object """
return TagReference.create(self, path, ref, message, force, **kwargs)

def delete_tag(self, *tags: TBD) -> None:
def delete_tag(self, *tags: TagReference) -> None:
"""Delete the given tag references"""
return TagReference.delete(self, *tags)

Expand Down Expand Up @@ -795,7 +795,7 @@ def active_branch(self) -> Head:
# reveal_type(self.head.reference) # => Reference
return self.head.reference

def blame_incremental(self, rev: TBD, file: TBD, **kwargs: Any) -> Optional[Iterator['BlameEntry']]:
def blame_incremental(self, rev: Union[str, HEAD], file: str, **kwargs: Any) -> Iterator['BlameEntry']:
"""Iterator for blame information for the given file at the given revision.

Unlike .blame(), this does not return the actual file's contents, only
Expand All @@ -809,6 +809,7 @@ def blame_incremental(self, rev: TBD, file: TBD, **kwargs: Any) -> Optional[Iter
If you combine all line number ranges outputted by this command, you
should get a continuous range spanning all line numbers in the file.
"""

data = self.git.blame(rev, '--', file, p=True, incremental=True, stdout_as_string=False, **kwargs)
commits: Dict[str, Commit] = {}

Expand Down Expand Up @@ -870,7 +871,7 @@ def blame_incremental(self, rev: TBD, file: TBD, **kwargs: Any) -> Optional[Iter
safe_decode(orig_filename),
range(orig_lineno, orig_lineno + num_lines))

def blame(self, rev: TBD, file: TBD, incremental: bool = False, **kwargs: Any
def blame(self, rev: Union[str, HEAD], file: str, incremental: bool = False, **kwargs: Any
) -> Union[List[List[Union[Optional['Commit'], List[str]]]], Optional[Iterator[BlameEntry]]]:
"""The blame information for the given file at the given revision.

Expand Down