From 948171a8391d9241b0645eafb6a81433de1c70ec Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 19 Jul 2023 14:09:25 -0700 Subject: [PATCH] ruff: Fix B034 `re.split`, `re.sub` should pass keyword arguments. Signed-off-by: Anders Kaseorg (cherry picked from commit d87eea1a6771e550f8bbd5b36a04c7b8ec84c916) --- zerver/lib/email_mirror.py | 2 +- zerver/lib/widget.py | 2 +- zerver/migrations/0041_create_attachments_for_old_messages.py | 2 +- zerver/webhooks/gitlab/view.py | 4 +++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/zerver/lib/email_mirror.py b/zerver/lib/email_mirror.py index 4730b541c5..406dd00ccd 100644 --- a/zerver/lib/email_mirror.py +++ b/zerver/lib/email_mirror.py @@ -311,7 +311,7 @@ def filter_footer(text: str) -> str: # isn't a trivial footer structure. return text - return re.split(r"^\s*--\s*$", text, 1, flags=re.MULTILINE)[0].strip() + return re.split(r"^\s*--\s*$", text, maxsplit=1, flags=re.MULTILINE)[0].strip() def extract_and_upload_attachments(message: EmailMessage, realm: Realm, sender: UserProfile) -> str: diff --git a/zerver/lib/widget.py b/zerver/lib/widget.py index c3be37810c..2eabedf08c 100644 --- a/zerver/lib/widget.py +++ b/zerver/lib/widget.py @@ -33,7 +33,7 @@ def get_extra_data_from_widget_type(content: str, widget_type: Optional[str]) -> for line in lines: # If someone is using the list syntax, we remove it # before adding an option. - option = re.sub(r"(\s*[-*]?\s*)", "", line.strip(), 1) + option = re.sub(r"(\s*[-*]?\s*)", "", line.strip(), count=1) if len(option) > 0: options.append(option) extra_data = { diff --git a/zerver/migrations/0041_create_attachments_for_old_messages.py b/zerver/migrations/0041_create_attachments_for_old_messages.py index f9fd4ac39d..18aa8da1c1 100644 --- a/zerver/migrations/0041_create_attachments_for_old_messages.py +++ b/zerver/migrations/0041_create_attachments_for_old_messages.py @@ -11,7 +11,7 @@ attachment_url_re = re.compile(r"[/\-]user[\-_]uploads[/\.-].*?(?=[ )]|\Z)") def attachment_url_to_path_id(attachment_url: str) -> str: path_id_raw = re.sub(r"[/\-]user[\-_]uploads[/\.-]", "", attachment_url) # Remove any extra '.' after file extension. These are probably added by the user - return re.sub("[.]+$", "", path_id_raw, re.M) + return re.sub("[.]+$", "", path_id_raw, flags=re.M) def check_and_create_attachments(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None: diff --git a/zerver/webhooks/gitlab/view.py b/zerver/webhooks/gitlab/view.py index 4c4c0db527..d700708de8 100644 --- a/zerver/webhooks/gitlab/view.py +++ b/zerver/webhooks/gitlab/view.py @@ -89,7 +89,9 @@ def get_issue_created_event_body(payload: WildValue, include_title: bool) -> str # Filter out multiline hidden comments if description: stringified_description = description.tame(check_string) - stringified_description = re.sub("", "", stringified_description, 0, re.DOTALL) + stringified_description = re.sub( + "", "", stringified_description, count=0, flags=re.DOTALL + ) stringified_description = stringified_description.rstrip() else: stringified_description = None