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

Commit6643a9f

Browse files
authored
Merge pull request#1202 from Yobmod/main
Add more types
2 parents690722a +c93e971 commit6643a9f

File tree

11 files changed

+338
-228
lines changed

11 files changed

+338
-228
lines changed

‎git/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66
# flake8: noqa
77
#@PydevCodeAnalysisIgnore
8+
fromgit.excimport*# @NoMove @IgnorePep8
89
importinspect
910
importos
1011
importsys
11-
1212
importos.pathasosp
1313

14+
fromtypingimportOptional
15+
fromgit.typesimportPathLike
1416

1517
__version__='git'
1618

1719

1820
#{ Initialization
19-
def_init_externals():
21+
def_init_externals()->None:
2022
"""Initialize external projects by putting them into the path"""
2123
if__version__=='git'and'PYOXIDIZER'notinos.environ:
2224
sys.path.insert(1,osp.join(osp.dirname(__file__),'ext','gitdb'))
@@ -29,13 +31,13 @@ def _init_externals():
2931

3032
#} END initialization
3133

34+
3235
#################
3336
_init_externals()
3437
#################
3538

3639
#{ Imports
3740

38-
fromgit.excimport*# @NoMove @IgnorePep8
3941
try:
4042
fromgit.configimportGitConfigParser# @NoMove @IgnorePep8
4143
fromgit.objectsimport*# @NoMove @IgnorePep8
@@ -65,7 +67,8 @@ def _init_externals():
6567
#{ Initialize git executable path
6668
GIT_OK=None
6769

68-
defrefresh(path=None):
70+
71+
defrefresh(path:Optional[PathLike]=None)->None:
6972
"""Convenience method for setting the git executable path."""
7073
globalGIT_OK
7174
GIT_OK=False
@@ -78,6 +81,7 @@ def refresh(path=None):
7881
GIT_OK=True
7982
#} END initialize git executable path
8083

84+
8185
#################
8286
try:
8387
refresh()

‎git/cmd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def refresh(cls, path=None):
210210
# - a GitCommandNotFound error is spawned by ourselves
211211
# - a PermissionError is spawned if the git executable provided
212212
# cannot be executed for whatever reason
213-
213+
214214
has_git=False
215215
try:
216216
cls().version()
@@ -498,7 +498,7 @@ def readlines(self, size=-1):
498498
# skipcq: PYL-E0301
499499
def__iter__(self):
500500
returnself
501-
501+
502502
def__next__(self):
503503
returnself.next()
504504

@@ -639,7 +639,7 @@ def execute(self, command,
639639
640640
:param env:
641641
A dictionary of environment variables to be passed to `subprocess.Popen`.
642-
642+
643643
:param max_chunk_size:
644644
Maximum number of bytes in one chunk of data passed to the output_stream in
645645
one invocation of write() method. If the given number is not positive then

‎git/compat.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,57 +11,71 @@
1111
importos
1212
importsys
1313

14-
1514
fromgitdb.utils.encodingimport (
1615
force_bytes,# @UnusedImport
1716
force_text# @UnusedImport
1817
)
1918

19+
# typing --------------------------------------------------------------------
20+
21+
fromtypingimportAny,AnyStr,Dict,Optional,Type
22+
fromgit.typesimportTBD
23+
24+
# ---------------------------------------------------------------------------
2025

21-
is_win= (os.name=='nt')
26+
27+
is_win= (os.name=='nt')# type: bool
2228
is_posix= (os.name=='posix')
2329
is_darwin= (os.name=='darwin')
2430
defenc=sys.getfilesystemencoding()
2531

2632

27-
defsafe_decode(s):
33+
defsafe_decode(s:Optional[AnyStr])->Optional[str]:
2834
"""Safely decodes a binary string to unicode"""
2935
ifisinstance(s,str):
3036
returns
3137
elifisinstance(s,bytes):
3238
returns.decode(defenc,'surrogateescape')
33-
elifsisnotNone:
39+
elifsisNone:
40+
returnNone
41+
else:
3442
raiseTypeError('Expected bytes or text, but got %r'% (s,))
3543

3644

37-
defsafe_encode(s):
38-
"""Safelydecodes a binary string to unicode"""
45+
defsafe_encode(s:Optional[AnyStr])->Optional[bytes]:
46+
"""Safelyencodes a binary string to unicode"""
3947
ifisinstance(s,str):
4048
returns.encode(defenc)
4149
elifisinstance(s,bytes):
4250
returns
43-
elifsisnotNone:
51+
elifsisNone:
52+
returnNone
53+
else:
4454
raiseTypeError('Expected bytes or text, but got %r'% (s,))
4555

4656

47-
defwin_encode(s):
57+
defwin_encode(s:Optional[AnyStr])->Optional[bytes]:
4858
"""Encode unicodes for process arguments on Windows."""
4959
ifisinstance(s,str):
5060
returns.encode(locale.getpreferredencoding(False))
5161
elifisinstance(s,bytes):
5262
returns
5363
elifsisnotNone:
5464
raiseTypeError('Expected bytes or text, but got %r'% (s,))
65+
returnNone
66+
5567

5668

57-
defwith_metaclass(meta,*bases):
69+
defwith_metaclass(meta:Type[Any],*bases:Any)->'metaclass':# type: ignore ## mypy cannot understand dynamic class creation
5870
"""copied from https://github.com/Byron/bcore/blob/master/src/python/butility/future.py#L15"""
59-
classmetaclass(meta):
71+
72+
classmetaclass(meta):# type: ignore
6073
__call__=type.__call__
61-
__init__=type.__init__
74+
__init__=type.__init__# type: ignore
6275

63-
def__new__(cls,name,nbases,d):
76+
def__new__(cls,name:str,nbases:Optional[int],d:Dict[str,Any])->TBD:
6477
ifnbasesisNone:
6578
returntype.__new__(cls,name, (),d)
6679
returnmeta(name,bases,d)
80+
6781
returnmetaclass(meta.__name__+'Helper',None, {})

‎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/db.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@
77
fromgitdb.dbimportGitDB# @UnusedImport
88
fromgitdb.dbimportLooseObjectDB
99

10-
from .excimport (
11-
GitCommandError,
12-
BadObject
13-
)
10+
fromgitdb.excimportBadObject
11+
fromgit.excimportGitCommandError
12+
13+
# typing-------------------------------------------------
14+
15+
fromtypingimportTYPE_CHECKING,AnyStr
16+
fromgit.typesimportPathLike
17+
18+
ifTYPE_CHECKING:
19+
fromgit.cmdimportGit
20+
1421

22+
# --------------------------------------------------------
1523

1624
__all__= ('GitCmdObjectDB','GitDB')
1725

@@ -28,23 +36,23 @@ class GitCmdObjectDB(LooseObjectDB):
2836
have packs and the other implementations
2937
"""
3038

31-
def__init__(self,root_path,git):
39+
def__init__(self,root_path:PathLike,git:'Git')->None:
3240
"""Initialize this instance with the root and a git command"""
3341
super(GitCmdObjectDB,self).__init__(root_path)
3442
self._git=git
3543

36-
definfo(self,sha):
44+
definfo(self,sha:bytes)->OInfo:
3745
hexsha,typename,size=self._git.get_object_header(bin_to_hex(sha))
3846
returnOInfo(hex_to_bin(hexsha),typename,size)
3947

40-
defstream(self,sha):
48+
defstream(self,sha:bytes)->OStream:
4149
"""For now, all lookup is done by git itself"""
4250
hexsha,typename,size,stream=self._git.stream_object_data(bin_to_hex(sha))
4351
returnOStream(hex_to_bin(hexsha),typename,size,stream)
4452

4553
# { Interface
4654

47-
defpartial_to_complete_sha_hex(self,partial_hexsha):
55+
defpartial_to_complete_sha_hex(self,partial_hexsha:AnyStr)->bytes:
4856
""":return: Full binary 20 byte sha from the given partial hexsha
4957
:raise AmbiguousObjectName:
5058
:raise BadObject:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp