Skip to content

Commit 7406bea

Browse files
jdrew82claude
andcommitted
style: Fix linter warnings and missing docstring args
Apply linter auto-fixes (unused imports, whitespace, line length) and add missing batch_size/concurrent/max_workers arg descriptions to sync_to() docstring. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b395cab commit 7406bea

File tree

5 files changed

+17
-23
lines changed

5 files changed

+17
-23
lines changed

diffsync/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,9 @@ def sync_to( # pylint: disable=too-many-arguments, too-many-positional-argument
728728
sync_attrs: Optional dict of {model_type: set_of_attr_names} to whitelist attributes for syncing.
729729
exclude_attrs: Optional dict of {model_type: set_of_attr_names} to exclude attributes from syncing.
730730
sync_filter: Optional callback (action, model_type, ids, attrs) -> bool to approve/reject each operation.
731+
batch_size: Optional chunk size for batched sync execution.
732+
concurrent: If True, sync independent top-level subtrees in parallel.
733+
max_workers: Maximum number of threads for concurrent sync.
731734
732735
Returns:
733736
Diff between origin object and target

diffsync/helpers.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"""
1717

1818
import threading
19-
from collections import defaultdict
2019
from collections.abc import Iterable as ABCIterable
2120
from collections.abc import Mapping as ABCMapping
2221
from concurrent.futures import ThreadPoolExecutor, as_completed
@@ -519,15 +518,11 @@ def sync_model( # pylint: disable=too-many-branches, unused-argument
519518
dst_model = self._local.model_class.create(adapter=self.dst_diffsync, ids=ids, attrs=attrs)
520519
elif self._local.action == DiffSyncActions.UPDATE:
521520
if dst_model is None:
522-
raise ObjectNotUpdated(
523-
f"Failed to update {self._local.model_class.get_type()} {ids} - not found!"
524-
)
521+
raise ObjectNotUpdated(f"Failed to update {self._local.model_class.get_type()} {ids} - not found!")
525522
dst_model = dst_model.update(attrs=attrs)
526523
elif self._local.action == DiffSyncActions.DELETE:
527524
if dst_model is None:
528-
raise ObjectNotDeleted(
529-
f"Failed to delete {self._local.model_class.get_type()} {ids} - not found!"
530-
)
525+
raise ObjectNotDeleted(f"Failed to delete {self._local.model_class.get_type()} {ids} - not found!")
531526
dst_model = dst_model.delete()
532527
else:
533528
raise ObjectCrudException(f'Unknown action "{self._local.action}"!')
@@ -536,10 +531,7 @@ def sync_model( # pylint: disable=too-many-branches, unused-argument
536531
status, message = dst_model.get_status()
537532
else:
538533
status = DiffSyncStatus.FAILURE
539-
message = (
540-
f"{self._local.model_class.get_type()} "
541-
f"{self._local.action} did not return the model object."
542-
)
534+
message = f"{self._local.model_class.get_type()} {self._local.action} did not return the model object."
543535

544536
except ObjectCrudException as exception:
545537
status = DiffSyncStatus.ERROR
@@ -557,9 +549,7 @@ def sync_model( # pylint: disable=too-many-branches, unused-argument
557549
model_type = self._local.model_class.get_type()
558550
if model_type not in self.operations:
559551
self.operations[model_type] = {"create": [], "update": [], "delete": []}
560-
self.operations[model_type][self._local.action].append(
561-
{"ids": ids, "attrs": attrs, "model": dst_model}
562-
)
552+
self.operations[model_type][self._local.action].append({"ids": ids, "attrs": attrs, "model": dst_model})
563553

564554
return (True, dst_model)
565555

tests/unit/test_diff_filtering.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
limitations under the License.
1616
"""
1717

18-
import pytest
1918

20-
from diffsync.diff import Diff, DiffElement
2119

2220

2321
def test_diff_filter_by_action_create(diff_with_children):

tests/unit/test_diffsync_diff_and_sync_parameters.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@
1717

1818
from typing import Dict, List, Optional
1919

20-
import pytest
21-
2220
from diffsync import Adapter, DiffSyncModel
2321
from diffsync.enum import DiffSyncFlags
2422

25-
2623
# ---------------------------------------------------------------------------
2724
# Models and adapters used across this test module
2825
# ---------------------------------------------------------------------------
2926

27+
3028
class _Site(DiffSyncModel):
3129
_modelname = "site"
3230
_identifiers = ("name",)
@@ -97,6 +95,7 @@ def _make_adapter_pair():
9795
# model_types scoping
9896
# ---------------------------------------------------------------------------
9997

98+
10099
def test_diff_with_model_types_restricts_to_site_only():
101100
"""Passing model_types={'site'} should exclude child device elements from the diff."""
102101
src, dst = _make_adapter_pair()
@@ -133,6 +132,7 @@ def test_sync_with_model_types_does_not_touch_excluded_types():
133132
# sync_attrs / exclude_attrs
134133
# ---------------------------------------------------------------------------
135134

135+
136136
def test_sync_attrs_limits_diff_to_whitelisted_attributes():
137137
"""Only the attributes named in sync_attrs should appear in the diff."""
138138
src, dst = _make_adapter_pair()
@@ -179,6 +179,7 @@ def test_sync_attrs_and_exclude_attrs_applied_together():
179179
# filters (query predicates)
180180
# ---------------------------------------------------------------------------
181181

182+
182183
def test_filters_include_matching_objects():
183184
"""Objects whose predicate returns True should be included in the diff."""
184185
src, dst = _make_adapter_pair()
@@ -190,8 +191,8 @@ def test_filters_include_matching_objects():
190191
if device_el.type == "device":
191192
device_names.add(device_el.name)
192193

193-
assert "device1" in device_names # spine in source
194-
assert "device3" in device_names # spine in source
194+
assert "device1" in device_names # spine in source
195+
assert "device3" in device_names # spine in source
195196
assert "device2" not in device_names # leaf in source, filtered out
196197

197198

@@ -222,6 +223,7 @@ def test_filters_do_not_affect_unfiltered_types():
222223
# sync_filter callback
223224
# ---------------------------------------------------------------------------
224225

226+
225227
def test_sync_filter_blocks_delete_operations():
226228
"""A sync_filter that rejects deletes should preserve objects that only exist in the destination."""
227229
src, dst = _make_adapter_pair()
@@ -280,6 +282,7 @@ def test_sync_filter_blocks_by_model_type():
280282
# sync_complete operations summary
281283
# ---------------------------------------------------------------------------
282284

285+
283286
class _TrackingAdapter(_SimpleAdapter):
284287
"""Adapter that captures the operations dict passed to sync_complete."""
285288

@@ -354,6 +357,7 @@ def sync_complete(self, source, diff, flags=DiffSyncFlags.NONE, logger=None):
354357
# concurrent sync
355358
# ---------------------------------------------------------------------------
356359

360+
357361
def test_concurrent_sync_matches_serial_sync():
358362
"""Syncing with concurrent=True should produce the same result as a serial sync."""
359363
src, dst_serial = _make_adapter_pair()
@@ -377,6 +381,7 @@ def test_sync_defaults_to_serial():
377381
# Combinations of multiple parameters
378382
# ---------------------------------------------------------------------------
379383

384+
380385
def test_diff_filter_then_sync_with_sync_filter():
381386
"""A pre-filtered Diff combined with a sync_filter should respect both layers."""
382387
src, dst = _make_adapter_pair()

tests/unit/test_diffsync_model_bulk.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
from typing import List
1919

20-
import pytest
21-
2220
from diffsync import Adapter, DiffSyncModel
2321

2422

0 commit comments

Comments
 (0)