88)
99from git .objects import Blob
1010
11+
12+ # typing ----------------------------------------------------------------------
13+
14+ from typing import (List , Sequence , TYPE_CHECKING , Tuple , cast )
15+
1116from git .types import PathLike
1217
18+ if TYPE_CHECKING :
19+ from git .repo import Repo
20+
21+ # ---------------------------------------------------------------------------------
1322
1423__all__ = ('BlobFilter' , 'BaseIndexEntry' , 'IndexEntry' )
1524
@@ -33,15 +42,15 @@ class BlobFilter(object):
3342 """
3443 __slots__ = 'paths'
3544
36- def __init__ (self , paths ) :
45+ def __init__ (self , paths : Sequence [ PathLike ]) -> None :
3746 """
3847 :param paths:
3948 tuple or list of paths which are either pointing to directories or
4049 to files relative to the current repository
4150 """
4251 self .paths = paths
4352
44- def __call__ (self , stage_blob ) :
53+ def __call__ (self , stage_blob : Blob ) -> bool :
4554 path = stage_blob [1 ].path
4655 for p in self .paths :
4756 if path .startswith (p ):
@@ -59,24 +68,24 @@ class BaseIndexEntry(tuple):
5968 expecting a BaseIndexEntry can also handle full IndexEntries even if they
6069 use numeric indices for performance reasons. """
6170
62- def __str__ (self ):
71+ def __str__ (self ) -> str :
6372 return "%o %s %i\t %s" % (self .mode , self .hexsha , self .stage , self .path )
6473
65- def __repr__ (self ):
74+ def __repr__ (self ) -> str :
6675 return "(%o, %s, %i, %s)" % (self .mode , self .hexsha , self .stage , self .path )
6776
6877 @property
69- def mode (self ):
78+ def mode (self ) -> int :
7079 """ File Mode, compatible to stat module constants """
7180 return self [0 ]
7281
7382 @property
74- def binsha (self ):
83+ def binsha (self ) -> bytes :
7584 """binary sha of the blob """
7685 return self [1 ]
7786
7887 @property
79- def hexsha (self ):
88+ def hexsha (self ) -> str :
8089 """hex version of our sha"""
8190 return b2a_hex (self [1 ]).decode ('ascii' )
8291
@@ -94,21 +103,21 @@ def stage(self) -> int:
94103 return (self [2 ] & CE_STAGEMASK ) >> CE_STAGESHIFT
95104
96105 @property
97- def path (self ) -> PathLike :
106+ def path (self ) -> str :
98107 """:return: our path relative to the repository working tree root"""
99108 return self [3 ]
100109
101110 @property
102- def flags (self ):
111+ def flags (self ) -> List [ str ] :
103112 """:return: flags stored with this entry"""
104113 return self [2 ]
105114
106115 @classmethod
107- def from_blob (cls , blob , stage = 0 ) :
116+ def from_blob (cls , blob : Blob , stage : int = 0 ) -> 'BaseIndexEntry' :
108117 """:return: Fully equipped BaseIndexEntry at the given stage"""
109118 return cls ((blob .mode , blob .binsha , stage << CE_STAGESHIFT , blob .path ))
110119
111- def to_blob (self , repo ) :
120+ def to_blob (self , repo : 'Repo' ) -> Blob :
112121 """:return: Blob using the information of this index entry"""
113122 return Blob (repo , self .binsha , self .mode , self .path )
114123
@@ -122,40 +131,40 @@ class IndexEntry(BaseIndexEntry):
122131
123132 See the properties for a mapping between names and tuple indices. """
124133 @property
125- def ctime (self ):
134+ def ctime (self ) -> Tuple [ int , int ] :
126135 """
127136 :return:
128137 Tuple(int_time_seconds_since_epoch, int_nano_seconds) of the
129138 file's creation time"""
130- return unpack (">LL" , self [4 ])
139+ return cast ( Tuple [ int , int ], unpack (">LL" , self [4 ]) )
131140
132141 @property
133- def mtime (self ):
142+ def mtime (self ) -> Tuple [ int , int ] :
134143 """See ctime property, but returns modification time """
135- return unpack (">LL" , self [5 ])
144+ return cast ( Tuple [ int , int ], unpack (">LL" , self [5 ]) )
136145
137146 @property
138- def dev (self ):
147+ def dev (self ) -> int :
139148 """ Device ID """
140149 return self [6 ]
141150
142151 @property
143- def inode (self ):
152+ def inode (self ) -> int :
144153 """ Inode ID """
145154 return self [7 ]
146155
147156 @property
148- def uid (self ):
157+ def uid (self ) -> int :
149158 """ User ID """
150159 return self [8 ]
151160
152161 @property
153- def gid (self ):
162+ def gid (self ) -> int :
154163 """ Group ID """
155164 return self [9 ]
156165
157166 @property
158- def size (self ):
167+ def size (self ) -> int :
159168 """:return: Uncompressed size of the blob """
160169 return self [10 ]
161170
@@ -171,7 +180,7 @@ def from_base(cls, base):
171180 return IndexEntry ((base .mode , base .binsha , base .flags , base .path , time , time , 0 , 0 , 0 , 0 , 0 ))
172181
173182 @classmethod
174- def from_blob (cls , blob , stage = 0 ) :
183+ def from_blob (cls , blob : Blob , stage : int = 0 ) -> 'IndexEntry' :
175184 """:return: Minimal entry resembling the given blob object"""
176185 time = pack (">LL" , 0 , 0 )
177186 return IndexEntry ((blob .mode , blob .binsha , stage << CE_STAGESHIFT , blob .path ,
0 commit comments