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

@@ -165,8 +165,8 @@ class BaseDocumentationSpider(scrapy.Spider):
if split_url.hostname == "github.com" and f"{split_url.path}/".startswith(
f"{ZULIP_SERVER_GITHUB_FILE_PATH_PREFIX}/"
):
file_path = (
DEPLOY_ROOT + split_url.path[len(ZULIP_SERVER_GITHUB_FILE_PATH_PREFIX) :]
file_path = DEPLOY_ROOT + split_url.path.removeprefix(
ZULIP_SERVER_GITHUB_FILE_PATH_PREFIX
)
if not os.path.isfile(file_path):
self.logger.error(
@@ -176,8 +176,8 @@ class BaseDocumentationSpider(scrapy.Spider):
elif split_url.hostname == "github.com" and f"{split_url.path}/".startswith(
f"{ZULIP_SERVER_GITHUB_DIRECTORY_PATH_PREFIX}/"
):
dir_path = (
DEPLOY_ROOT + split_url.path[len(ZULIP_SERVER_GITHUB_DIRECTORY_PATH_PREFIX) :]
dir_path = DEPLOY_ROOT + split_url.path.removeprefix(
ZULIP_SERVER_GITHUB_DIRECTORY_PATH_PREFIX
)
if not os.path.isdir(dir_path):
self.logger.error(