Skip to content

Commit 5bf7e9a

Browse files
committed
chore(lint): address SIM102
1 parent 71878e4 commit 5bf7e9a

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

tubesync/sync/tasks.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -450,20 +450,17 @@ def cleanup_removed_media(source_id, video_keys):
450450

451451

452452
def save_db_batch(qs, objs, fields, /):
453-
assert hasattr(qs, 'bulk_update')
454-
assert callable(qs.bulk_update)
455-
assert hasattr(objs, '__len__')
456-
assert callable(objs.__len__)
453+
assert callable(getattr(qs, 'bulk_update', False))
454+
assert callable(getattr(objs, '__len__', False))
457455
assert isinstance(fields, (tuple, list, set, frozenset))
458456

459457
num_updated = 0
460458
num_objs = len(objs)
461459
with atomic(durable=False):
462460
num_updated = qs.bulk_update(objs=objs, fields=fields)
463-
if num_objs == num_updated:
461+
if num_objs == num_updated and callable(func := getattr(objs, 'clear', False)):
464462
# this covers at least: list, set, deque
465-
if hasattr(objs, 'clear') and callable(objs.clear):
466-
objs.clear()
463+
func()
467464
return num_updated
468465

469466

0 commit comments

Comments
 (0)