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

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

‎git/objects/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ def utctz_to_altz(utctz: str) -> int:
143143
:param utctz: git utc timezone string, i.e. +0200
144144
"""
145145
int_utctz=int(utctz)
146-
seconds= ((abs(int_utctz)//100)*3600+ (abs(int_utctz)%100)*60)
146+
seconds= (abs(int_utctz)//100)*3600+ (abs(int_utctz)%100)*60
147147
returnsecondsifint_utctz<0else-seconds
148148

149149

150-
defaltz_to_utctz_str(altz:int)->str:
150+
defaltz_to_utctz_str(altz:float)->str:
151151
"""Convert a timezone offset west of UTC in seconds into a git timezone offset string
152152
153153
:param altz: timezone offset in seconds west of UTC

‎git/remote.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,6 @@ def _get_fetch_info_from_stderr(
826826
progress:Union[Callable[...,Any],RemoteProgress,None],
827827
kill_after_timeout:Union[None,float]=None,
828828
)->IterableList["FetchInfo"]:
829-
830829
progress=to_progress_instance(progress)
831830

832831
# skip first line as it is some remote info we are not interested in

‎git/repo/base.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ def delete_head(self, *heads: "Union[str, Head]", **kwargs: Any) -> None:
498498
defcreate_tag(
499499
self,
500500
path:PathLike,
501-
ref:Union[str,'SymbolicReference']="HEAD",
501+
ref:Union[str,"SymbolicReference"]="HEAD",
502502
message:Optional[str]=None,
503503
force:bool=False,
504504
**kwargs:Any,
@@ -548,9 +548,8 @@ def _get_config_path(self, config_level: Lit_config_levels, git_dir: Optional[Pa
548548
else:
549549
returnosp.normpath(osp.join(repo_dir,"config"))
550550
else:
551-
552-
assert_never(
553-
config_level,# type:ignore[unreachable]
551+
assert_never(# type:ignore[unreachable]
552+
config_level,
554553
ValueError(f"Invalid configuration level:{config_level!r}"),
555554
)
556555

‎git/util.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ class IterableList(List[T_IterableObj]):
10491049

10501050
__slots__= ("_id_attr","_prefix")
10511051

1052-
def__new__(cls,id_attr:str,prefix:str="")->"IterableList[IterableObj]":
1052+
def__new__(cls,id_attr:str,prefix:str="")->"IterableList[T_IterableObj]":
10531053
returnsuper(IterableList,cls).__new__(cls)
10541054

10551055
def__init__(self,id_attr:str,prefix:str="")->None:
@@ -1083,7 +1083,6 @@ def __getattr__(self, attr: str) -> T_IterableObj:
10831083
returnlist.__getattribute__(self,attr)
10841084

10851085
def__getitem__(self,index:Union[SupportsIndex,int,slice,str])->T_IterableObj:# type: ignore
1086-
10871086
assertisinstance(index, (int,str,slice)),"Index of IterableList should be an int or str"
10881087

10891088
ifisinstance(index,int):
@@ -1098,7 +1097,6 @@ def __getitem__(self, index: Union[SupportsIndex, int, slice, str]) -> T_Iterabl
10981097
# END handle getattr
10991098

11001099
def__delitem__(self,index:Union[SupportsIndex,int,slice,str])->None:
1101-
11021100
assertisinstance(index, (int,str)),"Index of IterableList should be an int or str"
11031101

11041102
delindex=cast(int,index)

‎pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ filterwarnings = 'ignore::DeprecationWarning'
1919
# filterwarnings ignore::WarningType # ignores those warnings
2020

2121
[tool.mypy]
22+
python_version ="3.7"
2223
disallow_untyped_defs =true
2324
no_implicit_optional =true
2425
warn_redundant_casts =true
@@ -29,6 +30,7 @@ implicit_reexport = true
2930
# strict = true
3031

3132
# TODO: remove when 'gitdb' is fully annotated
33+
exclude = ["^git/ext/gitdb"]
3234
[[tool.mypy.overrides]]
3335
module ="gitdb.*"
3436
ignore_missing_imports =true
@@ -43,3 +45,4 @@ omit = ["*/git/ext/*"]
4345
[tool.black]
4446
line-length =120
4547
target-version = ['py37']
48+
exclude ="git/ext/gitdb"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp