1717import calendar
1818from datetime import datetime , timedelta , tzinfo
1919
20+
21+ from typing import TYPE_CHECKING , Union
22+
23+ if TYPE_CHECKING :
24+ from .commit import Commit
25+ from .blob import Blob
26+ from .tag import TagObject
27+ from .tree import Tree
28+
2029__all__ = ('get_object_type_by_name' , 'parse_date' , 'parse_actor_and_date' ,
2130 'ProcessStreamAdapter' , 'Traversable' , 'altz_to_utctz_str' , 'utctz_to_altz' ,
2231 'verify_utctz' , 'Actor' , 'tzoffset' , 'utc' )
2635#{ Functions
2736
2837
29- def mode_str_to_int (modestr ) :
38+ def mode_str_to_int (modestr : str ) -> int :
3039 """
3140 :param modestr: string like 755 or 644 or 100644 - only the last 6 chars will be used
3241 :return:
@@ -41,7 +50,7 @@ def mode_str_to_int(modestr):
4150 return mode
4251
4352
44- def get_object_type_by_name (object_type_name ) :
53+ def get_object_type_by_name (object_type_name : str ) -> Union [ 'Commit' , 'TagObject' , 'Tree' , 'Blob' ] :
4554 """
4655 :return: type suitable to handle the given object type name.
4756 Use the type to create new instances.
@@ -65,15 +74,15 @@ def get_object_type_by_name(object_type_name):
6574 raise ValueError ("Cannot handle unknown object type: %s" % object_type_name )
6675
6776
68- def utctz_to_altz (utctz ) :
77+ def utctz_to_altz (utctz : str ) -> int :
6978 """we convert utctz to the timezone in seconds, it is the format time.altzone
7079 returns. Git stores it as UTC timezone which has the opposite sign as well,
7180 which explains the -1 * ( that was made explicit here )
7281 :param utctz: git utc timezone string, i.e. +0200"""
7382 return - 1 * int (float (utctz ) / 100 * 3600 )
7483
7584
76- def altz_to_utctz_str (altz ) :
85+ def altz_to_utctz_str (altz : int ) -> str :
7786 """As above, but inverses the operation, returning a string that can be used
7887 in commit objects"""
7988 utci = - 1 * int ((float (altz ) / 3600 ) * 100 )
@@ -83,7 +92,7 @@ def altz_to_utctz_str(altz):
8392 return prefix + utcs
8493
8594
86- def verify_utctz (offset ) :
95+ def verify_utctz (offset : str ) -> str :
8796 """:raise ValueError: if offset is incorrect
8897 :return: offset"""
8998 fmt_exc = ValueError ("Invalid timezone offset format: %s" % offset )
@@ -101,6 +110,7 @@ def verify_utctz(offset):
101110
102111
103112class tzoffset (tzinfo ):
113+
104114 def __init__ (self , secs_west_of_utc , name = None ):
105115 self ._offset = timedelta (seconds = - secs_west_of_utc )
106116 self ._name = name or 'fixed'
0 commit comments