From 81bd63cb46273b8c94ef9e92c00893ed97110119 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 1 Sep 2023 14:05:08 -0700 Subject: [PATCH] ruff: Fix PIE808 Unnecessary `start` argument in `range`. Signed-off-by: Anders Kaseorg --- analytics/views/stats.py | 4 ++-- scripts/lib/supervisor.py | 2 +- scripts/log-search | 2 +- tools/renumber-migrations | 2 +- zerver/lib/upload/base.py | 2 +- zerver/tests/test_decorators.py | 2 +- zerver/tests/test_drafts.py | 2 +- zerver/tests/test_email_mirror.py | 4 ++-- zerver/tests/test_message_flags.py | 2 +- .../tests/test_message_notification_emails.py | 8 ++++---- zerver/tests/test_retention.py | 18 +++++++++--------- zerver/tests/test_upload.py | 2 +- 12 files changed, 25 insertions(+), 25 deletions(-) diff --git a/analytics/views/stats.py b/analytics/views/stats.py index a2679bed67..a31dcb9ab5 100644 --- a/analytics/views/stats.py +++ b/analytics/views/stats.py @@ -507,10 +507,10 @@ def rewrite_client_arrays(value_arrays: Dict[str, List[int]]) -> Dict[str, List[ for label, array in value_arrays.items(): mapped_label = client_label_map(label) if mapped_label in mapped_arrays: - for i in range(0, len(array)): + for i in range(len(array)): mapped_arrays[mapped_label][i] += value_arrays[label][i] else: - mapped_arrays[mapped_label] = [value_arrays[label][i] for i in range(0, len(array))] + mapped_arrays[mapped_label] = [value_arrays[label][i] for i in range(len(array))] return mapped_arrays diff --git a/scripts/lib/supervisor.py b/scripts/lib/supervisor.py index 41998fee13..fccf522977 100644 --- a/scripts/lib/supervisor.py +++ b/scripts/lib/supervisor.py @@ -9,7 +9,7 @@ class UnixStreamHTTPConnection(HTTPConnection): def connect(self) -> None: self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) connected = False - for i in range(0, 2): + for i in range(2): try: self.sock.connect(self.host) connected = True diff --git a/scripts/log-search b/scripts/log-search index 26026bb46d..bb6a6f5b30 100755 --- a/scripts/log-search +++ b/scripts/log-search @@ -63,7 +63,7 @@ def parser() -> argparse.ArgumentParser: "-H", help="Estimated minimum number of hours; includes previous log file, if estimated less than this", type=int, - choices=range(0, 24), + choices=range(24), default=3, ) log_selection.add_argument( diff --git a/tools/renumber-migrations b/tools/renumber-migrations index e25e8bebef..9eebf9ec7c 100755 --- a/tools/renumber-migrations +++ b/tools/renumber-migrations @@ -40,7 +40,7 @@ def renumber_migration(conflicts: List[str], order: List[int], last_correct_migr def resolve_conflicts(conflicts: List[str], files_list: List[str]) -> None: print("Conflicting migrations:") - for i in range(0, len(conflicts)): + for i in range(len(conflicts)): print(str(i + 1) + ". " + conflicts[i]) order_input = input("Enter the order in which these migrations should be arranged: ") diff --git a/zerver/lib/upload/base.py b/zerver/lib/upload/base.py index df77870dbb..eaba0bb4f3 100644 --- a/zerver/lib/upload/base.py +++ b/zerver/lib/upload/base.py @@ -98,7 +98,7 @@ def resize_animated(im: Image.Image, size: int = DEFAULT_EMOJI_SIZE) -> bytes: disposals = [] # If 'loop' info is not set then loop for infinite number of times. loop = im.info.get("loop", 0) - for frame_num in range(0, im.n_frames): + for frame_num in range(im.n_frames): im.seek(frame_num) new_frame = im.copy() new_frame.paste(im, (0, 0), im.convert("RGBA")) diff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.py index f7b47291b3..259b372600 100644 --- a/zerver/tests/test_decorators.py +++ b/zerver/tests/test_decorators.py @@ -889,7 +889,7 @@ class TestValidateApiKey(ZulipTestCase): self.assertFalse(has_api_key_format("33LONGXXXXXXXXXXXXXXXXXXXXXXXXXXX")) self.assertTrue(has_api_key_format("VIzRVw2CspUOnEm9Yu5vQiQtJNkvETkp")) - for i in range(0, 10): + for i in range(10): self.assertTrue(has_api_key_format(generate_api_key())) def test_validate_api_key_if_profile_does_not_exist(self) -> None: diff --git a/zerver/tests/test_drafts.py b/zerver/tests/test_drafts.py index 9fefe2560b..b69b6a6780 100644 --- a/zerver/tests/test_drafts.py +++ b/zerver/tests/test_drafts.py @@ -567,7 +567,7 @@ class DraftFetchTest(ZulipTestCase): first_draft_id = Draft.objects.filter(user_profile=hamlet).order_by("id")[0].id expected_draft_contents: List[Dict[str, object]] = [ - {"id": first_draft_id + i, **draft_dicts[i]} for i in range(0, 3) + {"id": first_draft_id + i, **draft_dicts[i]} for i in range(3) ] self.assertEqual(data["drafts"], expected_draft_contents) diff --git a/zerver/tests/test_email_mirror.py b/zerver/tests/test_email_mirror.py index debd952cb1..abe7a61e97 100644 --- a/zerver/tests/test_email_mirror.py +++ b/zerver/tests/test_email_mirror.py @@ -1332,7 +1332,7 @@ class TestMissedMessageEmailMessages(ZulipTestCase): incoming_valid_message["Reply-to"] = user_profile.delivery_email # there is no longer a usage limit. Ensure we can send multiple times. - for i in range(0, 5): + for i in range(5): process_missed_message(mm_address, incoming_valid_message) @@ -1586,7 +1586,7 @@ class TestEmailMirrorTornadoView(ZulipTestCase): def test_using_mm_address_multiple_times(self) -> None: mm_address = self.send_private_message() # there is no longer a usage limit. Ensure we can send multiple times. - for i in range(0, 5): + for i in range(5): result = self.send_offline_message(mm_address, self.example_user("cordelia")) self.assert_json_success(result) diff --git a/zerver/tests/test_message_flags.py b/zerver/tests/test_message_flags.py index 9ae0f4112e..0124b051b4 100644 --- a/zerver/tests/test_message_flags.py +++ b/zerver/tests/test_message_flags.py @@ -662,7 +662,7 @@ class MarkAllAsReadEndpointTest(ZulipTestCase): othello = self.example_user("othello") self.subscribe(hamlet, "Denmark") - for i in range(0, 4): + for i in range(4): self.send_stream_message(othello, "Verona", "test") self.send_personal_message(othello, hamlet, "test") diff --git a/zerver/tests/test_message_notification_emails.py b/zerver/tests/test_message_notification_emails.py index 8a552e2363..c464d41e86 100644 --- a/zerver/tests/test_message_notification_emails.py +++ b/zerver/tests/test_message_notification_emails.py @@ -173,7 +173,7 @@ class TestMessageNotificationEmails(ZulipTestCase): def _extra_context_in_missed_stream_messages_mention( self, send_as_user: bool, show_message_content: bool = True ) -> None: - for i in range(0, 11): + for i in range(11): self.send_stream_message( self.example_user("othello"), "Denmark", @@ -387,7 +387,7 @@ class TestMessageNotificationEmails(ZulipTestCase): ) def _extra_context_in_missed_stream_messages_email_notify(self, send_as_user: bool) -> None: - for i in range(0, 11): + for i in range(11): self.send_stream_message(self.example_user("othello"), "Denmark", content=str(i)) self.send_stream_message(self.example_user("othello"), "Denmark", "11", topic_name="test2") msg_id = self.send_stream_message(self.example_user("othello"), "denmark", "12") @@ -410,7 +410,7 @@ class TestMessageNotificationEmails(ZulipTestCase): cordelia = self.example_user("cordelia") self.subscribe(cordelia, "Denmark") - for i in range(0, 3): + for i in range(3): self.send_stream_message(cordelia, "Denmark", str(i)) msg_id = self.send_stream_message( self.example_user("othello"), "Denmark", "@**King Hamlet**" @@ -432,7 +432,7 @@ class TestMessageNotificationEmails(ZulipTestCase): topic_name = "threading and so forth" othello_user = self.example_user("othello") msg_id = -1 - for i in range(0, 3): + for i in range(3): msg_id = self.send_stream_message( othello_user, "Denmark", diff --git a/zerver/tests/test_retention.py b/zerver/tests/test_retention.py index 1cd6e21b3a..54f68c4226 100644 --- a/zerver/tests/test_retention.py +++ b/zerver/tests/test_retention.py @@ -603,7 +603,7 @@ class MoveMessageToArchiveBase(RetentionTestingBase): class MoveMessageToArchiveGeneral(MoveMessageToArchiveBase): def test_personal_messages_archiving(self) -> None: - msg_ids = [self.send_personal_message(self.sender, self.recipient) for i in range(0, 3)] + msg_ids = [self.send_personal_message(self.sender, self.recipient) for i in range(3)] usermsg_ids = self._get_usermessage_ids(msg_ids) self._assert_archive_empty() @@ -615,7 +615,7 @@ class MoveMessageToArchiveGeneral(MoveMessageToArchiveBase): def test_move_messages_to_archive_with_realm_argument(self) -> None: realm = get_realm("zulip") - msg_ids = [self.send_personal_message(self.sender, self.recipient) for i in range(0, 3)] + msg_ids = [self.send_personal_message(self.sender, self.recipient) for i in range(3)] usermsg_ids = self._get_usermessage_ids(msg_ids) self._assert_archive_empty() @@ -627,7 +627,7 @@ class MoveMessageToArchiveGeneral(MoveMessageToArchiveBase): self.assertEqual(archive_transaction.realm, realm) def test_stream_messages_archiving(self) -> None: - msg_ids = [self.send_stream_message(self.sender, "Verona") for i in range(0, 3)] + msg_ids = [self.send_stream_message(self.sender, "Verona") for i in range(3)] usermsg_ids = self._get_usermessage_ids(msg_ids) self._assert_archive_empty() @@ -638,7 +638,7 @@ class MoveMessageToArchiveGeneral(MoveMessageToArchiveBase): self._verify_restored_data(msg_ids, usermsg_ids) def test_archiving_messages_second_time(self) -> None: - msg_ids = [self.send_stream_message(self.sender, "Verona") for i in range(0, 3)] + msg_ids = [self.send_stream_message(self.sender, "Verona") for i in range(3)] usermsg_ids = self._get_usermessage_ids(msg_ids) self._assert_archive_empty() @@ -659,8 +659,8 @@ class MoveMessageToArchiveGeneral(MoveMessageToArchiveBase): cordelia = self.lear_user("cordelia") king = self.lear_user("king") - zulip_msg_ids = [self.send_personal_message(iago, othello) for i in range(0, 3)] - lear_msg_ids = [self.send_personal_message(cordelia, king) for i in range(0, 3)] + zulip_msg_ids = [self.send_personal_message(iago, othello) for i in range(3)] + lear_msg_ids = [self.send_personal_message(cordelia, king) for i in range(3)] msg_ids = zulip_msg_ids + lear_msg_ids usermsg_ids = self._get_usermessage_ids(msg_ids) @@ -1088,13 +1088,13 @@ class TestRestoreStreamMessages(ArchiveMessagesTestingBase): stream = get_stream(stream_name, realm) message_ids_to_archive_manually = [ - self.send_stream_message(cordelia, stream_name, str(i)) for i in range(0, 2) + self.send_stream_message(cordelia, stream_name, str(i)) for i in range(2) ] usermessage_ids_to_archive_manually = self._get_usermessage_ids( message_ids_to_archive_manually ) message_ids_to_archive_by_policy = [ - self.send_stream_message(hamlet, stream_name, str(i)) for i in range(0, 2) + self.send_stream_message(hamlet, stream_name, str(i)) for i in range(2) ] usermessage_ids_to_archive_by_policy = self._get_usermessage_ids( message_ids_to_archive_by_policy @@ -1132,7 +1132,7 @@ class TestDoDeleteMessages(ZulipTestCase): def test_do_delete_messages_multiple(self) -> None: realm = get_realm("zulip") cordelia = self.example_user("cordelia") - message_ids = [self.send_stream_message(cordelia, "Verona", str(i)) for i in range(0, 10)] + message_ids = [self.send_stream_message(cordelia, "Verona", str(i)) for i in range(10)] messages = Message.objects.filter(id__in=message_ids) with self.assert_database_query_count(20): diff --git a/zerver/tests/test_upload.py b/zerver/tests/test_upload.py index 5375511666..86e35df3bb 100644 --- a/zerver/tests/test_upload.py +++ b/zerver/tests/test_upload.py @@ -770,7 +770,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase): def test_multiple_message_attachment_file_download(self) -> None: hamlet = self.example_user("hamlet") - for i in range(0, 5): + for i in range(5): stream_name = f"test-subscribe {i}" self.make_stream( stream_name,