@@ -78,7 +78,7 @@ def _sanitize_error_message_text(message: str) -> str:
7878
7979
8080def _has_non_blank_text (value : Any ) -> bool :
81- if not isinstance (value , str ) :
81+ if type (value ) is not str :
8282 return False
8383 try :
8484 stripped_value = value .strip ()
@@ -170,8 +170,7 @@ def _normalize_request_url(url: Any) -> str:
170170 if any (character .isspace () for character in normalized_url ):
171171 return "unknown URL"
172172 if any (
173- ord (character ) < 32 or ord (character ) == 127
174- for character in normalized_url
173+ ord (character ) < 32 or ord (character ) == 127 for character in normalized_url
175174 ):
176175 return "unknown URL"
177176 if len (normalized_url ) > _MAX_REQUEST_URL_DISPLAY_LENGTH :
@@ -192,14 +191,16 @@ def _truncate_error_message(message: str) -> str:
192191
193192
194193def _normalize_response_text_for_error_message (response_text : Any ) -> str :
195- if isinstance (response_text , str ) :
194+ if type (response_text ) is str :
196195 try :
197196 normalized_response_text = "" .join (character for character in response_text )
198197 if type (normalized_response_text ) is not str :
199198 raise TypeError ("normalized response text must be a string" )
200199 return normalized_response_text
201200 except Exception :
202201 return _safe_to_string (response_text )
202+ if isinstance (response_text , str ):
203+ return _safe_to_string (response_text )
203204 if isinstance (response_text , (bytes , bytearray , memoryview )):
204205 try :
205206 return memoryview (response_text ).tobytes ().decode ("utf-8" )
@@ -211,14 +212,16 @@ def _normalize_response_text_for_error_message(response_text: Any) -> str:
211212def _stringify_error_value (value : Any , * , _depth : int = 0 ) -> str :
212213 if _depth > 10 :
213214 return _safe_to_string (value )
214- if isinstance (value , str ) :
215+ if type (value ) is str :
215216 try :
216217 normalized_value = "" .join (character for character in value )
217218 if type (normalized_value ) is not str :
218219 raise TypeError ("normalized error value must be a string" )
219220 return normalized_value
220221 except Exception :
221222 return _safe_to_string (value )
223+ if isinstance (value , str ):
224+ return _safe_to_string (value )
222225 if isinstance (value , Mapping ):
223226 for key in ("message" , "error" , "detail" , "errors" , "msg" , "title" , "reason" ):
224227 try :
@@ -289,7 +292,7 @@ def _fallback_message() -> str:
289292 break
290293 else :
291294 extracted_message = _stringify_error_value (error_data )
292- elif isinstance (error_data , str ) :
295+ elif type (error_data ) is str :
293296 extracted_message = error_data
294297 else :
295298 extracted_message = _stringify_error_value (error_data )
0 commit comments