Skip to content

Commit 6928565

Browse files
committed
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

Diff for: .flake8

+1
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

Diff for: diffsync/__init__.py

+11-3
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()

Diff for: docs/source/upgrading/01-upgrading-to-2.0.md

+5-1
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

0 commit comments

Comments
 (0)