18
18
import os
19
19
import uuid
20
20
from datetime import datetime
21
- from typing import Dict , Iterable , Tuple
21
+ from typing import Any , Dict , Tuple
22
22
from uuid import uuid4
23
23
24
24
from marshmallow import ValidationError
@@ -68,7 +68,7 @@ def __init__(self, logger: logging.Logger, activity_info: str):
68
68
:type activity_info: str
69
69
"""
70
70
self ._activity_info = activity_info
71
- super (ActivityLoggerAdapter , self ).__init__ (logger , None )
71
+ super (ActivityLoggerAdapter , self ).__init__ (logger , None ) # type: ignore[arg-type]
72
72
73
73
@property
74
74
def activity_info (self ) -> str :
@@ -79,7 +79,7 @@ def activity_info(self) -> str:
79
79
"""
80
80
return self ._activity_info
81
81
82
- def process (self , msg : str , kwargs : Dict ) -> Tuple [str , Dict ]:
82
+ def process (self , msg : str , kwargs : Dict ) -> Tuple [str , Dict ]: # type: ignore[override]
83
83
"""Process the log message.
84
84
85
85
:param msg: The log message.
@@ -158,7 +158,7 @@ def log_activity(
158
158
activity_name ,
159
159
activity_type = ActivityType .INTERNALCALL ,
160
160
custom_dimensions = None ,
161
- ) -> Iterable [ ActivityLoggerAdapter ] :
161
+ ) -> Any :
162
162
"""Log an activity.
163
163
164
164
An activity is a logical block of code that consumers want to monitor.
@@ -190,7 +190,7 @@ def log_activity(
190
190
completion_status = ActivityCompletionStatus .SUCCESS
191
191
192
192
message = "ActivityStarted, {}" .format (activity_name )
193
- activityLogger = ActivityLoggerAdapter (logger , activity_info )
193
+ activityLogger = ActivityLoggerAdapter (logger , activity_info ) # type: ignore[arg-type]
194
194
activityLogger .info (message )
195
195
exception = None
196
196
@@ -207,7 +207,8 @@ def log_activity(
207
207
in [ErrorCategory .SYSTEM_ERROR , ErrorCategory .UNKNOWN ]
208
208
) or (
209
209
"errorCategory" in activityLogger .activity_info
210
- and activityLogger .activity_info ["errorCategory" ] in [ErrorCategory .SYSTEM_ERROR , ErrorCategory .UNKNOWN ]
210
+ and activityLogger .activity_info ["errorCategory" ] # type: ignore[index]
211
+ in [ErrorCategory .SYSTEM_ERROR , ErrorCategory .UNKNOWN ]
211
212
):
212
213
raise Exception ("Got InternalSDKError" , e ) from e
213
214
raise
@@ -217,25 +218,28 @@ def log_activity(
217
218
end_time = datetime .utcnow ()
218
219
duration_ms = round ((end_time - start_time ).total_seconds () * 1000 , 2 )
219
220
220
- activityLogger .activity_info ["completionStatus" ] = completion_status
221
- activityLogger .activity_info ["durationMs" ] = duration_ms
221
+ activityLogger .activity_info ["completionStatus" ] = completion_status # type: ignore[index]
222
+ activityLogger .activity_info ["durationMs" ] = duration_ms # type: ignore[index]
222
223
message = "ActivityCompleted: Activity={}, HowEnded={}, Duration={} [ms]" .format (
223
224
activity_name , completion_status , duration_ms
224
225
)
225
226
if exception :
226
227
message += ", Exception={}" .format (type (exception ).__name__ )
227
- activityLogger .activity_info ["exception" ] = type (exception ).__name__
228
+ activityLogger .activity_info ["exception" ] = type (exception ).__name__ # type: ignore[index]
228
229
if isinstance (exception , MlException ):
229
- activityLogger .activity_info [
230
+ activityLogger .activity_info [ # type: ignore[index]
230
231
"errorMessage"
231
232
] = exception .no_personal_data_message # pylint: disable=no-member
232
- activityLogger .activity_info ["errorTarget" ] = exception .target # pylint: disable=no-member
233
- activityLogger .activity_info [
233
+ # pylint: disable=no-member
234
+ activityLogger .activity_info ["errorTarget" ] = exception .target # type: ignore[index]
235
+ activityLogger .activity_info [ # type: ignore[index]
234
236
"errorCategory"
235
237
] = exception .error_category # pylint: disable=no-member
236
238
if exception .inner_exception : # pylint: disable=no-member
237
239
# pylint: disable=no-member
238
- activityLogger .activity_info ["innerException" ] = type (exception .inner_exception ).__name__
240
+ activityLogger .activity_info ["innerException" ] = type ( # type: ignore[index]
241
+ exception .inner_exception
242
+ ).__name__
239
243
activityLogger .error (message )
240
244
else :
241
245
activityLogger .info (message )
0 commit comments