1717import calendar
1818from datetime import datetime , timedelta , tzinfo
1919
20-
21- from typing import TYPE_CHECKING , Union
20+ # typing ------------------------------------------------------------
21+ from typing import Literal , TYPE_CHECKING , Tuple , Union
2222
2323if TYPE_CHECKING :
2424 from .commit import Commit
2525 from .blob import Blob
2626 from .tag import TagObject
2727 from .tree import Tree
28+ from subprocess import Popen
2829
2930__all__ = ('get_object_type_by_name' , 'parse_date' , 'parse_actor_and_date' ,
3031 'ProcessStreamAdapter' , 'Traversable' , 'altz_to_utctz_str' , 'utctz_to_altz' ,
@@ -111,27 +112,27 @@ def verify_utctz(offset: str) -> str:
111112
112113class tzoffset (tzinfo ):
113114
114- def __init__ (self , secs_west_of_utc , name = None ):
115+ def __init__ (self , secs_west_of_utc : float , name : Union [ None , str ] = None ) -> None :
115116 self ._offset = timedelta (seconds = - secs_west_of_utc )
116117 self ._name = name or 'fixed'
117118
118- def __reduce__ (self ):
119+ def __reduce__ (self ) -> Tuple [ 'tzoffset' , Tuple [ float , str ]] :
119120 return tzoffset , (- self ._offset .total_seconds (), self ._name )
120121
121- def utcoffset (self , dt ):
122+ def utcoffset (self , dt ) -> timedelta :
122123 return self ._offset
123124
124- def tzname (self , dt ):
125+ def tzname (self , dt ) -> str :
125126 return self ._name
126127
127- def dst (self , dt ):
128+ def dst (self , dt ) -> timedelta :
128129 return ZERO
129130
130131
131132utc = tzoffset (0 , 'UTC' )
132133
133134
134- def from_timestamp (timestamp , tz_offset ) :
135+ def from_timestamp (timestamp , tz_offset : float ) -> datetime :
135136 """Converts a timestamp + tz_offset into an aware datetime instance."""
136137 utc_dt = datetime .fromtimestamp (timestamp , utc )
137138 try :
@@ -141,7 +142,7 @@ def from_timestamp(timestamp, tz_offset):
141142 return utc_dt
142143
143144
144- def parse_date (string_date ) :
145+ def parse_date (string_date : str ) -> Tuple [ int , int ] :
145146 """
146147 Parse the given date as one of the following
147148
@@ -228,7 +229,7 @@ def parse_date(string_date):
228229_re_only_actor = re .compile (r'^.+? (.*)$' )
229230
230231
231- def parse_actor_and_date (line ) :
232+ def parse_actor_and_date (line : str ) -> Tuple [ Actor , int , int ] :
232233 """Parse out the actor (author or committer) info from a line like::
233234
234235 author Tom Preston-Werner <tom@mojombo.com> 1191999972 -0700
@@ -257,7 +258,7 @@ class ProcessStreamAdapter(object):
257258 it if the instance goes out of scope."""
258259 __slots__ = ("_proc" , "_stream" )
259260
260- def __init__ (self , process , stream_name ):
261+ def __init__ (self , process : Popen , stream_name : str ):
261262 self ._proc = process
262263 self ._stream = getattr (process , stream_name )
263264
0 commit comments