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

Commit6609ef7

Browse files
committed
Make types in refs compatible with objects
1 parent29e12e9 commit6609ef7

File tree

7 files changed

+30
-23
lines changed

7 files changed

+30
-23
lines changed

‎git/objects/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
# typing ------------------------------------------------------------------
1717

18-
fromtypingimportAny,TYPE_CHECKING,Optional,Union
18+
fromtypingimportAny,TYPE_CHECKING,Union
1919

20-
fromgit.typesimportPathLike,Commit_ish
20+
fromgit.typesimportPathLike,Commit_ish,Lit_commit_ish
2121

2222
ifTYPE_CHECKING:
2323
fromgit.repoimportRepo
@@ -44,7 +44,7 @@ class Object(LazyMixin):
4444

4545
TYPES= (dbtyp.str_blob_type,dbtyp.str_tree_type,dbtyp.str_commit_type,dbtyp.str_tag_type)
4646
__slots__= ("repo","binsha","size")
47-
type=None# type: Optional[str] # to be set by subclass
47+
type:Union[Lit_commit_ish,None]=None
4848

4949
def__init__(self,repo:'Repo',binsha:bytes):
5050
"""Initialize an object by identifying it by its binary sha.

‎git/objects/blob.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
frommimetypesimportguess_type
77
from .importbase
88

9+
fromgit.typesimportLiteral
10+
911
__all__= ('Blob', )
1012

1113

1214
classBlob(base.IndexObject):
1315

1416
"""A Blob encapsulates a git blob object"""
1517
DEFAULT_MIME_TYPE="text/plain"
16-
type="blob"
18+
type:Literal['blob']="blob"
1719

1820
# valid blob modes
1921
executable_mode=0o100755

‎git/objects/commit.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@
4141

4242
fromtypingimportAny,IO,Iterator,List,Sequence,Tuple,Union,TYPE_CHECKING
4343

44-
fromgit.typesimportPathLike,TypeGuard
44+
fromgit.typesimportPathLike,TypeGuard,Literal
4545

4646
ifTYPE_CHECKING:
4747
fromgit.repoimportRepo
48+
fromgit.refsimportSymbolicReference
4849

4950
# ------------------------------------------------------------------------
5051

@@ -73,14 +74,14 @@ class Commit(base.Object, TraversableIterableObj, Diffable, Serializable):
7374
default_encoding="UTF-8"
7475

7576
# object configuration
76-
type="commit"
77+
type:Literal['commit']="commit"
7778
__slots__= ("tree",
7879
"author","authored_date","author_tz_offset",
7980
"committer","committed_date","committer_tz_offset",
8081
"message","parents","encoding","gpgsig")
8182
_id_attribute_="hexsha"
8283

83-
def__init__(self,repo:'Repo',binsha:bytes,tree:Union['Tree',None]=None,
84+
def__init__(self,repo:'Repo',binsha:bytes,tree:Union[Tree,None]=None,
8485
author:Union[Actor,None]=None,
8586
authored_date:Union[int,None]=None,
8687
author_tz_offset:Union[None,float]=None,
@@ -201,11 +202,11 @@ def _set_cache_(self, attr: str) -> None:
201202
# END handle attrs
202203

203204
@property
204-
defauthored_datetime(self)->'datetime.datetime':
205+
defauthored_datetime(self)->datetime.datetime:
205206
returnfrom_timestamp(self.authored_date,self.author_tz_offset)
206207

207208
@property
208-
defcommitted_datetime(self)->'datetime.datetime':
209+
defcommitted_datetime(self)->datetime.datetime:
209210
returnfrom_timestamp(self.committed_date,self.committer_tz_offset)
210211

211212
@property
@@ -242,7 +243,7 @@ def name_rev(self) -> str:
242243
returnself.repo.git.name_rev(self)
243244

244245
@classmethod
245-
defiter_items(cls,repo:'Repo',rev:str,# type: ignore
246+
defiter_items(cls,repo:'Repo',rev:Union[str,'Commit','SymbolicReference'],# type: ignore
246247
paths:Union[PathLike,Sequence[PathLike]]='',**kwargs:Any
247248
)->Iterator['Commit']:
248249
"""Find all commits matching the given criteria.
@@ -354,7 +355,7 @@ def is_stream(inp) -> TypeGuard[IO]:
354355
finalize_process(proc_or_stream)
355356

356357
@classmethod
357-
defcreate_from_tree(cls,repo:'Repo',tree:Union['Tree',str],message:str,
358+
defcreate_from_tree(cls,repo:'Repo',tree:Union[Tree,str],message:str,
358359
parent_commits:Union[None,List['Commit']]=None,head:bool=False,
359360
author:Union[None,Actor]=None,committer:Union[None,Actor]=None,
360361
author_date:Union[None,str]=None,commit_date:Union[None,str]=None):
@@ -516,8 +517,10 @@ def _serialize(self, stream: BytesIO) -> 'Commit':
516517
returnself
517518

518519
def_deserialize(self,stream:BytesIO)->'Commit':
519-
""":param from_rev_list: if true, the stream format is coming from the rev-list command
520-
Otherwise it is assumed to be a plain data stream from our object"""
520+
"""
521+
:param from_rev_list: if true, the stream format is coming from the rev-list command
522+
Otherwise it is assumed to be a plain data stream from our object
523+
"""
521524
readline=stream.readline
522525
self.tree=Tree(self.repo,hex_to_bin(readline().split()[1]),Tree.tree_id<<12,'')
523526

‎git/objects/fun.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def traverse_trees_recursive(odb: 'GitCmdObjectDB', tree_shas: Sequence[Union[by
167167
data:List[EntryTupOrNone]= []
168168
else:
169169
# make new list for typing as list invariant
170-
data=[xforxintree_entries_from_data(odb.stream(tree_sha).read())]
170+
data=list(tree_entries_from_data(odb.stream(tree_sha).read()))
171171
# END handle muted trees
172172
trees_data.append(data)
173173
# END for each sha to get data for

‎git/objects/submodule/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
fromtypingimportCallable,Dict,Mapping,Sequence,TYPE_CHECKING,cast
5353
fromtypingimportAny,Iterator,Union
5454

55-
fromgit.typesimportCommit_ish,PathLike,TBD
55+
fromgit.typesimportCommit_ish,Literal,PathLike,TBD
5656

5757
ifTYPE_CHECKING:
5858
fromgit.indeximportIndexFile
@@ -105,7 +105,7 @@ class Submodule(IndexObject, TraversableIterableObj):
105105
k_default_mode=stat.S_IFDIR|stat.S_IFLNK# submodules are directories with link-status
106106

107107
# this is a bogus type for base class compatibility
108-
type='submodule'
108+
type:Literal['submodule']='submodule'# type: ignore
109109

110110
__slots__= ('_parent_commit','_url','_branch_path','_name','__weakref__')
111111
_cache_attrs= ('path','_url','_branch_path')

‎git/objects/tag.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
fromtypingimportList,TYPE_CHECKING,Union
1313

14+
fromgit.typesimportLiteral
15+
1416
ifTYPE_CHECKING:
1517
fromgit.repoimportRepo
1618
fromgit.utilimportActor
@@ -24,7 +26,7 @@
2426
classTagObject(base.Object):
2527

2628
"""Non-Lightweight tag carrying additional information about an object we are pointing to."""
27-
type="tag"
29+
type:Literal['tag']="tag"
2830
__slots__= ("object","tag","tagger","tagged_date","tagger_tz_offset","message")
2931

3032
def__init__(self,repo:'Repo',binsha:bytes,

‎git/objects/tree.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
fromtypingimport (Any,Callable,Dict,Iterable,Iterator,List,
2525
Tuple,Type,Union,cast,TYPE_CHECKING)
2626

27-
fromgit.typesimportPathLike,TypeGuard
27+
fromgit.typesimportPathLike,TypeGuard,Literal
2828

2929
ifTYPE_CHECKING:
3030
fromgit.repoimportRepo
@@ -195,7 +195,7 @@ class Tree(IndexObject, git_diff.Diffable, util.Traversable, util.Serializable):
195195
blob = tree[0]
196196
"""
197197

198-
type="tree"
198+
type:Literal['tree']="tree"
199199
__slots__="_cache"
200200

201201
# actual integer ids for comparison
@@ -285,7 +285,7 @@ def trees(self) -> List['Tree']:
285285
return [iforiinselfifi.type=="tree"]
286286

287287
@property
288-
defblobs(self)->List['Blob']:
288+
defblobs(self)->List[Blob]:
289289
""":return: list(Blob, ...) list of blobs directly below this tree"""
290290
return [iforiinselfifi.type=="blob"]
291291

@@ -322,16 +322,16 @@ def traverse(self, # type: ignore # overrides super()
322322
# assert is_tree_traversed(ret_tup), f"Type is {[type(x) for x in list(ret_tup[0])]}"
323323
# return ret_tup[0]"""
324324
returncast(Union[Iterator[IndexObjUnion],Iterator[TraversedTreeTup]],
325-
super(Tree,self).traverse(predicate,prune,depth,# type: ignore
326-
branch_first,visit_once,ignore_self))
325+
super(Tree,self)._traverse(predicate,prune,depth,# type: ignore
326+
branch_first,visit_once,ignore_self))
327327

328328
deflist_traverse(self,*args:Any,**kwargs:Any)->IterableList[IndexObjUnion]:
329329
"""
330330
:return: IterableList with the results of the traversal as produced by
331331
traverse()
332332
Tree -> IterableList[Union['Submodule', 'Tree', 'Blob']]
333333
"""
334-
returnsuper(Tree,self).list_traverse(*args,**kwargs)
334+
returnsuper(Tree,self)._list_traverse(*args,**kwargs)
335335

336336
# List protocol
337337

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp