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

Commit91fce33

Browse files
committed
increase mypy strictness (warn unused ignored and warn unreachable)
1 parent0525c17 commit91fce33

File tree

10 files changed

+29
-23
lines changed

10 files changed

+29
-23
lines changed

‎git/cmd.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
fromtypingimport (Any,AnyStr,BinaryIO,Callable,Dict,IO,Iterator,List,Mapping,
4343
Sequence,TYPE_CHECKING,TextIO,Tuple,Union,cast,overload)
4444

45-
fromgit.typesimportPathLike,Literal
45+
fromgit.typesimportPathLike,Literal,TBD
4646

4747
ifTYPE_CHECKING:
4848
fromgit.repo.baseimportRepo
@@ -575,8 +575,8 @@ def __init__(self, working_dir: Union[None, PathLike] = None):
575575
self._environment:Dict[str,str]= {}
576576

577577
# cached command slots
578-
self.cat_file_header=None
579-
self.cat_file_all=None
578+
self.cat_file_header:Union[None,TBD]=None
579+
self.cat_file_all:Union[None,TBD]=None
580580

581581
def__getattr__(self,name:str)->Any:
582582
"""A convenience method as it allows to call the command as if it was
@@ -1012,8 +1012,6 @@ def transform_kwargs(self, split_single_char_options: bool = True, **kwargs: Any
10121012

10131013
@classmethod
10141014
def__unpack_args(cls,arg_list:Sequence[str])->List[str]:
1015-
ifnotisinstance(arg_list, (list,tuple)):
1016-
return [str(arg_list)]
10171015

10181016
outlist= []
10191017
forarginarg_list:

‎git/config.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ def get_config_path(config_level: Lit_config_levels) -> str:
236236
raiseValueError("No repo to get repository configuration from. Use Repo._get_config_path")
237237
else:
238238
# Should not reach here. Will raise ValueError if does. Static typing will warn missing elifs
239-
assert_never(config_level,ValueError(f"Invalid configuration level:{config_level!r}"))
239+
assert_never(config_level,# type: ignore[unreachable]
240+
ValueError(f"Invalid configuration level:{config_level!r}"))
240241

241242

242243
classGitConfigParser(cp.RawConfigParser,metaclass=MetaParserBuilder):

‎git/diff.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ def _index_from_patch_format(cls, repo: 'Repo', proc: Union['Popen', 'Git.AutoIn
456456
# for now, we have to bake the stream
457457
text=b''.join(text_list)
458458
index:'DiffIndex'=DiffIndex()
459-
previous_header=None
460-
header=None
459+
previous_header:Union[Match[bytes],None]=None
460+
header:Union[Match[bytes],None]=None
461461
a_path,b_path=None,None# for mypy
462462
a_mode,b_mode=None,None# for mypy
463463
for_headerincls.re_header.finditer(text):

‎git/index/base.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,6 @@ def handle_stderr(proc: 'Popen[bytes]', iter_checked_out_files: Iterable[PathLik
12021202
handle_stderr(proc,checked_out_files)
12031203
returnchecked_out_files
12041204
# END paths handling
1205-
assert"Should not reach this point"
12061205

12071206
@default_index
12081207
defreset(self,commit:Union[Commit,'Reference',str]='HEAD',working_tree:bool=False,

‎git/objects/fun.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def tree_to_stream(entries: Sequence[EntryTup], write: Callable[['ReadableBuffer
5151
ifisinstance(name,str):
5252
name_bytes=name.encode(defenc)
5353
else:
54-
name_bytes=name
54+
name_bytes=name# type: ignore[unreachable] # check runtime types - is always str?
5555
write(b''.join((mode_str,b' ',name_bytes,b'\0',binsha)))
5656
# END for each item
5757

‎git/objects/tree.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def __init__(self, repo: 'Repo', binsha: bytes, mode: int = tree_id << 12, path:
215215
super(Tree,self).__init__(repo,binsha,mode,path)
216216

217217
@classmethod
218-
def_get_intermediate_items(cls,index_object:'Tree',
218+
def_get_intermediate_items(cls,index_object:IndexObjUnion,
219219
)->Union[Tuple['Tree', ...],Tuple[()]]:
220220
ifindex_object.type=="tree":
221221
returntuple(index_object._iter_convert_to_object(index_object._cache))

‎git/objects/util.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def from_timestamp(timestamp: float, tz_offset: float) -> datetime:
167167
returnutc_dt
168168

169169

170-
defparse_date(string_date:str)->Tuple[int,int]:
170+
defparse_date(string_date:Union[str,datetime])->Tuple[int,int]:
171171
"""
172172
Parse the given date as one of the following
173173
@@ -182,8 +182,10 @@ def parse_date(string_date: str) -> Tuple[int, int]:
182182
:note: Date can also be YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY.
183183
"""
184184
ifisinstance(string_date,datetime)andstring_date.tzinfo:
185-
offset=-int(string_date.utcoffset().total_seconds())
185+
offset=-int(string_date.utcoffset().total_seconds())# type: ignore[union-attr]
186186
returnint(string_date.astimezone(utc).timestamp()),offset
187+
else:
188+
assertisinstance(string_date,str)# for mypy
187189

188190
# git time
189191
try:
@@ -338,7 +340,7 @@ def _list_traverse(self, as_edge: bool = False, *args: Any, **kwargs: Any
338340
"""
339341
# Commit and Submodule have id.__attribute__ as IterableObj
340342
# Tree has id.__attribute__ inherited from IndexObject
341-
ifisinstance(self,(TraversableIterableObj,Has_id_attribute)):
343+
ifisinstance(self,Has_id_attribute):
342344
id=self._id_attribute_
343345
else:
344346
id=""# shouldn't reach here, unless Traversable subclass created with no _id_attribute_

‎git/repo/base.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ def __init__(self, path: Optional[PathLike] = None, odbt: Type[LooseObjectDB] =
200200
# END while curpath
201201

202202
ifself.git_dirisNone:
203-
self.git_dir=cast(PathLike,self.git_dir)
204203
raiseInvalidGitRepositoryError(epath)
205204

206205
self._bare=False

‎git/repo/fun.py‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Package with general repository related functions"""
2+
fromgit.refs.referenceimportReference
3+
fromgit.typesimportCommit_ish
24
importos
35
importstat
46
fromstringimportdigits
@@ -202,7 +204,7 @@ def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']:
202204
raiseNotImplementedError("commit by message search ( regex )")
203205
# END handle search
204206

205-
obj=cast(Object,None)# not ideal. Should use guards
207+
obj:Union[Commit_ish,Reference,None]=None
206208
ref=None
207209
output_type="commit"
208210
start=0
@@ -222,14 +224,16 @@ def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']:
222224
ref=repo.head.ref
223225
else:
224226
iftoken=='@':
225-
ref=name_to_object(repo,rev[:start],return_ref=True)
227+
ref=cast(Reference,name_to_object(repo,rev[:start],return_ref=True))
226228
else:
227-
obj=name_to_object(repo,rev[:start])
229+
obj=cast(Commit_ish,name_to_object(repo,rev[:start]))
228230
# END handle token
229231
# END handle refname
232+
else:
233+
assertobjisnotNone
230234

231235
ifrefisnotNone:
232-
obj=ref.commit
236+
obj=cast(Commit,ref.commit)
233237
# END handle ref
234238
# END initialize obj on first token
235239

@@ -247,11 +251,13 @@ def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']:
247251
pass# default
248252
elifoutput_type=='tree':
249253
try:
254+
obj=cast(Object,obj)
250255
obj=to_commit(obj).tree
251256
except (AttributeError,ValueError):
252257
pass# error raised later
253258
# END exception handling
254259
elifoutput_typein ('','blob'):
260+
obj=cast(TagObject,obj)
255261
ifobjandobj.type=='tag':
256262
obj=deref_tag(obj)
257263
else:
@@ -280,13 +286,13 @@ def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']:
280286
obj=Object.new_from_sha(repo,hex_to_bin(entry.newhexsha))
281287

282288
# make it pass the following checks
283-
output_type=None
289+
output_type=''
284290
else:
285291
raiseValueError("Invalid output type: %s ( in %s )"% (output_type,rev))
286292
# END handle output type
287293

288294
# empty output types don't require any specific type, its just about dereferencing tags
289-
ifoutput_typeandobj.type!=output_type:
295+
ifoutput_typeandobjandobj.type!=output_type:
290296
raiseValueError("Could not accommodate requested object type %r, got %s"% (output_type,obj.type))
291297
# END verify output type
292298

@@ -319,6 +325,7 @@ def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']:
319325
parsed_to=start
320326
# handle hierarchy walk
321327
try:
328+
obj=cast(Commit_ish,obj)
322329
iftoken=="~":
323330
obj=to_commit(obj)
324331
for_inrange(num):
@@ -347,7 +354,7 @@ def rev_parse(repo: 'Repo', rev: str) -> Union['Commit', 'Tag', 'Tree', 'Blob']:
347354

348355
# still no obj ? Its probably a simple name
349356
ifobjisNone:
350-
obj=name_to_object(repo,rev)
357+
obj=cast(Commit_ish,name_to_object(repo,rev))
351358
parsed_to=lr
352359
# END handle simple name
353360

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ no_implicit_optional = true
2424
warn_redundant_casts =true
2525
implicit_reexport =true
2626
warn_unused_ignores =true
27-
#warn_unreachable =True
27+
warn_unreachable =true
2828
show_error_codes =true
2929

3030
# TODO: remove when 'gitdb' is fully annotated

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp