Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bson/son.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def itervalues(self) -> Iterator[_Value]:
DeprecationWarning,
stacklevel=2,
)
for _, v in self.items():
for _, v in self.items(): # noqa: PERF102
yield v

def values(self) -> list[_Value]: # type: ignore[override]
Expand Down
2 changes: 1 addition & 1 deletion pymongo/asynchronous/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ async def validate_collection(
raise CollectionInvalid(f"{name} invalid: {info}")
# Sharded results
elif "raw" in result:
for _, res in result["raw"].items():
for res in result["raw"].values():
if "result" in res:
info = res["result"]
if info.find("exception") != -1 or info.find("corrupt") != -1:
Expand Down
2 changes: 1 addition & 1 deletion pymongo/mongo_client_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _after_fork_child(clients: Mapping[Any, Any]) -> None:
_release_locks()

# Perform cleanup in clients (i.e. get rid of topology)
for _, client in clients.items():
for client in clients.values():
client._after_fork()


Expand Down
2 changes: 1 addition & 1 deletion pymongo/synchronous/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ def validate_collection(
raise CollectionInvalid(f"{name} invalid: {info}")
# Sharded results
elif "raw" in result:
for _, res in result["raw"].items():
for res in result["raw"].values():
if "result" in res:
info = res["result"]
if info.find("exception") != -1 or info.find("corrupt") != -1:
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ ignore = [
"BLE", # Broad `Except` exception catches (intentional)
# These are all new defaults added in ruff 0.16.0. Individual tickets linked from PYTHON-5964 track enabling each one.
"FURB", # refurb
"PERF", # Perflint
"PYI", # flake8-pyi
"TC", # flake8-type-checking
"TRY", # tryceratops
Expand Down
4 changes: 2 additions & 2 deletions test/asynchronous/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ async def test_index_2dsphere(self):
await db.coll.drop_indexes()
self.assertEqual("geo_2dsphere", await db.coll.create_index([("geo", GEOSPHERE)]))

for dummy, info in (await db.coll.index_information()).items():
for info in (await db.coll.index_information()).values():
field, idx_type = info["key"][0]
if field == "geo" and idx_type == "2dsphere":
break
Expand All @@ -523,7 +523,7 @@ async def test_index_hashed(self):
await db.coll.drop_indexes()
self.assertEqual("a_hashed", await db.coll.create_index([("a", HASHED)]))

for dummy, info in (await db.coll.index_information()).items():
for info in (await db.coll.index_information()).values():
field, idx_type = info["key"][0]
if field == "a" and idx_type == "hashed":
break
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ async def test_id_ordering(self):
)
cursor = db.coll.find()
async for x in cursor:
for k, _v in x.items():
for k in x.keys():
self.assertEqual(k, "_id")
break

Expand Down
4 changes: 2 additions & 2 deletions test/asynchronous/test_discovery_and_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ async def test_rtt_connection_is_enabled_stream(self):
await client.admin.command("ping")

def predicate():
for _, server in client._topology._servers.items():
for server in client._topology._servers.values():
monitor = server._monitor
if not monitor._stream:
return False
Expand Down Expand Up @@ -603,7 +603,7 @@ async def test_rtt_connection_is_disabled_auto(self):

async def assert_rtt_connection_is_disabled(self, client):
await client.admin.command("ping")
for _, server in client._topology._servers.items():
for server in client._topology._servers.values():
monitor = server._monitor
self.assertFalse(monitor._stream)
if _IS_SYNC:
Expand Down
4 changes: 2 additions & 2 deletions test/asynchronous/test_read_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ def test_read_preference_hedge_deprecated(self):
"secondaryPreferred": SecondaryPreferred,
"nearest": Nearest,
}
for _, cls in cases.items():
for cls in cases.values():
with self.assertRaises(DeprecationWarning):
cls(hedge={"enabled": True})

Expand All @@ -593,7 +593,7 @@ async def test_send_hedge(self):
listener = OvertCommandListener()
client = await self.async_rs_client(event_listeners=[listener])
await client.admin.command("ping")
for _mode, cls in cases.items():
for cls in cases.values():
with _ignore_deprecations():
pref = cls(hedge={"enabled": True})
coll = client.test.get_collection("coll", read_preference=pref)
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_sdam_monitoring_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def compare_topology_descriptions(expected, actual):
if len(expected) != len(actual):
return False
for exp_server in expected:
for _address, actual_server in actual.items():
for actual_server in actual.values():
if compare_server_descriptions(exp_server, actual_server):
break
else:
Expand Down
4 changes: 2 additions & 2 deletions test/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def test_index_2dsphere(self):
db.coll.drop_indexes()
self.assertEqual("geo_2dsphere", db.coll.create_index([("geo", GEOSPHERE)]))

for dummy, info in (db.coll.index_information()).items():
for info in (db.coll.index_information()).values():
field, idx_type = info["key"][0]
if field == "geo" and idx_type == "2dsphere":
break
Expand All @@ -513,7 +513,7 @@ def test_index_hashed(self):
db.coll.drop_indexes()
self.assertEqual("a_hashed", db.coll.create_index([("a", HASHED)]))

for dummy, info in (db.coll.index_information()).items():
for info in (db.coll.index_information()).values():
field, idx_type = info["key"][0]
if field == "a" and idx_type == "hashed":
break
Expand Down
2 changes: 1 addition & 1 deletion test/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def test_id_ordering(self):
)
cursor = db.coll.find()
for x in cursor:
for k, _v in x.items():
for k in x.keys():
self.assertEqual(k, "_id")
break

Expand Down
4 changes: 2 additions & 2 deletions test/test_discovery_and_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def test_rtt_connection_is_enabled_stream(self):
client.admin.command("ping")

def predicate():
for _, server in client._topology._servers.items():
for server in client._topology._servers.values():
monitor = server._monitor
if not monitor._stream:
return False
Expand Down Expand Up @@ -600,7 +600,7 @@ def test_rtt_connection_is_disabled_auto(self):

def assert_rtt_connection_is_disabled(self, client):
client.admin.command("ping")
for _, server in client._topology._servers.items():
for server in client._topology._servers.values():
monitor = server._monitor
self.assertFalse(monitor._stream)
if _IS_SYNC:
Expand Down
4 changes: 2 additions & 2 deletions test/test_read_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def test_read_preference_hedge_deprecated(self):
"secondaryPreferred": SecondaryPreferred,
"nearest": Nearest,
}
for _, cls in cases.items():
for cls in cases.values():
with self.assertRaises(DeprecationWarning):
cls(hedge={"enabled": True})

Expand All @@ -573,7 +573,7 @@ def test_send_hedge(self):
listener = OvertCommandListener()
client = self.rs_client(event_listeners=[listener])
client.admin.command("ping")
for _mode, cls in cases.items():
for cls in cases.values():
with _ignore_deprecations():
pref = cls(hedge={"enabled": True})
coll = client.test.get_collection("coll", read_preference=pref)
Expand Down
2 changes: 1 addition & 1 deletion test/test_sdam_monitoring_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def compare_topology_descriptions(expected, actual):
if len(expected) != len(actual):
return False
for exp_server in expected:
for _address, actual_server in actual.items():
for actual_server in actual.values():
if compare_server_descriptions(exp_server, actual_server):
break
else:
Expand Down
4 changes: 1 addition & 3 deletions test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,11 @@ def test_bulk_write(self) -> None:
coll: Collection[Movie] = self.coll
requests: list[InsertOne[Movie]] = [InsertOne(Movie(name="American Graffiti", year=1973))]
self.assertTrue(coll.bulk_write(requests).acknowledged)
new_requests: list[InsertOne[Movie] | ReplaceOne[Movie]] = []
input_list: list[InsertOne[Movie] | ReplaceOne[Movie]] = [
InsertOne(Movie(name="American Graffiti", year=1973)),
ReplaceOne({}, Movie(name="American Graffiti", year=1973)),
]
for i in input_list:
new_requests.append(i)
new_requests: list[InsertOne[Movie] | ReplaceOne[Movie]] = list.copy(input_list)
self.assertTrue(coll.bulk_write(new_requests).acknowledged)

# Because ReplaceOne is not generic, type checking is not enforced for ReplaceOne in the first example.
Expand Down
Loading