1616import logging
1717import re
1818import typing
19- from typing import Any , Callable , Dict , Generator , Pattern
19+ from typing import Any , Callable , Dict , Generator , Optional , Pattern
2020
2121import attr
2222from frozendict import frozendict
@@ -110,7 +110,9 @@ def time_msec(self) -> int:
110110 """Returns the current system time in milliseconds since epoch."""
111111 return int (self .time () * 1000 )
112112
113- def looping_call (self , f : Callable , msec : float , * args , ** kwargs ) -> LoopingCall :
113+ def looping_call (
114+ self , f : Callable , msec : float , * args : Any , ** kwargs : Any
115+ ) -> LoopingCall :
114116 """Call a function repeatedly.
115117
116118 Waits `msec` initially before calling `f` for the first time.
@@ -130,20 +132,22 @@ def looping_call(self, f: Callable, msec: float, *args, **kwargs) -> LoopingCall
130132 d .addErrback (log_failure , "Looping call died" , consumeErrors = False )
131133 return call
132134
133- def call_later (self , delay , callback , * args , ** kwargs ) -> IDelayedCall :
135+ def call_later (
136+ self , delay : float , callback : Callable , * args : Any , ** kwargs : Any
137+ ) -> IDelayedCall :
134138 """Call something later
135139
136140 Note that the function will be called with no logcontext, so if it is anything
137141 other than trivial, you probably want to wrap it in run_as_background_process.
138142
139143 Args:
140- delay(float) : How long to wait in seconds.
141- callback(function) : Function to call
144+ delay: How long to wait in seconds.
145+ callback: Function to call
142146 *args: Postional arguments to pass to function.
143147 **kwargs: Key arguments to pass to function.
144148 """
145149
146- def wrapped_callback (* args , ** kwargs ) :
150+ def wrapped_callback (* args : Any , ** kwargs : Any ) -> None :
147151 with context .PreserveLoggingContext ():
148152 callback (* args , ** kwargs )
149153
@@ -158,25 +162,29 @@ def cancel_call_later(self, timer: IDelayedCall, ignore_errs: bool = False) -> N
158162 raise
159163
160164
161- def log_failure (failure , msg , consumeErrors = True ):
165+ def log_failure (
166+ failure : Failure , msg : str , consumeErrors : bool = True
167+ ) -> Optional [Failure ]:
162168 """Creates a function suitable for passing to `Deferred.addErrback` that
163169 logs any failures that occur.
164170
165171 Args:
166- msg (str): Message to log
167- consumeErrors (bool): If true consumes the failure, otherwise passes
168- on down the callback chain
172+ failure: The Failure to log
173+ msg: Message to log
174+ consumeErrors: If true consumes the failure, otherwise passes on down
175+ the callback chain
169176
170177 Returns:
171- func( Failure)
178+ The Failure if consumeErrors is false. None, otherwise.
172179 """
173180
174181 logger .error (
175- msg , exc_info = (failure .type , failure .value , failure .getTracebackObject ())
182+ msg , exc_info = (failure .type , failure .value , failure .getTracebackObject ()) # type: ignore[arg-type]
176183 )
177184
178185 if not consumeErrors :
179186 return failure
187+ return None
180188
181189
182190def glob_to_regex (glob : str , word_boundary : bool = False ) -> Pattern :
0 commit comments