Skip to content

Partial clean up wrt mypy and black #1617

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 7 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Run black and exclude submodule
  • Loading branch information
bodograumann committed Jul 20, 2023
commit 6035db092decf72e6a01e175d044f0343818b51c
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ To typecheck, run: `mypy -p git`

To test, run: `pytest`

For automatic code formatting run: `black git`

Configuration for flake8 is in the ./.flake8 file.

Configurations for mypy, pytest and coverage.py are in ./pyproject.toml.
Expand Down
7 changes: 2 additions & 5 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def handle_process_output(
To specify a timeout in seconds for the git command, after which the process
should be killed.
"""

# Use 2 "pump" threads and wait for both to finish.
def pump_stream(
cmdline: List[str],
Expand Down Expand Up @@ -488,10 +489,7 @@ def check_unsafe_options(cls, options: List[str], unsafe_options: List[str]) ->
"""
# Options can be of the form `foo` or `--foo bar` `--foo=bar`,
# so we need to check if they start with "--foo" or if they are equal to "foo".
bare_unsafe_options = [
option.lstrip("-")
for option in unsafe_options
]
bare_unsafe_options = [option.lstrip("-") for option in unsafe_options]
for option in options:
for unsafe_option, bare_option in zip(unsafe_options, bare_unsafe_options):
if option.startswith(unsafe_option) or option == bare_option:
Expand Down Expand Up @@ -1194,7 +1192,6 @@ def transform_kwargs(self, split_single_char_options: bool = True, **kwargs: Any

@classmethod
def _unpack_args(cls, arg_list: Sequence[str]) -> List[str]:

outlist = []
if isinstance(arg_list, (list, tuple)):
for arg in arg_list:
Expand Down
3 changes: 1 addition & 2 deletions git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ def items_all(self) -> List[Tuple[str, List[_T]]]:


def get_config_path(config_level: Lit_config_levels) -> str:

# we do not support an absolute path of the gitconfig on windows ,
# use the global config instead
if is_win and config_level == "system":
Expand Down Expand Up @@ -655,7 +654,7 @@ def write_section(name: str, section_dict: _OMD) -> None:

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():
for key, values in section_dict.items_all():
if key == "__name__":
continue

Expand Down
3 changes: 1 addition & 2 deletions git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def diff(
args.append("--full-index") # get full index paths, not only filenames

# remove default '-M' arg (check for renames) if user is overriding it
if not any(x in kwargs for x in ('find_renames', 'no_renames', 'M')):
if not any(x in kwargs for x in ("find_renames", "no_renames", "M")):
args.append("-M")

if create_patch:
Expand Down Expand Up @@ -338,7 +338,6 @@ def __init__(
change_type: Optional[Lit_change_type],
score: Optional[int],
) -> None:

assert a_rawpath is None or isinstance(a_rawpath, bytes)
assert b_rawpath is None or isinstance(b_rawpath, bytes)
self.a_rawpath = a_rawpath
Expand Down
2 changes: 0 additions & 2 deletions git/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def __init__(
valid_files: Sequence[PathLike],
failed_reasons: List[str],
) -> None:

Exception.__init__(self, message)
self.failed_files = failed_files
self.failed_reasons = failed_reasons
Expand Down Expand Up @@ -170,7 +169,6 @@ def __init__(
stderr: Union[bytes, str, None] = None,
stdout: Union[bytes, str, None] = None,
) -> None:

super(HookExecutionError, self).__init__(command, status, stderr, stdout)
self._msg = "Hook('%s') failed%s"

Expand Down
1 change: 0 additions & 1 deletion git/index/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ def aggressive_tree_merge(odb: "GitCmdObjectDB", tree_shas: Sequence[bytes]) ->
out.append(_tree_entry_to_baseindexentry(theirs, 0))
# END handle modification
else:

if ours[0] != base[0] or ours[1] != base[1]:
# they deleted it, we changed it, conflict
out.append(_tree_entry_to_baseindexentry(base, 1))
Expand Down
4 changes: 1 addition & 3 deletions git/objects/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,7 @@ def trailers(self) -> Dict[str, str]:
Dictionary containing whitespace stripped trailer information.
Only contains the latest instance of each trailer key.
"""
return {
k: v[0] for k, v in self.trailers_dict.items()
}
return {k: v[0] for k, v in self.trailers_dict.items()}

@property
def trailers_list(self) -> List[Tuple[str, str]]:
Expand Down
1 change: 0 additions & 1 deletion git/objects/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def traverse_trees_recursive(
# is a tree. If the match is a non-tree item, put it into the result.
# Processed items will be set None
for ti, tree_data in enumerate(trees_data):

for ii, item in enumerate(tree_data):
if not item:
continue
Expand Down
2 changes: 1 addition & 1 deletion git/objects/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def utctz_to_altz(utctz: str) -> int:
:param utctz: git utc timezone string, i.e. +0200
"""
int_utctz = int(utctz)
seconds = ((abs(int_utctz) // 100) * 3600 + (abs(int_utctz) % 100) * 60)
seconds = (abs(int_utctz) // 100) * 3600 + (abs(int_utctz) % 100) * 60
return seconds if int_utctz < 0 else -seconds


Expand Down
1 change: 0 additions & 1 deletion git/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,6 @@ def _get_fetch_info_from_stderr(
progress: Union[Callable[..., Any], RemoteProgress, None],
kill_after_timeout: Union[None, float] = None,
) -> IterableList["FetchInfo"]:

progress = to_progress_instance(progress)

# skip first line as it is some remote info we are not interested in
Expand Down
3 changes: 1 addition & 2 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def delete_head(self, *heads: "Union[str, Head]", **kwargs: Any) -> None:
def create_tag(
self,
path: PathLike,
ref: Union[str, 'SymbolicReference'] = "HEAD",
ref: Union[str, "SymbolicReference"] = "HEAD",
message: Optional[str] = None,
force: bool = False,
**kwargs: Any,
Expand Down Expand Up @@ -548,7 +548,6 @@ def _get_config_path(self, config_level: Lit_config_levels, git_dir: Optional[Pa
else:
return osp.normpath(osp.join(repo_dir, "config"))
else:

assert_never( # type:ignore[unreachable]
config_level,
ValueError(f"Invalid configuration level: {config_level!r}"),
Expand Down
2 changes: 0 additions & 2 deletions git/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,6 @@ def __getattr__(self, attr: str) -> T_IterableObj:
return list.__getattribute__(self, attr)

def __getitem__(self, index: Union[SupportsIndex, int, slice, str]) -> T_IterableObj: # type: ignore

assert isinstance(index, (int, str, slice)), "Index of IterableList should be an int or str"

if isinstance(index, int):
Expand All @@ -1098,7 +1097,6 @@ def __getitem__(self, index: Union[SupportsIndex, int, slice, str]) -> T_Iterabl
# END handle getattr

def __delitem__(self, index: Union[SupportsIndex, int, slice, str]) -> None:

assert isinstance(index, (int, str)), "Index of IterableList should be an int or str"

delindex = cast(int, index)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ omit = ["*/git/ext/*"]
[tool.black]
line-length = 120
target-version = ['py37']
exclude = "git/ext/gitdb"