python: Simplify with str.removeprefix, str.removesuffix.

These are available in Python ≥ 3.9.
https://docs.python.org/3/library/stdtypes.html#str.removeprefix

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2024-09-03 10:42:14 -07:00
committed by Tim Abbott
parent 1ec4539550
commit 91ade25ba3
42 changed files with 79 additions and 92 deletions

View File

@@ -78,7 +78,7 @@ def get_or_create_key_prefix() -> str:
tries = 1
while tries < 10:
with open(filename) as f:
prefix = f.readline()[:-1]
prefix = f.readline().removesuffix("\n")
if len(prefix) == 33:
break
tries += 1
@@ -214,7 +214,7 @@ def cache_get_many(keys: list[str], cache_name: str | None = None) -> dict[str,
remote_cache_stats_start()
ret = get_cache_backend(cache_name).get_many(keys)
remote_cache_stats_finish()
return {key[len(KEY_PREFIX) :]: value for key, value in ret.items()}
return {key.removeprefix(KEY_PREFIX): value for key, value in ret.items()}
def safe_cache_get_many(keys: list[str], cache_name: str | None = None) -> dict[str, Any]: