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

Commit71e28b8

Browse files
committed
add types to git.db and git.exc
1 parenta094ac1 commit71e28b8

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

‎git/db.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
)
77
fromgitdb.dbimportGitDB# @UnusedImport
88
fromgitdb.dbimportLooseObjectDB
9+
fromgitdb.excimportBadObject
910

10-
from .excimport (
11-
GitCommandError,
12-
BadObject
13-
)
11+
from .excimportGitCommandError
12+
13+
# typing-------------------------------------------------
14+
15+
from .cmdimportGit
16+
from .typesimportPathLike,TBD
1417

18+
# --------------------------------------------------------
1519

1620
__all__= ('GitCmdObjectDB','GitDB')
1721

@@ -28,23 +32,23 @@ class GitCmdObjectDB(LooseObjectDB):
2832
have packs and the other implementations
2933
"""
3034

31-
def__init__(self,root_path,git):
35+
def__init__(self,root_path:PathLike,git:Git)->None:
3236
"""Initialize this instance with the root and a git command"""
3337
super(GitCmdObjectDB,self).__init__(root_path)
3438
self._git=git
3539

36-
definfo(self,sha):
40+
definfo(self,sha:bytes)->OInfo:
3741
hexsha,typename,size=self._git.get_object_header(bin_to_hex(sha))
3842
returnOInfo(hex_to_bin(hexsha),typename,size)
3943

40-
defstream(self,sha):
44+
defstream(self,sha:bytes)->OStream:
4145
"""For now, all lookup is done by git itself"""
4246
hexsha,typename,size,stream=self._git.stream_object_data(bin_to_hex(sha))
4347
returnOStream(hex_to_bin(hexsha),typename,size,stream)
4448

4549
# { Interface
4650

47-
defpartial_to_complete_sha_hex(self,partial_hexsha):
51+
defpartial_to_complete_sha_hex(self,partial_hexsha:str)->bytes:
4852
""":return: Full binary 20 byte sha from the given partial hexsha
4953
:raise AmbiguousObjectName:
5054
:raise BadObject:

‎git/exc.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
fromgitdb.excimport*# NOQA @UnusedWildImport skipcq: PYL-W0401, PYL-W0614
99
fromgit.compatimportsafe_decode
1010

11+
# typing ----------------------------------------------------
12+
13+
fromgit.repo.baseimportRepo
14+
fromgit.typesimportPathLike
15+
fromtypingimportIO,List,Optional,Sequence,Tuple,Union
16+
17+
# ------------------------------------------------------------------
1118

1219
classGitError(Exception):
1320
""" Base class for all package exceptions """
@@ -37,7 +44,9 @@ class CommandError(GitError):
3744
#: "'%s' failed%s"
3845
_msg="Cmd('%s') failed%s"
3946

40-
def__init__(self,command,status=None,stderr=None,stdout=None):
47+
def__init__(self,command:Union[List[str],Tuple[str, ...],str],
48+
status:Union[str,None,Exception]=None,
49+
stderr:Optional[IO[str]]=None,stdout:Optional[IO[str]]=None)->None:
4150
ifnotisinstance(command, (tuple,list)):
4251
command=command.split()
4352
self.command=command
@@ -53,28 +62,33 @@ def __init__(self, command, status=None, stderr=None, stdout=None):
5362
status="'%s'"%sifisinstance(status,str)elses
5463

5564
self._cmd=safe_decode(command[0])
56-
self._cmdline=' '.join(safe_decode(i)foriincommand)
65+
self._cmdline=' '.join(str(safe_decode(i))foriincommand)
5766
self._cause=statusand" due to: %s"%statusor"!"
58-
self.stdout=stdoutand"\n stdout: '%s'"%safe_decode(stdout)or''
59-
self.stderr=stderrand"\n stderr: '%s'"%safe_decode(stderr)or''
67+
self.stdout=stdoutand"\n stdout: '%s'"%safe_decode(str(stdout))or''
68+
self.stderr=stderrand"\n stderr: '%s'"%safe_decode(str(stderr))or''
6069

61-
def__str__(self):
70+
def__str__(self)->str:
6271
return (self._msg+"\n cmdline: %s%s%s")% (
6372
self._cmd,self._cause,self._cmdline,self.stdout,self.stderr)
6473

6574

6675
classGitCommandNotFound(CommandError):
6776
"""Thrown if we cannot find the `git` executable in the PATH or at the path given by
6877
the GIT_PYTHON_GIT_EXECUTABLE environment variable"""
69-
def__init__(self,command,cause):
78+
79+
def__init__(self,command:Union[List[str],Tuple[str],str],cause:Union[str,Exception])->None:
7080
super(GitCommandNotFound,self).__init__(command,cause)
7181
self._msg="Cmd('%s') not found%s"
7282

7383

7484
classGitCommandError(CommandError):
7585
""" Thrown if execution of the git command fails with non-zero status code. """
7686

77-
def__init__(self,command,status,stderr=None,stdout=None):
87+
def__init__(self,command:Union[List[str],Tuple[str, ...],str],
88+
status:Union[str,None,Exception]=None,
89+
stderr:Optional[IO[str]]=None,
90+
stdout:Optional[IO[str]]=None,
91+
)->None:
7892
super(GitCommandError,self).__init__(command,status,stderr,stdout)
7993

8094

@@ -92,13 +106,13 @@ class CheckoutError(GitError):
92106
were checked out successfully and hence match the version stored in the
93107
index"""
94108

95-
def__init__(self,message,failed_files,valid_files,failed_reasons):
109+
def__init__(self,message:str,failed_files:List[PathLike],valid_files:List[PathLike],failed_reasons:List[str])->None:
96110
Exception.__init__(self,message)
97111
self.failed_files=failed_files
98112
self.failed_reasons=failed_reasons
99113
self.valid_files=valid_files
100114

101-
def__str__(self):
115+
def__str__(self)->str:
102116
returnException.__str__(self)+":%s"%self.failed_files
103117

104118

@@ -116,17 +130,18 @@ class HookExecutionError(CommandError):
116130
"""Thrown if a hook exits with a non-zero exit code. It provides access to the exit code and the string returned
117131
via standard output"""
118132

119-
def__init__(self,command,status,stderr=None,stdout=None):
133+
def__init__(self,command:Union[List[str],Tuple[str, ...],str],status:Optional[str],
134+
stderr:Optional[IO[str]]=None,stdout:Optional[IO[str]]=None)->None:
120135
super(HookExecutionError,self).__init__(command,status,stderr,stdout)
121136
self._msg="Hook('%s') failed%s"
122137

123138

124139
classRepositoryDirtyError(GitError):
125140
"""Thrown whenever an operation on a repository fails as it has uncommitted changes that would be overwritten"""
126141

127-
def__init__(self,repo,message):
142+
def__init__(self,repo:Repo,message:str)->None:
128143
self.repo=repo
129144
self.message=message
130145

131-
def__str__(self):
146+
def__str__(self)->str:
132147
return"Operation cannot be performed on %r: %s"% (self.repo,self.message)

‎mypy.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
[mypy]
33

44
disallow_untyped_defs = True
5+
6+
mypy_path ='git'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp