55import json
66import logging
77from contextvars import ContextVar
8- from typing import TYPE_CHECKING , Any , Callable , NamedTuple , cast
8+ from typing import TYPE_CHECKING , Any , Callable , NamedTuple
99
1010# Conditional import only executed when type checking, otherwise we'd get circular dependency issues
1111if TYPE_CHECKING :
@@ -39,12 +39,12 @@ class LogContext(NamedTuple):
3939# Metaclass for resource clients which wraps all their public methods
4040# With injection of their details to the log context vars
4141class WithLogDetailsClient (type ):
42- def __new__ (cls : type [ type ] , name : str , bases : tuple , attrs : dict ) -> WithLogDetailsClient :
42+ def __new__ (cls , name : str , bases : tuple , attrs : dict ) -> WithLogDetailsClient :
4343 for attr_name , attr_value in attrs .items ():
4444 if not attr_name .startswith ('_' ) and inspect .isfunction (attr_value ):
4545 attrs [attr_name ] = _injects_client_details_to_log_context (attr_value )
4646
47- return cast ( WithLogDetailsClient , type .__new__ (cls , name , bases , attrs ) )
47+ return type .__new__ (cls , name , bases , attrs )
4848
4949
5050# Wraps an unbound method so that its call will inject the details
@@ -87,7 +87,7 @@ def wrapper(resource_client: _BaseBaseClient, *args: Any, **kwargs: Any) -> Any:
8787# A filter which lets every log record through,
8888# but adds the current logging context to the record
8989class _ContextInjectingFilter (logging .Filter ):
90- def filter (self : _ContextInjectingFilter , record : logging .LogRecord ) -> bool :
90+ def filter (self , record : logging .LogRecord ) -> bool :
9191 record .client_method = log_context .client_method .get ()
9292 record .resource_id = log_context .resource_id .get ()
9393 record .method = log_context .method .get ()
@@ -105,15 +105,15 @@ class _DebugLogFormatter(logging.Formatter):
105105 empty_record = logging .LogRecord ('dummy' , 0 , 'dummy' , 0 , 'dummy' , None , None )
106106
107107 # Gets the extra fields from the log record which are not present on an empty record
108- def _get_extra_fields (self : _DebugLogFormatter , record : logging .LogRecord ) -> dict :
108+ def _get_extra_fields (self , record : logging .LogRecord ) -> dict :
109109 extra_fields : dict = {}
110110 for key , value in record .__dict__ .items ():
111111 if key not in self .empty_record .__dict__ :
112112 extra_fields [key ] = value # noqa: PERF403
113113
114114 return extra_fields
115115
116- def format (self : _DebugLogFormatter , record : logging .LogRecord ) -> str :
116+ def format (self , record : logging .LogRecord ) -> str :
117117 extra = self ._get_extra_fields (record )
118118
119119 log_string = super ().format (record )
0 commit comments