ruff: Fix PIE808 Unnecessary `start` argument in `range`.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-09-01 14:05:08 -07:00 committed by Anders Kaseorg
parent 9cff7e14c4
commit 81bd63cb46
12 changed files with 25 additions and 25 deletions

View File

@ -507,10 +507,10 @@ def rewrite_client_arrays(value_arrays: Dict[str, List[int]]) -> Dict[str, List[
for label, array in value_arrays.items(): for label, array in value_arrays.items():
mapped_label = client_label_map(label) mapped_label = client_label_map(label)
if mapped_label in mapped_arrays: 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] mapped_arrays[mapped_label][i] += value_arrays[label][i]
else: 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 return mapped_arrays

View File

@ -9,7 +9,7 @@ class UnixStreamHTTPConnection(HTTPConnection):
def connect(self) -> None: def connect(self) -> None:
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
connected = False connected = False
for i in range(0, 2): for i in range(2):
try: try:
self.sock.connect(self.host) self.sock.connect(self.host)
connected = True connected = True

View File

@ -63,7 +63,7 @@ def parser() -> argparse.ArgumentParser:
"-H", "-H",
help="Estimated minimum number of hours; includes previous log file, if estimated less than this", help="Estimated minimum number of hours; includes previous log file, if estimated less than this",
type=int, type=int,
choices=range(0, 24), choices=range(24),
default=3, default=3,
) )
log_selection.add_argument( log_selection.add_argument(

View File

@ -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: def resolve_conflicts(conflicts: List[str], files_list: List[str]) -> None:
print("Conflicting migrations:") print("Conflicting migrations:")
for i in range(0, len(conflicts)): for i in range(len(conflicts)):
print(str(i + 1) + ". " + conflicts[i]) print(str(i + 1) + ". " + conflicts[i])
order_input = input("Enter the order in which these migrations should be arranged: ") order_input = input("Enter the order in which these migrations should be arranged: ")

View File

@ -98,7 +98,7 @@ def resize_animated(im: Image.Image, size: int = DEFAULT_EMOJI_SIZE) -> bytes:
disposals = [] disposals = []
# If 'loop' info is not set then loop for infinite number of times. # If 'loop' info is not set then loop for infinite number of times.
loop = im.info.get("loop", 0) 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) im.seek(frame_num)
new_frame = im.copy() new_frame = im.copy()
new_frame.paste(im, (0, 0), im.convert("RGBA")) new_frame.paste(im, (0, 0), im.convert("RGBA"))

View File

@ -889,7 +889,7 @@ class TestValidateApiKey(ZulipTestCase):
self.assertFalse(has_api_key_format("33LONGXXXXXXXXXXXXXXXXXXXXXXXXXXX")) self.assertFalse(has_api_key_format("33LONGXXXXXXXXXXXXXXXXXXXXXXXXXXX"))
self.assertTrue(has_api_key_format("VIzRVw2CspUOnEm9Yu5vQiQtJNkvETkp")) 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())) self.assertTrue(has_api_key_format(generate_api_key()))
def test_validate_api_key_if_profile_does_not_exist(self) -> None: def test_validate_api_key_if_profile_does_not_exist(self) -> None:

View File

@ -567,7 +567,7 @@ class DraftFetchTest(ZulipTestCase):
first_draft_id = Draft.objects.filter(user_profile=hamlet).order_by("id")[0].id first_draft_id = Draft.objects.filter(user_profile=hamlet).order_by("id")[0].id
expected_draft_contents: List[Dict[str, object]] = [ 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) self.assertEqual(data["drafts"], expected_draft_contents)

View File

@ -1332,7 +1332,7 @@ class TestMissedMessageEmailMessages(ZulipTestCase):
incoming_valid_message["Reply-to"] = user_profile.delivery_email incoming_valid_message["Reply-to"] = user_profile.delivery_email
# there is no longer a usage limit. Ensure we can send multiple times. # 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) process_missed_message(mm_address, incoming_valid_message)
@ -1586,7 +1586,7 @@ class TestEmailMirrorTornadoView(ZulipTestCase):
def test_using_mm_address_multiple_times(self) -> None: def test_using_mm_address_multiple_times(self) -> None:
mm_address = self.send_private_message() mm_address = self.send_private_message()
# there is no longer a usage limit. Ensure we can send multiple times. # 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")) result = self.send_offline_message(mm_address, self.example_user("cordelia"))
self.assert_json_success(result) self.assert_json_success(result)

View File

@ -662,7 +662,7 @@ class MarkAllAsReadEndpointTest(ZulipTestCase):
othello = self.example_user("othello") othello = self.example_user("othello")
self.subscribe(hamlet, "Denmark") self.subscribe(hamlet, "Denmark")
for i in range(0, 4): for i in range(4):
self.send_stream_message(othello, "Verona", "test") self.send_stream_message(othello, "Verona", "test")
self.send_personal_message(othello, hamlet, "test") self.send_personal_message(othello, hamlet, "test")

View File

@ -173,7 +173,7 @@ class TestMessageNotificationEmails(ZulipTestCase):
def _extra_context_in_missed_stream_messages_mention( def _extra_context_in_missed_stream_messages_mention(
self, send_as_user: bool, show_message_content: bool = True self, send_as_user: bool, show_message_content: bool = True
) -> None: ) -> None:
for i in range(0, 11): for i in range(11):
self.send_stream_message( self.send_stream_message(
self.example_user("othello"), self.example_user("othello"),
"Denmark", "Denmark",
@ -387,7 +387,7 @@ class TestMessageNotificationEmails(ZulipTestCase):
) )
def _extra_context_in_missed_stream_messages_email_notify(self, send_as_user: bool) -> None: 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", content=str(i))
self.send_stream_message(self.example_user("othello"), "Denmark", "11", topic_name="test2") 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") msg_id = self.send_stream_message(self.example_user("othello"), "denmark", "12")
@ -410,7 +410,7 @@ class TestMessageNotificationEmails(ZulipTestCase):
cordelia = self.example_user("cordelia") cordelia = self.example_user("cordelia")
self.subscribe(cordelia, "Denmark") self.subscribe(cordelia, "Denmark")
for i in range(0, 3): for i in range(3):
self.send_stream_message(cordelia, "Denmark", str(i)) self.send_stream_message(cordelia, "Denmark", str(i))
msg_id = self.send_stream_message( msg_id = self.send_stream_message(
self.example_user("othello"), "Denmark", "@**King Hamlet**" self.example_user("othello"), "Denmark", "@**King Hamlet**"
@ -432,7 +432,7 @@ class TestMessageNotificationEmails(ZulipTestCase):
topic_name = "threading and so forth" topic_name = "threading and so forth"
othello_user = self.example_user("othello") othello_user = self.example_user("othello")
msg_id = -1 msg_id = -1
for i in range(0, 3): for i in range(3):
msg_id = self.send_stream_message( msg_id = self.send_stream_message(
othello_user, othello_user,
"Denmark", "Denmark",

View File

@ -603,7 +603,7 @@ class MoveMessageToArchiveBase(RetentionTestingBase):
class MoveMessageToArchiveGeneral(MoveMessageToArchiveBase): class MoveMessageToArchiveGeneral(MoveMessageToArchiveBase):
def test_personal_messages_archiving(self) -> None: 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) usermsg_ids = self._get_usermessage_ids(msg_ids)
self._assert_archive_empty() self._assert_archive_empty()
@ -615,7 +615,7 @@ class MoveMessageToArchiveGeneral(MoveMessageToArchiveBase):
def test_move_messages_to_archive_with_realm_argument(self) -> None: def test_move_messages_to_archive_with_realm_argument(self) -> None:
realm = get_realm("zulip") 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) usermsg_ids = self._get_usermessage_ids(msg_ids)
self._assert_archive_empty() self._assert_archive_empty()
@ -627,7 +627,7 @@ class MoveMessageToArchiveGeneral(MoveMessageToArchiveBase):
self.assertEqual(archive_transaction.realm, realm) self.assertEqual(archive_transaction.realm, realm)
def test_stream_messages_archiving(self) -> None: 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) usermsg_ids = self._get_usermessage_ids(msg_ids)
self._assert_archive_empty() self._assert_archive_empty()
@ -638,7 +638,7 @@ class MoveMessageToArchiveGeneral(MoveMessageToArchiveBase):
self._verify_restored_data(msg_ids, usermsg_ids) self._verify_restored_data(msg_ids, usermsg_ids)
def test_archiving_messages_second_time(self) -> None: 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) usermsg_ids = self._get_usermessage_ids(msg_ids)
self._assert_archive_empty() self._assert_archive_empty()
@ -659,8 +659,8 @@ class MoveMessageToArchiveGeneral(MoveMessageToArchiveBase):
cordelia = self.lear_user("cordelia") cordelia = self.lear_user("cordelia")
king = self.lear_user("king") king = self.lear_user("king")
zulip_msg_ids = [self.send_personal_message(iago, othello) 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(0, 3)] lear_msg_ids = [self.send_personal_message(cordelia, king) for i in range(3)]
msg_ids = zulip_msg_ids + lear_msg_ids msg_ids = zulip_msg_ids + lear_msg_ids
usermsg_ids = self._get_usermessage_ids(msg_ids) usermsg_ids = self._get_usermessage_ids(msg_ids)
@ -1088,13 +1088,13 @@ class TestRestoreStreamMessages(ArchiveMessagesTestingBase):
stream = get_stream(stream_name, realm) stream = get_stream(stream_name, realm)
message_ids_to_archive_manually = [ 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( usermessage_ids_to_archive_manually = self._get_usermessage_ids(
message_ids_to_archive_manually message_ids_to_archive_manually
) )
message_ids_to_archive_by_policy = [ 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( usermessage_ids_to_archive_by_policy = self._get_usermessage_ids(
message_ids_to_archive_by_policy message_ids_to_archive_by_policy
@ -1132,7 +1132,7 @@ class TestDoDeleteMessages(ZulipTestCase):
def test_do_delete_messages_multiple(self) -> None: def test_do_delete_messages_multiple(self) -> None:
realm = get_realm("zulip") realm = get_realm("zulip")
cordelia = self.example_user("cordelia") 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) messages = Message.objects.filter(id__in=message_ids)
with self.assert_database_query_count(20): with self.assert_database_query_count(20):

View File

@ -770,7 +770,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
def test_multiple_message_attachment_file_download(self) -> None: def test_multiple_message_attachment_file_download(self) -> None:
hamlet = self.example_user("hamlet") hamlet = self.example_user("hamlet")
for i in range(0, 5): for i in range(5):
stream_name = f"test-subscribe {i}" stream_name = f"test-subscribe {i}"
self.make_stream( self.make_stream(
stream_name, stream_name,