Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb543c72

Browse files
authored
Merge pull request#1617 from bodograumann/improve-dx
Partial clean up wrt mypy and black
2 parents09861ea +f01ee4f commitb543c72

File tree

15 files changed

+28
-38
lines changed

15 files changed

+28
-38
lines changed

‎README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ To typecheck, run: `mypy -p git`
110110

111111
To test, run:`pytest`
112112

113+
For automatic code formatting run:`black git`
114+
113115
Configuration for flake8 is in the ./.flake8 file.
114116

115117
Configurations for mypy, pytest and coverage.py are in ./pyproject.toml.

‎git/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def refresh(path: Optional[PathLike] = None) -> None:
7676
ifnotGit.refresh(path=path):
7777
return
7878
ifnotFetchInfo.refresh():
79-
return
79+
return# type: ignore [unreachable]
8080

8181
GIT_OK=True
8282

‎git/cmd.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def handle_process_output(
122122
To specify a timeout in seconds for the git command, after which the process
123123
should be killed.
124124
"""
125+
125126
# Use 2 "pump" threads and wait for both to finish.
126127
defpump_stream(
127128
cmdline:List[str],
@@ -154,7 +155,7 @@ def pump_stream(
154155
p_stdout=process.proc.stdoutifprocess.procelseNone
155156
p_stderr=process.proc.stderrifprocess.procelseNone
156157
else:
157-
process=cast(Popen,process)
158+
process=cast(Popen,process)# type: ignore [redundant-cast]
158159
cmdline=getattr(process,"args","")
159160
p_stdout=process.stdout
160161
p_stderr=process.stderr
@@ -210,7 +211,7 @@ def dashify(string: str) -> str:
210211
returnstring.replace("_","-")
211212

212213

213-
defslots_to_dict(self:object,exclude:Sequence[str]= ())->Dict[str,Any]:
214+
defslots_to_dict(self:"Git",exclude:Sequence[str]= ())->Dict[str,Any]:
214215
return {s:getattr(self,s)forsinself.__slots__ifsnotinexclude}
215216

216217

@@ -488,10 +489,7 @@ def check_unsafe_options(cls, options: List[str], unsafe_options: List[str]) ->
488489
"""
489490
# Options can be of the form `foo` or `--foo bar` `--foo=bar`,
490491
# so we need to check if they start with "--foo" or if they are equal to "foo".
491-
bare_unsafe_options= [
492-
option.lstrip("-")
493-
foroptioninunsafe_options
494-
]
492+
bare_unsafe_options= [option.lstrip("-")foroptioninunsafe_options]
495493
foroptioninoptions:
496494
forunsafe_option,bare_optioninzip(unsafe_options,bare_unsafe_options):
497495
ifoption.startswith(unsafe_option)oroption==bare_option:
@@ -1194,7 +1192,6 @@ def transform_kwargs(self, split_single_char_options: bool = True, **kwargs: Any
11941192

11951193
@classmethod
11961194
def_unpack_args(cls,arg_list:Sequence[str])->List[str]:
1197-
11981195
outlist= []
11991196
ifisinstance(arg_list, (list,tuple)):
12001197
forarginarg_list:

‎git/config.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ def items_all(self) -> List[Tuple[str, List[_T]]]:
248248

249249

250250
defget_config_path(config_level:Lit_config_levels)->str:
251-
252251
# we do not support an absolute path of the gitconfig on windows ,
253252
# use the global config instead
254253
ifis_winandconfig_level=="system":
@@ -265,8 +264,8 @@ def get_config_path(config_level: Lit_config_levels) -> str:
265264
raiseValueError("No repo to get repository configuration from. Use Repo._get_config_path")
266265
else:
267266
# Should not reach here. Will raise ValueError if does. Static typing will warn missing elifs
268-
assert_never(
269-
config_level,# type: ignore[unreachable]
267+
assert_never(# type: ignore[unreachable]
268+
config_level,
270269
ValueError(f"Invalid configuration level:{config_level!r}"),
271270
)
272271

@@ -655,7 +654,7 @@ def write_section(name: str, section_dict: _OMD) -> None:
655654

656655
values:Sequence[str]# runtime only gets str in tests, but should be whatever _OMD stores
657656
v:str
658-
for(key,values)insection_dict.items_all():
657+
forkey,valuesinsection_dict.items_all():
659658
ifkey=="__name__":
660659
continue
661660

‎git/diff.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def diff(
145145
args.append("--full-index")# get full index paths, not only filenames
146146

147147
# remove default '-M' arg (check for renames) if user is overriding it
148-
ifnotany(xinkwargsforxin ('find_renames','no_renames','M')):
148+
ifnotany(xinkwargsforxin ("find_renames","no_renames","M")):
149149
args.append("-M")
150150

151151
ifcreate_patch:
@@ -338,7 +338,6 @@ def __init__(
338338
change_type:Optional[Lit_change_type],
339339
score:Optional[int],
340340
)->None:
341-
342341
asserta_rawpathisNoneorisinstance(a_rawpath,bytes)
343342
assertb_rawpathisNoneorisinstance(b_rawpath,bytes)
344343
self.a_rawpath=a_rawpath

‎git/exc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ def __init__(
139139
valid_files:Sequence[PathLike],
140140
failed_reasons:List[str],
141141
)->None:
142-
143142
Exception.__init__(self,message)
144143
self.failed_files=failed_files
145144
self.failed_reasons=failed_reasons
@@ -170,7 +169,6 @@ def __init__(
170169
stderr:Union[bytes,str,None]=None,
171170
stdout:Union[bytes,str,None]=None,
172171
)->None:
173-
174172
super(HookExecutionError,self).__init__(command,status,stderr,stdout)
175173
self._msg="Hook('%s') failed%s"
176174

‎git/index/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ def _store_path(self, filepath: PathLike, fprogress: Callable) -> BaseIndexEntry
656656
def_entries_for_paths(
657657
self,
658658
paths:List[str],
659-
path_rewriter:Callable,
659+
path_rewriter:Union[Callable,None],
660660
fprogress:Callable,
661661
entries:List[BaseIndexEntry],
662662
)->List[BaseIndexEntry]:

‎git/index/fun.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def hook_path(name: str, git_dir: PathLike) -> str:
7676
returnosp.join(git_dir,"hooks",name)
7777

7878

79-
def_has_file_extension(path):
79+
def_has_file_extension(path:str)->str:
8080
returnosp.splitext(path)[1]
8181

8282

@@ -102,7 +102,7 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None:
102102
relative_hp=Path(hp).relative_to(index.repo.working_dir).as_posix()
103103
cmd= ["bash.exe",relative_hp]
104104

105-
cmd=subprocess.Popen(
105+
process=subprocess.Popen(
106106
cmd+list(args),
107107
env=env,
108108
stdout=subprocess.PIPE,
@@ -116,13 +116,13 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None:
116116
else:
117117
stdout_list:List[str]= []
118118
stderr_list:List[str]= []
119-
handle_process_output(cmd,stdout_list.append,stderr_list.append,finalize_process)
119+
handle_process_output(process,stdout_list.append,stderr_list.append,finalize_process)
120120
stdout="".join(stdout_list)
121121
stderr="".join(stderr_list)
122-
ifcmd.returncode!=0:
122+
ifprocess.returncode!=0:
123123
stdout=force_text(stdout,defenc)
124124
stderr=force_text(stderr,defenc)
125-
raiseHookExecutionError(hp,cmd.returncode,stderr,stdout)
125+
raiseHookExecutionError(hp,process.returncode,stderr,stdout)
126126
# end handle return code
127127

128128

@@ -394,7 +394,6 @@ def aggressive_tree_merge(odb: "GitCmdObjectDB", tree_shas: Sequence[bytes]) ->
394394
out.append(_tree_entry_to_baseindexentry(theirs,0))
395395
# END handle modification
396396
else:
397-
398397
ifours[0]!=base[0]orours[1]!=base[1]:
399398
# they deleted it, we changed it, conflict
400399
out.append(_tree_entry_to_baseindexentry(base,1))

‎git/objects/commit.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,7 @@ def trailers(self) -> Dict[str, str]:
345345
Dictionary containing whitespace stripped trailer information.
346346
Only contains the latest instance of each trailer key.
347347
"""
348-
return {
349-
k:v[0]fork,vinself.trailers_dict.items()
350-
}
348+
return {k:v[0]fork,vinself.trailers_dict.items()}
351349

352350
@property
353351
deftrailers_list(self)->List[Tuple[str,str]]:
@@ -460,7 +458,7 @@ def _iter_from_process_or_stream(cls, repo: "Repo", proc_or_stream: Union[Popen,
460458
ifproc_or_stream.stdoutisnotNone:
461459
stream=proc_or_stream.stdout
462460
elifhasattr(proc_or_stream,"readline"):
463-
proc_or_stream=cast(IO,proc_or_stream)
461+
proc_or_stream=cast(IO,proc_or_stream)# type: ignore [redundant-cast]
464462
stream=proc_or_stream
465463

466464
readline=stream.readline

‎git/objects/fun.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ def traverse_trees_recursive(
190190
# is a tree. If the match is a non-tree item, put it into the result.
191191
# Processed items will be set None
192192
forti,tree_datainenumerate(trees_data):
193-
194193
forii,iteminenumerate(tree_data):
195194
ifnotitem:
196195
continue

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp