Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6928565

Browse files
committedJan 22, 2024
various 2.0 preparation things
1 parent f5ed544 commit 6928565

File tree

5 files changed

+161
-50
lines changed

5 files changed

+161
-50
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: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import sys
1818
from inspect import isclass
1919
from typing import Callable, ClassVar, Dict, List, Optional, Tuple, Type, Union, Any, Set
20+
import warnings
2021

2122
from pydantic import ConfigDict, BaseModel, PrivateAttr
2223
import structlog # type: ignore
@@ -854,8 +855,15 @@ def count(self, model: Union[StrType, "DiffSyncModel", Type["DiffSyncModel"], No
854855
return self.store.count(model=model)
855856

856857

857-
# For backwards-compatibility, keep around the old name
858-
DiffSync = Adapter
858+
def DiffSync(*args: Any, **kwargs: Any) -> Adapter: # noqa pylint: disable=invalid-name
859+
"""For backwards-compatibility, keep around the old name."""
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

‎poetry.lock

Lines changed: 141 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎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)
Please sign in to comment.