1818from datetime import datetime , timedelta , tzinfo
1919
2020# typing ------------------------------------------------------------
21- from typing import Literal , TYPE_CHECKING , Tuple , Union
21+ from typing import Literal , TYPE_CHECKING , Tuple , Type , Union , cast
2222
2323if TYPE_CHECKING :
2424 from .commit import Commit
3636#{ Functions
3737
3838
39- def mode_str_to_int (modestr : str ) -> int :
39+ def mode_str_to_int (modestr : Union [ bytes , str ] ) -> int :
4040 """
4141 :param modestr: string like 755 or 644 or 100644 - only the last 6 chars will be used
4242 :return:
@@ -46,12 +46,14 @@ def mode_str_to_int(modestr: str) -> int:
4646 for example."""
4747 mode = 0
4848 for iteration , char in enumerate (reversed (modestr [- 6 :])):
49+ char = cast (Union [str , int ], char )
4950 mode += int (char ) << iteration * 3
5051 # END for each char
5152 return mode
5253
5354
54- def get_object_type_by_name (object_type_name : str ) -> Union ['Commit' , 'TagObject' , 'Tree' , 'Blob' ]:
55+ def get_object_type_by_name (object_type_name : bytes
56+ ) -> Union [Type ['Commit' ], Type ['TagObject' ], Type ['Tree' ], Type ['Blob' ]]:
5557 """
5658 :return: type suitable to handle the given object type name.
5759 Use the type to create new instances.
@@ -72,7 +74,7 @@ def get_object_type_by_name(object_type_name: str) -> Union['Commit', 'TagObject
7274 from . import tree
7375 return tree .Tree
7476 else :
75- raise ValueError ("Cannot handle unknown object type: %s" % object_type_name )
77+ raise ValueError ("Cannot handle unknown object type: %s" % object_type_name . decode () )
7678
7779
7880def utctz_to_altz (utctz : str ) -> int :
@@ -116,7 +118,7 @@ def __init__(self, secs_west_of_utc: float, name: Union[None, str] = None) -> No
116118 self ._offset = timedelta (seconds = - secs_west_of_utc )
117119 self ._name = name or 'fixed'
118120
119- def __reduce__ (self ) -> Tuple ['tzoffset' , Tuple [float , str ]]:
121+ def __reduce__ (self ) -> Tuple [Type [ 'tzoffset' ] , Tuple [float , str ]]:
120122 return tzoffset , (- self ._offset .total_seconds (), self ._name )
121123
122124 def utcoffset (self , dt ) -> timedelta :
@@ -163,18 +165,18 @@ def parse_date(string_date: str) -> Tuple[int, int]:
163165 # git time
164166 try :
165167 if string_date .count (' ' ) == 1 and string_date .rfind (':' ) == - 1 :
166- timestamp , offset = string_date .split ()
168+ timestamp , offset_str = string_date .split ()
167169 if timestamp .startswith ('@' ):
168170 timestamp = timestamp [1 :]
169- timestamp = int (timestamp )
170- return timestamp , utctz_to_altz (verify_utctz (offset ))
171+ timestamp_int = int (timestamp )
172+ return timestamp_int , utctz_to_altz (verify_utctz (offset_str ))
171173 else :
172- offset = "+0000" # local time by default
174+ offset_str = "+0000" # local time by default
173175 if string_date [- 5 ] in '-+' :
174- offset = verify_utctz (string_date [- 5 :])
176+ offset_str = verify_utctz (string_date [- 5 :])
175177 string_date = string_date [:- 6 ] # skip space as well
176178 # END split timezone info
177- offset = utctz_to_altz (offset )
179+ offset = utctz_to_altz (offset_str )
178180
179181 # now figure out the date and time portion - split time
180182 date_formats = []
@@ -235,7 +237,7 @@ def parse_actor_and_date(line: str) -> Tuple[Actor, int, int]:
235237 author Tom Preston-Werner <tom@mojombo.com> 1191999972 -0700
236238
237239 :return: [Actor, int_seconds_since_epoch, int_timezone_offset]"""
238- actor , epoch , offset = '' , 0 , 0
240+ actor , epoch , offset = '' , '0' , '0'
239241 m = _re_actor_epoch .search (line )
240242 if m :
241243 actor , epoch , offset = m .groups ()
0 commit comments