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

Commitab69b9a

Browse files
committed
Add types to config.py GitConfigParser .write() ._write() .items() .items_all()
1 parentc6e458c commitab69b9a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

‎git/config.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ def read(self) -> None:
604604
self._merge_includes=False
605605
# end
606606

607-
def_write(self,fp):
607+
def_write(self,fp:IO)->None:
608608
"""Write an .ini-format representation of the configuration state in
609609
git compatible format"""
610610
defwrite_section(name,section_dict):
@@ -623,11 +623,11 @@ def write_section(name, section_dict):
623623
forname,valueinself._sections.items():
624624
write_section(name,value)
625625

626-
defitems(self,section_name):
626+
defitems(self,section_name:str)->List[Tuple[str,str]]:
627627
""":return: list((option, value), ...) pairs of all items in the given section"""
628628
return [(k,v)fork,vinsuper(GitConfigParser,self).items(section_name)ifk!='__name__']
629629

630-
defitems_all(self,section_name):
630+
defitems_all(self,section_name:str)->List[Tuple[str,List[str]]]:
631631
""":return: list((option, [values...]), ...) pairs of all items in the given section"""
632632
rv=_OMD(self._defaults)
633633

@@ -644,7 +644,7 @@ def items_all(self, section_name):
644644
returnrv.items_all()
645645

646646
@needs_values
647-
defwrite(self):
647+
defwrite(self)->None:
648648
"""Write changes to our file, if there are changes at all
649649
650650
:raise IOError: if this is a read-only writer instance or if we could not obtain
@@ -661,19 +661,21 @@ def write(self):
661661
ifself._has_includes():
662662
log.debug("Skipping write-back of configuration file as include files were merged in."+
663663
"Set merge_includes=False to prevent this.")
664-
return
664+
returnNone
665665
# end
666666

667667
fp=self._file_or_files
668668

669669
# we have a physical file on disk, so get a lock
670670
is_file_lock=isinstance(fp, (str,IOBase))
671-
ifis_file_lock:
671+
ifis_file_lockandself._lockisnotNone:# else raise Error?
672672
self._lock._obtain_lock()
673673
ifnothasattr(fp,"seek"):
674-
withopen(self._file_or_files,"wb")asfp:
675-
self._write(fp)
674+
self._file_or_files=cast(PathLike,self._file_or_files)
675+
withopen(self._file_or_files,"wb")asfp_open:
676+
self._write(fp_open)
676677
else:
678+
fp=cast(IO,fp)
677679
fp.seek(0)
678680
# make sure we do not overwrite into an existing file
679681
ifhasattr(fp,'truncate'):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp