Skip to content

Commit 1156c39

Browse files
author
Leo Kirchner
committed
various 2.0 preparation things
1 parent f5ed544 commit 1156c39

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
# E501: Line length is enforced by Black, so flake8 doesn't need to check it
33
# W503: Black disagrees with this rule, as does PEP 8; Black wins
44
ignore = E501, W503
5+
exclude = .venv

diffsync/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,15 @@ def count(self, model: Union[StrType, "DiffSyncModel", Type["DiffSyncModel"], No
855855

856856

857857
# For backwards-compatibility, keep around the old name
858-
DiffSync = Adapter
858+
def DiffSync(*args: Any, **kwargs: Any) -> Adapter: # noqa
859+
import warnings
859860

860-
# DiffSyncModel references DiffSync and DiffSync references DiffSyncModel. Break the typing loop:
861+
warnings.warn(
862+
"'diffsync.DiffSync' is deprecated and will be removed with 2.1, use 'diffsync.Adapter' instead.",
863+
DeprecationWarning,
864+
)
865+
return Adapter(*args, **kwargs)
866+
867+
868+
# DiffSyncModel references Adapter and Adapter references DiffSyncModel. Break the typing loop:
861869
DiffSyncModel.model_rebuild()

docs/source/upgrading/01-upgrading-to-2.0.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
With diffsync 2.0, there a couple of breaking changes. What they are and how to deal with them is described in this document.
44

5+
## Rename of the `diffsync.Diffsync` class to `diffsync.Adapter`
6+
7+
The main diffsync class `diffsync.Diffsync` has been renamed to `diffsync.Adapter` as we have found that this is the verbiage that is most often used by users and explains the intent of the class clearer. The old name will still be around until 2.1, but is considered deprecated at this point.
8+
59
## Upgrade to Pydantic's major version 2
610

711
A [migration guide](https://docs.pydantic.dev/latest/migration/) is available in the Pydantic documentation. Here are the key things that may apply to your usage of diffsync:
@@ -22,7 +26,7 @@ class Person(DiffSyncModel):
2226
age: Optional[int]
2327

2428
# After
25-
class BetterPerson(DiffSyncModel)
29+
class BetterPerson(DiffSyncModel):
2630
_identifiers = ("name",)
2731
_attributes = ("age",)
2832

tests/unit/test_diffsync_model_flags.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class ParentModel(DiffSyncModel):
194194
attribute: str
195195
children: List[ChildModel] = []
196196

197-
class Adapter(DiffSync):
197+
class TestAdapter(Adapter):
198198
"""Test adapter."""
199199

200200
top_level = ["parent"]
@@ -218,9 +218,9 @@ def load(self, is_source=False) -> None:
218218
parent.add_child(child)
219219
self.add(child)
220220

221-
source_adapter = Adapter()
221+
source_adapter = TestAdapter()
222222
source_adapter.load(is_source=True)
223-
destination_adapter = Adapter()
223+
destination_adapter = TestAdapter()
224224
destination_adapter.load()
225225

226226
source_adapter.sync_to(destination_adapter)

0 commit comments

Comments
 (0)