make logging not use f-str, change others to f-str (#22882)

This commit is contained in:
Asuka Minato
2025-07-25 11:32:48 +09:00
committed by GitHub
parent 570aee5fe6
commit a189d293f8
164 changed files with 557 additions and 563 deletions

View File

@@ -95,7 +95,7 @@ def email(email):
if re.match(pattern, email) is not None:
return email
error = "{email} is not a valid email.".format(email=email)
error = f"{email} is not a valid email."
raise ValueError(error)
@@ -107,7 +107,7 @@ def uuid_value(value):
uuid_obj = uuid.UUID(value)
return str(uuid_obj)
except ValueError:
error = "{value} is not a valid uuid.".format(value=value)
error = f"{value} is not a valid uuid."
raise ValueError(error)
@@ -126,7 +126,7 @@ def timestamp_value(timestamp):
raise ValueError
return int_timestamp
except ValueError:
error = "{timestamp} is not a valid timestamp.".format(timestamp=timestamp)
error = f"{timestamp} is not a valid timestamp."
raise ValueError(error)
@@ -169,14 +169,14 @@ def _get_float(value):
try:
return float(value)
except (TypeError, ValueError):
raise ValueError("{} is not a valid float".format(value))
raise ValueError(f"{value} is not a valid float")
def timezone(timezone_string):
if timezone_string and timezone_string in available_timezones():
return timezone_string
error = "{timezone_string} is not a valid timezone.".format(timezone_string=timezone_string)
error = f"{timezone_string} is not a valid timezone."
raise ValueError(error)
@@ -321,7 +321,7 @@ class TokenManager:
key = cls._get_token_key(token, token_type)
token_data_json = redis_client.get(key)
if token_data_json is None:
logging.warning(f"{token_type} token {token} not found with key {key}")
logging.warning("%s token %s not found with key %s", token_type, token, key)
return None
token_data: Optional[dict[str, Any]] = json.loads(token_data_json)
return token_data

View File

@@ -50,13 +50,13 @@ def encrypt(text: str, public_key: Union[str, bytes]) -> bytes:
def get_decrypt_decoding(tenant_id: str) -> tuple[RSA.RsaKey, object]:
filepath = os.path.join("privkeys", tenant_id, "private.pem")
cache_key = "tenant_privkey:{hash}".format(hash=hashlib.sha3_256(filepath.encode()).hexdigest())
cache_key = f"tenant_privkey:{hashlib.sha3_256(filepath.encode()).hexdigest()}"
private_key = redis_client.get(cache_key)
if not private_key:
try:
private_key = storage.load(filepath)
except FileNotFoundError:
raise PrivkeyNotFoundError("Private key not found, tenant_id: {tenant_id}".format(tenant_id=tenant_id))
raise PrivkeyNotFoundError(f"Private key not found, tenant_id: {tenant_id}")
redis_client.setex(cache_key, 120, private_key)

View File

@@ -41,5 +41,5 @@ class SendGridClient:
)
raise
except Exception as e:
logging.exception(f"SendGridClient Unexpected error occurred while sending email to {_to}")
logging.exception("SendGridClient Unexpected error occurred while sending email to %s", _to)
raise

View File

@@ -50,7 +50,7 @@ class SMTPClient:
logging.exception("Timeout occurred while sending email")
raise
except Exception as e:
logging.exception(f"Unexpected error occurred while sending email to {mail['to']}")
logging.exception("Unexpected error occurred while sending email to %s", mail["to"])
raise
finally:
if smtp: