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

Commit5b0028e

Browse files
committed
start add types to util.py
1 parentad4079d commit5b0028e

File tree

5 files changed

+135
-97
lines changed

5 files changed

+135
-97
lines changed

‎git/cmd.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
importthreading
2020
fromcollectionsimportOrderedDict
2121
fromtextwrapimportdedent
22+
fromtypingimportAny,Dict,List,Optional
2223

2324
fromgit.compatimport (
2425
defenc,
@@ -39,6 +40,8 @@
3940
stream_copy,
4041
)
4142

43+
from .typesimportPathLike
44+
4245
execute_kwargs= {'istream','with_extended_output',
4346
'with_exceptions','as_process','stdout_as_string',
4447
'output_stream','with_stdout','kill_after_timeout',
@@ -516,7 +519,7 @@ def __del__(self):
516519
self._stream.read(bytes_left+1)
517520
# END handle incomplete read
518521

519-
def__init__(self,working_dir=None):
522+
def__init__(self,working_dir:Optional[PathLike]=None)->None:
520523
"""Initialize this instance with:
521524
522525
:param working_dir:
@@ -525,12 +528,12 @@ def __init__(self, working_dir=None):
525528
It is meant to be the working tree directory if available, or the
526529
.git directory in case of bare repositories."""
527530
super(Git,self).__init__()
528-
self._working_dir=expand_path(working_dir)
531+
self._working_dir=expand_path(working_dir)ifworking_dirisnotNoneelseNone
529532
self._git_options= ()
530-
self._persistent_git_options= []
533+
self._persistent_git_options= []# type: List[str]
531534

532535
# Extra environment variables to pass to git commands
533-
self._environment= {}
536+
self._environment= {}# type: Dict[str, Any]
534537

535538
# cached command slots
536539
self.cat_file_header=None
@@ -544,7 +547,7 @@ def __getattr__(self, name):
544547
returnLazyMixin.__getattr__(self,name)
545548
returnlambda*args,**kwargs:self._call_process(name,*args,**kwargs)
546549

547-
defset_persistent_git_options(self,**kwargs):
550+
defset_persistent_git_options(self,**kwargs)->None:
548551
"""Specify command line options to the git executable
549552
for subsequent subcommand calls
550553

‎git/compat.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
importlocale
1111
importos
1212
importsys
13+
fromtypingimportAnyStr,Optional,Type
1314

1415

1516
fromgitdb.utils.encodingimport (
@@ -18,40 +19,46 @@
1819
)
1920

2021

21-
is_win= (os.name=='nt')
22+
is_win= (os.name=='nt')# type: bool
2223
is_posix= (os.name=='posix')
2324
is_darwin= (os.name=='darwin')
2425
defenc=sys.getfilesystemencoding()
2526

2627

27-
defsafe_decode(s):
28+
defsafe_decode(s:Optional[AnyStr])->Optional[str]:
2829
"""Safely decodes a binary string to unicode"""
2930
ifisinstance(s,str):
3031
returns
3132
elifisinstance(s,bytes):
3233
returns.decode(defenc,'surrogateescape')
33-
elifsisnotNone:
34+
elifsisNone:
35+
returnNone
36+
else:
3437
raiseTypeError('Expected bytes or text, but got %r'% (s,))
3538

3639

37-
defsafe_encode(s):
38-
"""Safely decodes a binary string to unicode"""
40+
41+
defsafe_encode(s:Optional[AnyStr])->Optional[bytes]:
42+
"""Safely encodes a binary string to unicode"""
3943
ifisinstance(s,str):
4044
returns.encode(defenc)
4145
elifisinstance(s,bytes):
4246
returns
43-
elifsisnotNone:
47+
elifsisNone:
48+
returnNone
49+
else:
4450
raiseTypeError('Expected bytes or text, but got %r'% (s,))
4551

4652

47-
defwin_encode(s):
53+
defwin_encode(s:Optional[AnyStr])->Optional[bytes]:
4854
"""Encode unicodes for process arguments on Windows."""
4955
ifisinstance(s,str):
5056
returns.encode(locale.getpreferredencoding(False))
5157
elifisinstance(s,bytes):
5258
returns
5359
elifsisnotNone:
5460
raiseTypeError('Expected bytes or text, but got %r'% (s,))
61+
returnNone
5562

5663

5764
defwith_metaclass(meta,*bases):

‎git/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
importfnmatch
1717
fromcollectionsimportOrderedDict
1818

19+
fromtyping_extensionsimportLiteral
20+
1921
fromgit.compatimport (
2022
defenc,
2123
force_text,
@@ -194,7 +196,7 @@ def items_all(self):
194196
return [(k,self.getall(k))forkinself]
195197

196198

197-
defget_config_path(config_level):
199+
defget_config_path(config_level:Literal['system','global','user','repository'])->str:
198200

199201
# we do not support an absolute path of the gitconfig on windows ,
200202
# use the global config instead

‎git/refs/symbolic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ def _create(cls, repo, path, resolve, reference, force, logmsg=None):
513513
returnref
514514

515515
@classmethod
516-
defcreate(cls,repo,path,reference='HEAD',force=False,logmsg=None):
516+
defcreate(cls,repo,path,reference='HEAD',force=False,logmsg=None,**kwargs):
517517
"""Create a new symbolic reference, hence a reference pointing to another reference.
518518
519519
:param repo:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp