Skip to content

Commit a577092

Browse files
committed
Replace sum() with faster any() in boolean expressions
1 parent aab4c7d commit a577092

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

mergin/client_push.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def push_project_async(mc, directory) -> Optional[List[UploadJob]]:
220220
if mp.is_versioned_file(f["path"]):
221221
mp.copy_versioned_file_for_upload(f, tmp_dir.name)
222222

223-
if not sum(len(v) for v in changes.values()):
223+
if not any(len(v) for v in changes.values()):
224224
mp.log.info(f"--- push {project_path} - nothing to do")
225225
return
226226

mergin/test/test_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def test_push_pull_changes(mc):
304304

305305
# check changes before applied
306306
pull_changes, push_changes, _ = mc.project_status(project_dir)
307-
assert not sum(len(v) for v in pull_changes.values())
307+
assert not any(len(v) for v in pull_changes.values())
308308
assert next((f for f in push_changes["added"] if f["path"] == f_added), None)
309309
assert next((f for f in push_changes["removed"] if f["path"] == f_removed), None)
310310
assert next((f for f in push_changes["updated"] if f["path"] == f_updated), None)
@@ -388,7 +388,7 @@ def test_cancel_push(mc):
388388

389389
# check changes before applied
390390
pull_changes, push_changes, _ = mc.project_status(project_dir)
391-
assert not sum(len(v) for v in pull_changes.values())
391+
assert not any(len(v) for v in pull_changes.values())
392392
assert next((f for f in push_changes["added"] if f["path"] == f_added), None)
393393
assert next((f for f in push_changes["updated"] if f["path"] == f_updated), None)
394394

@@ -2631,8 +2631,8 @@ def test_editor_push(mc: MerginClient, mc2: MerginClient):
26312631
assert any(file["path"] == txt_file_name for file in project_info.get("files")) is True
26322632
assert any(file["path"] == gpkg_file_name for file in project_info.get("files")) is True
26332633
pull_changes, push_changes, push_changes_summary = mc.project_status(project_dir)
2634-
assert not sum(len(v) for v in pull_changes.values())
2635-
assert not sum(len(v) for v in push_changes.values())
2634+
assert not any(len(v) for v in pull_changes.values())
2635+
assert not any(len(v) for v in push_changes.values())
26362636

26372637
# editor is trying to push row to gpkg file -> it's possible
26382638
shutil.copy(

0 commit comments

Comments
 (0)