From a481fde682c28d4aad32ffeacfb3f971b244d4c0 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Mon, 9 Nov 2026 13:27:59 -0500 Subject: [PATCH] PYTHON-6236 Enable ruff rule B905 for clearer zip() calls --- .evergreen/scripts/generate_config_utils.py | 1 + pymongo/auth_shared.py | 2 +- pymongo/message.py | 4 +++- pymongo/pool_options.py | 2 +- pyproject.toml | 1 - test/asynchronous/test_bulk.py | 4 ++-- test/asynchronous/test_change_stream.py | 2 +- test/asynchronous/test_client.py | 2 +- test/asynchronous/test_connection_monitoring.py | 2 +- test/asynchronous/test_cursor.py | 16 ++++++++-------- test/asynchronous/test_custom_types.py | 8 ++++++-- test/asynchronous/test_encryption.py | 3 ++- test/asynchronous/test_heartbeat_monitoring.py | 2 +- test/asynchronous/test_monitoring.py | 8 ++++---- test/asynchronous/test_read_preferences.py | 2 +- test/asynchronous/unified_format.py | 6 ++++-- test/test_bulk.py | 4 ++-- test/test_change_stream.py | 2 +- test/test_client.py | 2 +- test/test_connection_monitoring.py | 2 +- test/test_cursor.py | 16 ++++++++-------- test/test_custom_types.py | 8 ++++++-- test/test_encryption.py | 3 ++- test/test_heartbeat_monitoring.py | 2 +- test/test_monitoring.py | 8 ++++---- test/test_raw_bson_shared.py | 2 +- test/test_read_preferences.py | 2 +- test/test_uri_spec.py | 2 +- test/unified_format.py | 6 ++++-- test/unified_format_shared.py | 2 +- 30 files changed, 71 insertions(+), 55 deletions(-) diff --git a/.evergreen/scripts/generate_config_utils.py b/.evergreen/scripts/generate_config_utils.py index 0ba291ab5b..e131bcffe0 100644 --- a/.evergreen/scripts/generate_config_utils.py +++ b/.evergreen/scripts/generate_config_utils.py @@ -85,6 +85,7 @@ class Host: "rhel82-arm64-small", "amazon2023-arm64-latest-large-m8g", ], + strict=True, ): HOSTS[name] = Host(name, run_on, name, dict()) diff --git a/pymongo/auth_shared.py b/pymongo/auth_shared.py index 3bd538d9ff..a65d1f0d57 100644 --- a/pymongo/auth_shared.py +++ b/pymongo/auth_shared.py @@ -233,7 +233,7 @@ def _build_credentials_tuple( def _xor(fir: bytes, sec: bytes) -> bytes: """XOR two byte strings together.""" - return b"".join([bytes([x ^ y]) for x, y in zip(fir, sec)]) + return b"".join([bytes([x ^ y]) for x, y in zip(fir, sec, strict=True)]) def _parse_scram_response(response: bytes) -> dict[bytes, bytes]: diff --git a/pymongo/message.py b/pymongo/message.py index f6b22b77cb..fe499df7e4 100644 --- a/pymongo/message.py +++ b/pymongo/message.py @@ -831,7 +831,9 @@ def _check_doc_size_limits( total_ops_length = 0 total_ns_length = 0 - for idx, ((real_op_type, op_doc), namespace) in enumerate(zip(operations, namespaces)): + for idx, ((real_op_type, op_doc), namespace) in enumerate( + zip(operations, namespaces, strict=True) + ): op_type = real_op_type # Check insert/replace document size if unacknowledged. if real_op_type == "insert": diff --git a/pymongo/pool_options.py b/pymongo/pool_options.py index 87c127d721..855c7cd2c9 100644 --- a/pymongo/pool_options.py +++ b/pymongo/pool_options.py @@ -333,7 +333,7 @@ def _truncate_metadata(metadata: MutableMapping[str, Any]) -> None: # driver) are dropped first since they cost nothing. name_str = driver.get("name", "") version_str = driver.get("version", "") - raw_pairs = list(zip(name_str.split("|"), version_str.split("|"))) + raw_pairs = list(zip(name_str.split("|"), version_str.split("|"), strict=True)) pairs = [(name, version) for name, version in raw_pairs if name or version] new_name = "|".join(name for name, _ in pairs) new_version = "|".join(version for _, version in pairs) diff --git a/pyproject.toml b/pyproject.toml index e8c68fa546..2b4890e537 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -244,7 +244,6 @@ ignore = [ "ASYNC109", # Async function with a `timeout` parameter (CSOT timeouts are not `asyncio.timeout`) "UP042", # `str, Enum` should be `StrEnum` (changes `__str__` semantics) "UP017", # `timezone.utc` preferred over `datetime.UTC` (keep existing style) - "B905", # `zip()` without an explicit `strict=` parameter ] unfixable = [ "RUF100", # Unused noqa diff --git a/test/asynchronous/test_bulk.py b/test/asynchronous/test_bulk.py index 4850e56560..d39e6cb3a5 100644 --- a/test/asynchronous/test_bulk.py +++ b/test/asynchronous/test_bulk.py @@ -63,7 +63,7 @@ def assertEqualResponse(self, expected, actual): % (len(expected_upserts), len(actual_upserts)), ) - for e, a in zip(expected_upserts, actual_upserts): + for e, a in zip(expected_upserts, actual_upserts, strict=True): self.assertEqualUpsert(e, a) elif key == "writeErrors": @@ -76,7 +76,7 @@ def assertEqualResponse(self, expected, actual): % (len(expected_errors), len(actual_errors)), ) - for e, a in zip(expected_errors, actual_errors): + for e, a in zip(expected_errors, actual_errors, strict=True): self.assertEqualWriteError(e, a) else: diff --git a/test/asynchronous/test_change_stream.py b/test/asynchronous/test_change_stream.py index 6b1b7b4cb9..cba8d51a72 100644 --- a/test/asynchronous/test_change_stream.py +++ b/test/asynchronous/test_change_stream.py @@ -1090,7 +1090,7 @@ def assert_list_contents_are_subset(self, superlist, sublist): element in superlist. """ self.assertEqual(len(superlist), len(sublist)) - for sup, sub in zip(superlist, sublist): + for sup, sub in zip(superlist, sublist, strict=True): if isinstance(sub, dict): self.assert_dict_is_subset(sup, sub) continue diff --git a/test/asynchronous/test_client.py b/test/asynchronous/test_client.py index 2b61dda182..f78a26679a 100644 --- a/test/asynchronous/test_client.py +++ b/test/asynchronous/test_client.py @@ -1318,7 +1318,7 @@ async def test_list_databases(self): self.assertGreater(len(helper_docs), 0) self.assertEqual(len(helper_docs), len(cmd_docs)) # PYTHON-3529 Some fields may change between calls, just compare names. - for helper_doc, cmd_doc in zip(helper_docs, cmd_docs): + for helper_doc, cmd_doc in zip(helper_docs, cmd_docs, strict=True): self.assertIs(type(helper_doc), dict) self.assertEqual(helper_doc.keys(), cmd_doc.keys()) client = await self.async_rs_or_single_client(document_class=SON) diff --git a/test/asynchronous/test_connection_monitoring.py b/test/asynchronous/test_connection_monitoring.py index c9399be48e..48fc08de28 100644 --- a/test/asynchronous/test_connection_monitoring.py +++ b/test/asynchronous/test_connection_monitoring.py @@ -199,7 +199,7 @@ def actual_events(self, ignore): def check_events(self, events, ignore): """Check the events of a test.""" actual_events = self.actual_events(ignore) - for actual, expected in zip(actual_events, events): + for actual, expected in zip(actual_events, events, strict=False): self.logs.append(f"Checking event actual: {actual!r} vs expected: {expected!r}") self.check_event(actual, expected) diff --git a/test/asynchronous/test_cursor.py b/test/asynchronous/test_cursor.py index 364f4eb946..2bd45c00b8 100644 --- a/test/asynchronous/test_cursor.py +++ b/test/asynchronous/test_cursor.py @@ -1037,18 +1037,18 @@ def test_getitem_slice_index(self): self.assertRaises(IndexError, lambda: self.db.coll.find()[-1:]) self.assertRaises(IndexError, lambda: self.db.coll.find()[1:2:2]) - for a, b in zip(count(0), self.db.coll.find()): # type: ignore[call-overload] + for a, b in zip(count(0), self.db.coll.find(), strict=False): # type: ignore[call-overload] self.assertEqual(a, b["i"]) self.assertEqual(100, len(list(self.db.coll.find()[0:]))) # type: ignore[call-overload] - for a, b in zip(count(0), self.db.coll.find()[0:]): # type: ignore[call-overload] + for a, b in zip(count(0), self.db.coll.find()[0:], strict=False): # type: ignore[call-overload] self.assertEqual(a, b["i"]) self.assertEqual(80, len(list(self.db.coll.find()[20:]))) # type: ignore[call-overload] - for a, b in zip(count(20), self.db.coll.find()[20:]): # type: ignore[call-overload] + for a, b in zip(count(20), self.db.coll.find()[20:], strict=False): # type: ignore[call-overload] self.assertEqual(a, b["i"]) - for a, b in zip(count(99), self.db.coll.find()[99:]): # type: ignore[call-overload] + for a, b in zip(count(99), self.db.coll.find()[99:], strict=False): # type: ignore[call-overload] self.assertEqual(a, b["i"]) for _i in self.db.coll.find()[1000:]: @@ -1056,19 +1056,19 @@ def test_getitem_slice_index(self): self.assertEqual(5, len(list(self.db.coll.find()[20:25]))) # type: ignore[call-overload] self.assertEqual(5, len(list(self.db.coll.find()[20:25]))) # type: ignore[call-overload] - for a, b in zip(count(20), self.db.coll.find()[20:25]): # type: ignore[call-overload] + for a, b in zip(count(20), self.db.coll.find()[20:25], strict=False): # type: ignore[call-overload] self.assertEqual(a, b["i"]) self.assertEqual(80, len(list(self.db.coll.find()[40:45][20:]))) # type: ignore[call-overload] - for a, b in zip(count(20), self.db.coll.find()[40:45][20:]): # type: ignore[call-overload] + for a, b in zip(count(20), self.db.coll.find()[40:45][20:], strict=False): # type: ignore[call-overload] self.assertEqual(a, b["i"]) self.assertEqual(80, len(list(self.db.coll.find()[40:45].limit(0).skip(20)))) # type: ignore[call-overload] - for a, b in zip(count(20), self.db.coll.find()[40:45].limit(0).skip(20)): # type: ignore[call-overload] + for a, b in zip(count(20), self.db.coll.find()[40:45].limit(0).skip(20), strict=False): # type: ignore[call-overload] self.assertEqual(a, b["i"]) self.assertEqual(80, len(list(self.db.coll.find().limit(10).skip(40)[20:]))) # type: ignore[call-overload] - for a, b in zip(count(20), self.db.coll.find().limit(10).skip(40)[20:]): # type: ignore[call-overload] + for a, b in zip(count(20), self.db.coll.find().limit(10).skip(40)[20:], strict=False): # type: ignore[call-overload] self.assertEqual(a, b["i"]) self.assertEqual(1, len(list(self.db.coll.find()[:1]))) # type: ignore[call-overload] diff --git a/test/asynchronous/test_custom_types.py b/test/asynchronous/test_custom_types.py index 34c4d05650..437b9ed73c 100644 --- a/test/asynchronous/test_custom_types.py +++ b/test/asynchronous/test_custom_types.py @@ -181,7 +181,9 @@ def _generate_multidocument_bson_stream(self): @no_type_check def test_decode_iter(self): expected, bson_data = self._generate_multidocument_bson_stream() - for expected_doc, decoded_doc in zip(expected, decode_iter(bson_data, self.codecopts)): + for expected_doc, decoded_doc in zip( + expected, decode_iter(bson_data, self.codecopts), strict=True + ): self.assertEqual(expected_doc, decoded_doc) @no_type_check @@ -191,7 +193,9 @@ def test_decode_file_iter(self): fileobj.write(bson_data) fileobj.seek(0) - for expected_doc, decoded_doc in zip(expected, decode_file_iter(fileobj, self.codecopts)): + for expected_doc, decoded_doc in zip( + expected, decode_file_iter(fileobj, self.codecopts), strict=True + ): self.assertEqual(expected_doc, decoded_doc) fileobj.close() diff --git a/test/asynchronous/test_encryption.py b/test/asynchronous/test_encryption.py index b52f1a1d80..aace917091 100644 --- a/test/asynchronous/test_encryption.py +++ b/test/asynchronous/test_encryption.py @@ -2908,7 +2908,7 @@ async def run_expression_find( await self.encrypted_client.db.explicit_encryption.find(find_payload).to_list(), key=lambda x: x["_id"], ) - for elem, expected in zip(sorted_find, expected_elems): + for elem, expected in zip(sorted_find, expected_elems, strict=True): self.assertEqual(elem[f"encrypted{name}"], expected) async def run_test_cases(self, name, range_opts, cast_func): @@ -3313,6 +3313,7 @@ async def test_mixed_null_keyids(self): for val, key in zip( ["123-45-6789", "11/22/1963", "My secret", "New Mexico, 87104"], [field["keyId"] for field in ef["fields"]], + strict=True, ) ] await coll.insert_one( diff --git a/test/asynchronous/test_heartbeat_monitoring.py b/test/asynchronous/test_heartbeat_monitoring.py index ff8c7c9eb9..9e13532f2d 100644 --- a/test/asynchronous/test_heartbeat_monitoring.py +++ b/test/asynchronous/test_heartbeat_monitoring.py @@ -61,7 +61,7 @@ async def _check_with_socket(self, *args, **kwargs): ) # zip gives us len(expected_results) pairs. - for expected, actual in zip(expected_results, listener.events): + for expected, actual in zip(expected_results, listener.events, strict=False): self.assertEqual(expected, actual.__class__.__name__) self.assertEqual(actual.connection_id, responses[0]) if expected != "ServerHeartbeatStartedEvent": diff --git a/test/asynchronous/test_monitoring.py b/test/asynchronous/test_monitoring.py index e317f65ac3..fa2cb0189b 100644 --- a/test/asynchronous/test_monitoring.py +++ b/test/asynchronous/test_monitoring.py @@ -835,7 +835,7 @@ async def test_insert_many(self): count = 0 operation_id = started[0].operation_id self.assertIsInstance(operation_id, int) - for start, succeed in zip(started, succeeded): + for start, succeed in zip(started, succeeded, strict=True): self.assertIsInstance(start, monitoring.CommandStartedEvent) cmd = sanitize_cmd(start.command) self.assertEqual(["insert", "ordered", "documents"], list(cmd.keys())) @@ -875,7 +875,7 @@ async def test_insert_many_unacknowledged(self): documents = [] operation_id = started[0].operation_id self.assertIsInstance(operation_id, int) - for start, succeed in zip(started, succeeded): + for start, succeed in zip(started, succeeded, strict=True): self.assertIsInstance(start, monitoring.CommandStartedEvent) cmd = sanitize_cmd(start.command) cmd.pop("writeConcern", None) @@ -918,7 +918,7 @@ async def test_bulk_write(self): succeeded = self.listener.succeeded_events self.assertEqual(0, len(self.listener.failed_events)) operation_id = started[0].operation_id - pairs = list(zip(started, succeeded)) + pairs = list(zip(started, succeeded, strict=True)) self.assertEqual(3, len(pairs)) for start, succeed in pairs: self.assertIsInstance(start, monitoring.CommandStartedEvent) @@ -1034,7 +1034,7 @@ async def test_write_errors(self): succeeded = self.listener.succeeded_events self.assertEqual(0, len(self.listener.failed_events)) operation_id = started[0].operation_id - pairs = list(zip(started, succeeded)) + pairs = list(zip(started, succeeded, strict=True)) errors = [] for start, succeed in pairs: self.assertIsInstance(start, monitoring.CommandStartedEvent) diff --git a/test/asynchronous/test_read_preferences.py b/test/asynchronous/test_read_preferences.py index 3728c3163c..a193b9dedd 100644 --- a/test/asynchronous/test_read_preferences.py +++ b/test/asynchronous/test_read_preferences.py @@ -255,7 +255,7 @@ async def test_zero_latency(self): # Generate unique ping times. while len(ping_times) < len(self.client.nodes): ping_times.add(random.random()) - for ping_time, host in zip(ping_times, self.client.nodes): + for ping_time, host in zip(ping_times, self.client.nodes, strict=True): ServerDescription._host_to_round_trip_time[host] = ping_time try: client = await connected( diff --git a/test/asynchronous/unified_format.py b/test/asynchronous/unified_format.py index 38e112fa1a..94ce837726 100644 --- a/test/asynchronous/unified_format.py +++ b/test/asynchronous/unified_format.py @@ -748,7 +748,9 @@ def process_error(self, exception, spec): ) actual_write_concern_errors = exception.details.get("writeConcernErrors", []) self.assertEqual(len(write_concern_errors), len(actual_write_concern_errors)) - for expected_wce, actual_wce in zip(write_concern_errors, actual_write_concern_errors): + for expected_wce, actual_wce in zip( + write_concern_errors, actual_write_concern_errors, strict=True + ): # Use the spec's WriteConcernError field names. formatted_actual_wce = { "code": actual_wce.get("code", ""), @@ -1466,7 +1468,7 @@ def format_logs(log_list): len(actual_logs), f"expected {client['messages']} but got {actual_logs}", ) - for expected_msg, actual_msg in zip(client["messages"], actual_logs): + for expected_msg, actual_msg in zip(client["messages"], actual_logs, strict=True): expected_data, actual_data = expected_msg.pop("data"), actual_msg.pop("data") if "failureIsRedacted" in expected_msg: diff --git a/test/test_bulk.py b/test/test_bulk.py index de8561cb33..d1ec4c7c83 100644 --- a/test/test_bulk.py +++ b/test/test_bulk.py @@ -63,7 +63,7 @@ def assertEqualResponse(self, expected, actual): % (len(expected_upserts), len(actual_upserts)), ) - for e, a in zip(expected_upserts, actual_upserts): + for e, a in zip(expected_upserts, actual_upserts, strict=True): self.assertEqualUpsert(e, a) elif key == "writeErrors": @@ -76,7 +76,7 @@ def assertEqualResponse(self, expected, actual): % (len(expected_errors), len(actual_errors)), ) - for e, a in zip(expected_errors, actual_errors): + for e, a in zip(expected_errors, actual_errors, strict=True): self.assertEqualWriteError(e, a) else: diff --git a/test/test_change_stream.py b/test/test_change_stream.py index 5fb0f6046d..004e997df1 100644 --- a/test/test_change_stream.py +++ b/test/test_change_stream.py @@ -1070,7 +1070,7 @@ def assert_list_contents_are_subset(self, superlist, sublist): element in superlist. """ self.assertEqual(len(superlist), len(sublist)) - for sup, sub in zip(superlist, sublist): + for sup, sub in zip(superlist, sublist, strict=True): if isinstance(sub, dict): self.assert_dict_is_subset(sup, sub) continue diff --git a/test/test_client.py b/test/test_client.py index dff1bea01f..5b08e51dc8 100644 --- a/test/test_client.py +++ b/test/test_client.py @@ -1287,7 +1287,7 @@ def test_list_databases(self): self.assertGreater(len(helper_docs), 0) self.assertEqual(len(helper_docs), len(cmd_docs)) # PYTHON-3529 Some fields may change between calls, just compare names. - for helper_doc, cmd_doc in zip(helper_docs, cmd_docs): + for helper_doc, cmd_doc in zip(helper_docs, cmd_docs, strict=True): self.assertIs(type(helper_doc), dict) self.assertEqual(helper_doc.keys(), cmd_doc.keys()) client = self.rs_or_single_client(document_class=SON) diff --git a/test/test_connection_monitoring.py b/test/test_connection_monitoring.py index 58f2fe80cb..042812ac69 100644 --- a/test/test_connection_monitoring.py +++ b/test/test_connection_monitoring.py @@ -199,7 +199,7 @@ def actual_events(self, ignore): def check_events(self, events, ignore): """Check the events of a test.""" actual_events = self.actual_events(ignore) - for actual, expected in zip(actual_events, events): + for actual, expected in zip(actual_events, events, strict=False): self.logs.append(f"Checking event actual: {actual!r} vs expected: {expected!r}") self.check_event(actual, expected) diff --git a/test/test_cursor.py b/test/test_cursor.py index 5ce277e8a9..c229129a30 100644 --- a/test/test_cursor.py +++ b/test/test_cursor.py @@ -1030,18 +1030,18 @@ def test_getitem_slice_index(self): self.assertRaises(IndexError, lambda: self.db.coll.find()[-1:]) self.assertRaises(IndexError, lambda: self.db.coll.find()[1:2:2]) - for a, b in zip(count(0), self.db.coll.find()): # type: ignore[call-overload] + for a, b in zip(count(0), self.db.coll.find(), strict=False): # type: ignore[call-overload] self.assertEqual(a, b["i"]) self.assertEqual(100, len(list(self.db.coll.find()[0:]))) # type: ignore[call-overload] - for a, b in zip(count(0), self.db.coll.find()[0:]): # type: ignore[call-overload] + for a, b in zip(count(0), self.db.coll.find()[0:], strict=False): # type: ignore[call-overload] self.assertEqual(a, b["i"]) self.assertEqual(80, len(list(self.db.coll.find()[20:]))) # type: ignore[call-overload] - for a, b in zip(count(20), self.db.coll.find()[20:]): # type: ignore[call-overload] + for a, b in zip(count(20), self.db.coll.find()[20:], strict=False): # type: ignore[call-overload] self.assertEqual(a, b["i"]) - for a, b in zip(count(99), self.db.coll.find()[99:]): # type: ignore[call-overload] + for a, b in zip(count(99), self.db.coll.find()[99:], strict=False): # type: ignore[call-overload] self.assertEqual(a, b["i"]) for _i in self.db.coll.find()[1000:]: @@ -1049,19 +1049,19 @@ def test_getitem_slice_index(self): self.assertEqual(5, len(list(self.db.coll.find()[20:25]))) # type: ignore[call-overload] self.assertEqual(5, len(list(self.db.coll.find()[20:25]))) # type: ignore[call-overload] - for a, b in zip(count(20), self.db.coll.find()[20:25]): # type: ignore[call-overload] + for a, b in zip(count(20), self.db.coll.find()[20:25], strict=False): # type: ignore[call-overload] self.assertEqual(a, b["i"]) self.assertEqual(80, len(list(self.db.coll.find()[40:45][20:]))) # type: ignore[call-overload] - for a, b in zip(count(20), self.db.coll.find()[40:45][20:]): # type: ignore[call-overload] + for a, b in zip(count(20), self.db.coll.find()[40:45][20:], strict=False): # type: ignore[call-overload] self.assertEqual(a, b["i"]) self.assertEqual(80, len(list(self.db.coll.find()[40:45].limit(0).skip(20)))) # type: ignore[call-overload] - for a, b in zip(count(20), self.db.coll.find()[40:45].limit(0).skip(20)): # type: ignore[call-overload] + for a, b in zip(count(20), self.db.coll.find()[40:45].limit(0).skip(20), strict=False): # type: ignore[call-overload] self.assertEqual(a, b["i"]) self.assertEqual(80, len(list(self.db.coll.find().limit(10).skip(40)[20:]))) # type: ignore[call-overload] - for a, b in zip(count(20), self.db.coll.find().limit(10).skip(40)[20:]): # type: ignore[call-overload] + for a, b in zip(count(20), self.db.coll.find().limit(10).skip(40)[20:], strict=False): # type: ignore[call-overload] self.assertEqual(a, b["i"]) self.assertEqual(1, len(list(self.db.coll.find()[:1]))) # type: ignore[call-overload] diff --git a/test/test_custom_types.py b/test/test_custom_types.py index 34f0fb31bc..1605ed6dd2 100644 --- a/test/test_custom_types.py +++ b/test/test_custom_types.py @@ -181,7 +181,9 @@ def _generate_multidocument_bson_stream(self): @no_type_check def test_decode_iter(self): expected, bson_data = self._generate_multidocument_bson_stream() - for expected_doc, decoded_doc in zip(expected, decode_iter(bson_data, self.codecopts)): + for expected_doc, decoded_doc in zip( + expected, decode_iter(bson_data, self.codecopts), strict=True + ): self.assertEqual(expected_doc, decoded_doc) @no_type_check @@ -191,7 +193,9 @@ def test_decode_file_iter(self): fileobj.write(bson_data) fileobj.seek(0) - for expected_doc, decoded_doc in zip(expected, decode_file_iter(fileobj, self.codecopts)): + for expected_doc, decoded_doc in zip( + expected, decode_file_iter(fileobj, self.codecopts), strict=True + ): self.assertEqual(expected_doc, decoded_doc) fileobj.close() diff --git a/test/test_encryption.py b/test/test_encryption.py index dcb4861141..0666b8b096 100644 --- a/test/test_encryption.py +++ b/test/test_encryption.py @@ -2892,7 +2892,7 @@ def run_expression_find( self.encrypted_client.db.explicit_encryption.find(find_payload).to_list(), key=lambda x: x["_id"], ) - for elem, expected in zip(sorted_find, expected_elems): + for elem, expected in zip(sorted_find, expected_elems, strict=True): self.assertEqual(elem[f"encrypted{name}"], expected) def run_test_cases(self, name, range_opts, cast_func): @@ -3295,6 +3295,7 @@ def test_mixed_null_keyids(self): for val, key in zip( ["123-45-6789", "11/22/1963", "My secret", "New Mexico, 87104"], [field["keyId"] for field in ef["fields"]], + strict=True, ) ] coll.insert_one( diff --git a/test/test_heartbeat_monitoring.py b/test/test_heartbeat_monitoring.py index 1c0d45f46d..74e01392df 100644 --- a/test/test_heartbeat_monitoring.py +++ b/test/test_heartbeat_monitoring.py @@ -59,7 +59,7 @@ def _check_with_socket(self, *args, **kwargs): wait_until(lambda: len(listener.events) >= expected_len, "publish all events") # zip gives us len(expected_results) pairs. - for expected, actual in zip(expected_results, listener.events): + for expected, actual in zip(expected_results, listener.events, strict=False): self.assertEqual(expected, actual.__class__.__name__) self.assertEqual(actual.connection_id, responses[0]) if expected != "ServerHeartbeatStartedEvent": diff --git a/test/test_monitoring.py b/test/test_monitoring.py index 4b28687f4b..1611666a8c 100644 --- a/test/test_monitoring.py +++ b/test/test_monitoring.py @@ -833,7 +833,7 @@ def test_insert_many(self): count = 0 operation_id = started[0].operation_id self.assertIsInstance(operation_id, int) - for start, succeed in zip(started, succeeded): + for start, succeed in zip(started, succeeded, strict=True): self.assertIsInstance(start, monitoring.CommandStartedEvent) cmd = sanitize_cmd(start.command) self.assertEqual(["insert", "ordered", "documents"], list(cmd.keys())) @@ -873,7 +873,7 @@ def test_insert_many_unacknowledged(self): documents = [] operation_id = started[0].operation_id self.assertIsInstance(operation_id, int) - for start, succeed in zip(started, succeeded): + for start, succeed in zip(started, succeeded, strict=True): self.assertIsInstance(start, monitoring.CommandStartedEvent) cmd = sanitize_cmd(start.command) cmd.pop("writeConcern", None) @@ -916,7 +916,7 @@ def test_bulk_write(self): succeeded = self.listener.succeeded_events self.assertEqual(0, len(self.listener.failed_events)) operation_id = started[0].operation_id - pairs = list(zip(started, succeeded)) + pairs = list(zip(started, succeeded, strict=True)) self.assertEqual(3, len(pairs)) for start, succeed in pairs: self.assertIsInstance(start, monitoring.CommandStartedEvent) @@ -1032,7 +1032,7 @@ def test_write_errors(self): succeeded = self.listener.succeeded_events self.assertEqual(0, len(self.listener.failed_events)) operation_id = started[0].operation_id - pairs = list(zip(started, succeeded)) + pairs = list(zip(started, succeeded, strict=True)) errors = [] for start, succeed in pairs: self.assertIsInstance(start, monitoring.CommandStartedEvent) diff --git a/test/test_raw_bson_shared.py b/test/test_raw_bson_shared.py index b7d54879aa..dee503449e 100644 --- a/test/test_raw_bson_shared.py +++ b/test/test_raw_bson_shared.py @@ -303,7 +303,7 @@ def test_preserve_key_ordering(self): ] rawdoc = RawBSONDocument(encode(SON(keyvaluepairs))) - for rkey, elt in zip(rawdoc, keyvaluepairs): + for rkey, elt in zip(rawdoc, keyvaluepairs, strict=True): self.assertEqual(rkey, elt[0]) def test_contains_code_with_scope(self): diff --git a/test/test_read_preferences.py b/test/test_read_preferences.py index 2cd2f1b061..a7afab90fc 100644 --- a/test/test_read_preferences.py +++ b/test/test_read_preferences.py @@ -241,7 +241,7 @@ def test_zero_latency(self): # Generate unique ping times. while len(ping_times) < len(self.client.nodes): ping_times.add(random.random()) - for ping_time, host in zip(ping_times, self.client.nodes): + for ping_time, host in zip(ping_times, self.client.nodes, strict=True): ServerDescription._host_to_round_trip_time[host] = ping_time try: client = connected(self.rs_client(readPreference="nearest", localThresholdMS=0)) diff --git a/test/test_uri_spec.py b/test/test_uri_spec.py index c44d57ab8c..7aa8803abb 100644 --- a/test/test_uri_spec.py +++ b/test/test_uri_spec.py @@ -135,7 +135,7 @@ def run_scenario(self): "Incorrect number of hosts parsed from URI", ) - for exp, actual in zip(test["hosts"], options["nodelist"]): + for exp, actual in zip(test["hosts"], options["nodelist"], strict=True): self.assertEqual( exp["host"], actual[0], diff --git a/test/unified_format.py b/test/unified_format.py index e74bed1ff4..f39e97365e 100644 --- a/test/unified_format.py +++ b/test/unified_format.py @@ -747,7 +747,9 @@ def process_error(self, exception, spec): ) actual_write_concern_errors = exception.details.get("writeConcernErrors", []) self.assertEqual(len(write_concern_errors), len(actual_write_concern_errors)) - for expected_wce, actual_wce in zip(write_concern_errors, actual_write_concern_errors): + for expected_wce, actual_wce in zip( + write_concern_errors, actual_write_concern_errors, strict=True + ): # Use the spec's WriteConcernError field names. formatted_actual_wce = { "code": actual_wce.get("code", ""), @@ -1453,7 +1455,7 @@ def format_logs(log_list): len(actual_logs), f"expected {client['messages']} but got {actual_logs}", ) - for expected_msg, actual_msg in zip(client["messages"], actual_logs): + for expected_msg, actual_msg in zip(client["messages"], actual_logs, strict=True): expected_data, actual_data = expected_msg.pop("data"), actual_msg.pop("data") if "failureIsRedacted" in expected_msg: diff --git a/test/unified_format_shared.py b/test/unified_format_shared.py index f63f8df797..b3b8e28a3a 100644 --- a/test/unified_format_shared.py +++ b/test/unified_format_shared.py @@ -538,7 +538,7 @@ def match_result(self, expectation, actual, in_recursive_call=False, test=True): if isinstance(expectation, abc.MutableSequence): self.test.assertIsInstance(actual, abc.MutableSequence) - for e, a in zip(expectation, actual): + for e, a in zip(expectation, actual, strict=False): if isinstance(e, abc.Mapping): res = self._match_document(e, a, is_root=not in_recursive_call, test=test) else: