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

Commit2d2ff03

Browse files
authored
Merge pull request#1279 from Yobmod/main
Finish typing object, improve verious other types.
2 parents703280b +5d7b8ba commit2d2ff03

16 files changed

+255
-148
lines changed

‎git/index/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ def write_tree(self) -> Tree:
568568
# note: additional deserialization could be saved if write_tree_from_cache
569569
# would return sorted tree entries
570570
root_tree=Tree(self.repo,binsha,path='')
571-
root_tree._cache=tree_items
571+
root_tree._cache=tree_items# type: ignore
572572
returnroot_tree
573573

574574
def_process_diff_args(self,args:List[Union[str,diff.Diffable,object]]

‎git/index/fun.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
fromtypingimport (Dict,IO,List,Sequence,TYPE_CHECKING,Tuple,Type,Union,cast)
5555

56-
fromgit.typesimportPathLike
56+
fromgit.typesimportPathLike,TypeGuard
5757

5858
ifTYPE_CHECKING:
5959
from .baseimportIndexFile
@@ -185,11 +185,17 @@ def read_header(stream: IO[bytes]) -> Tuple[int, int]:
185185
defentry_key(*entry:Union[BaseIndexEntry,PathLike,int])->Tuple[PathLike,int]:
186186
""":return: Key suitable to be used for the index.entries dictionary
187187
:param entry: One instance of type BaseIndexEntry or the path and the stage"""
188+
189+
defis_entry_tuple(entry:Tuple)->TypeGuard[Tuple[PathLike,int]]:
190+
returnisinstance(entry,tuple)andlen(entry)==2
191+
188192
iflen(entry)==1:
189-
entry_first=cast(BaseIndexEntry,entry[0])# type: BaseIndexEntry
193+
entry_first=entry[0]
194+
assertisinstance(entry_first,BaseIndexEntry)
190195
return (entry_first.path,entry_first.stage)
191196
else:
192-
entry=cast(Tuple[PathLike,int],tuple(entry))
197+
# entry = tuple(entry)
198+
assertis_entry_tuple(entry)
193199
returnentry
194200
# END handle entry
195201

@@ -293,7 +299,7 @@ def write_tree_from_cache(entries: List[IndexEntry], odb, sl: slice, si: int = 0
293299
# finally create the tree
294300
sio=BytesIO()
295301
tree_to_stream(tree_items,sio.write)# converts bytes of each item[0] to str
296-
tree_items_stringified=cast(List[Tuple[str,int,str]],tree_items)# type: List[Tuple[str, int, str]]
302+
tree_items_stringified=cast(List[Tuple[str,int,str]],tree_items)
297303
sio.seek(0)
298304

299305
istream=odb.store(IStream(str_tree_type,len(sio.getvalue()),sio))

‎git/objects/commit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
fromgit.utilimport (
99
hex_to_bin,
1010
Actor,
11-
Iterable,
11+
IterableObj,
1212
Stats,
1313
finalize_process
1414
)
@@ -47,7 +47,7 @@
4747
__all__= ('Commit', )
4848

4949

50-
classCommit(base.Object,Iterable,Diffable,Traversable,Serializable):
50+
classCommit(base.Object,IterableObj,Diffable,Traversable,Serializable):
5151

5252
"""Wraps a git Commit object.
5353

‎git/objects/fun.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
"""Module with functions which are supposed to be as fast as possible"""
22
fromstatimportS_ISDIR
3+
34
fromgit.compatimport (
45
safe_decode,
56
defenc
67
)
78

9+
# typing ----------------------------------------------
10+
11+
fromtypingimportList,Tuple
12+
13+
14+
# ---------------------------------------------------
15+
16+
817
__all__= ('tree_to_stream','tree_entries_from_data','traverse_trees_recursive',
918
'traverse_tree_recursive')
1019

@@ -38,7 +47,7 @@ def tree_to_stream(entries, write):
3847
# END for each item
3948

4049

41-
deftree_entries_from_data(data):
50+
deftree_entries_from_data(data:bytes)->List[Tuple[bytes,int,str]]:
4251
"""Reads the binary representation of a tree and returns tuples of Tree items
4352
:param data: data block with tree data (as bytes)
4453
:return: list(tuple(binsha, mode, tree_relative_path), ...)"""
@@ -72,8 +81,8 @@ def tree_entries_from_data(data):
7281

7382
# default encoding for strings in git is utf8
7483
# Only use the respective unicode object if the byte stream was encoded
75-
name=data[ns:i]
76-
name=safe_decode(name)
84+
name_bytes=data[ns:i]
85+
name=safe_decode(name_bytes)
7786

7887
# byte is NULL, get next 20
7988
i+=1

‎git/objects/submodule/base.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
importlogging
44
importos
55
importstat
6-
fromtypingimportList
76
fromunittestimportSkipTest
87
importuuid
98

@@ -27,12 +26,13 @@
2726
fromgit.objects.baseimportIndexObject,Object
2827
fromgit.objects.utilimportTraversable
2928
fromgit.utilimport (
30-
Iterable,
29+
IterableObj,
3130
join_path_native,
3231
to_native_path_linux,
3332
RemoteProgress,
3433
rmtree,
35-
unbare_repo
34+
unbare_repo,
35+
IterableList
3636
)
3737
fromgit.utilimportHIDE_WINDOWS_KNOWN_ERRORS
3838

@@ -47,6 +47,11 @@
4747
)
4848

4949

50+
# typing ----------------------------------------------------------------------
51+
52+
53+
# -----------------------------------------------------------------------------
54+
5055
__all__= ["Submodule","UpdateProgress"]
5156

5257

@@ -74,7 +79,7 @@ class UpdateProgress(RemoteProgress):
7479
# IndexObject comes via util module, its a 'hacky' fix thanks to pythons import
7580
# mechanism which cause plenty of trouble of the only reason for packages and
7681
# modules is refactoring - subpackages shouldn't depend on parent packages
77-
classSubmodule(IndexObject,Iterable,Traversable):
82+
classSubmodule(IndexObject,IterableObj,Traversable):
7883

7984
"""Implements access to a git submodule. They are special in that their sha
8085
represents a commit in the submodule's repository which is to be checked out
@@ -136,12 +141,12 @@ def _set_cache_(self, attr):
136141
# END handle attribute name
137142

138143
@classmethod
139-
def_get_intermediate_items(cls,item:'Submodule')->List['Submodule']:# type: ignore
144+
def_get_intermediate_items(cls,item:'Submodule')->IterableList['Submodule']:
140145
""":return: all the submodules of our module repository"""
141146
try:
142147
returncls.list_items(item.module())
143148
exceptInvalidGitRepositoryError:
144-
return[]
149+
returnIterableList('')
145150
# END handle intermediate items
146151

147152
@classmethod
@@ -1153,7 +1158,7 @@ def name(self):
11531158
"""
11541159
returnself._name
11551160

1156-
defconfig_reader(self):
1161+
defconfig_reader(self)->SectionConstraint:
11571162
"""
11581163
:return: ConfigReader instance which allows you to qurey the configuration values
11591164
of this submodule, as provided by the .gitmodules file
@@ -1163,7 +1168,7 @@ def config_reader(self):
11631168
:raise IOError: If the .gitmodules file/blob could not be read"""
11641169
returnself._config_parser_constrained(read_only=True)
11651170

1166-
defchildren(self):
1171+
defchildren(self)->IterableList['Submodule']:
11671172
"""
11681173
:return: IterableList(Submodule, ...) an iterable list of submodules instances
11691174
which are children of this submodule or 0 if the submodule is not checked out"""

‎git/objects/submodule/util.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
fromioimportBytesIO
55
importweakref
66

7+
fromtypingimportTYPE_CHECKING
8+
9+
ifTYPE_CHECKING:
10+
from .baseimportSubmodule
11+
712
__all__= ('sm_section','sm_name','mkhead','find_first_remote_branch',
813
'SubmoduleConfigParser')
914

@@ -60,12 +65,12 @@ def __init__(self, *args, **kwargs):
6065
super(SubmoduleConfigParser,self).__init__(*args,**kwargs)
6166

6267
#{ Interface
63-
defset_submodule(self,submodule):
68+
defset_submodule(self,submodule:'Submodule')->None:
6469
"""Set this instance's submodule. It must be called before
6570
the first write operation begins"""
6671
self._smref=weakref.ref(submodule)
6772

68-
defflush_to_index(self):
73+
defflush_to_index(self)->None:
6974
"""Flush changes in our configuration file to the index"""
7075
assertself._smrefisnotNone
7176
# should always have a file here

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp