Skip to content

Commit

Permalink
Merge pull request #261 from networktocode/2.0-various-things
Browse files Browse the repository at this point in the history
various 2.0 preparation things
  • Loading branch information
Kircheneer authored Jan 22, 2024
2 parents f5ed544 + 6928565 commit 06afd58
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 50 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# E501: Line length is enforced by Black, so flake8 doesn't need to check it
# W503: Black disagrees with this rule, as does PEP 8; Black wins
ignore = E501, W503
exclude = .venv
14 changes: 11 additions & 3 deletions diffsync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import sys
from inspect import isclass
from typing import Callable, ClassVar, Dict, List, Optional, Tuple, Type, Union, Any, Set
import warnings

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


# For backwards-compatibility, keep around the old name
DiffSync = Adapter
def DiffSync(*args: Any, **kwargs: Any) -> Adapter: # noqa pylint: disable=invalid-name
"""For backwards-compatibility, keep around the old name."""

# DiffSyncModel references DiffSync and DiffSync references DiffSyncModel. Break the typing loop:
warnings.warn(
"'diffsync.DiffSync' is deprecated and will be removed with 2.1, use 'diffsync.Adapter' instead.",
DeprecationWarning,
)
return Adapter(*args, **kwargs)


# DiffSyncModel references Adapter and Adapter references DiffSyncModel. Break the typing loop:
DiffSyncModel.model_rebuild()
6 changes: 5 additions & 1 deletion docs/source/upgrading/01-upgrading-to-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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

## Rename of the `diffsync.Diffsync` class to `diffsync.Adapter`

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.

## Upgrade to Pydantic's major version 2

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:
Expand All @@ -22,7 +26,7 @@ class Person(DiffSyncModel):
age: Optional[int]

# After
class BetterPerson(DiffSyncModel)
class BetterPerson(DiffSyncModel):
_identifiers = ("name",)
_attributes = ("age",)

Expand Down
Loading

0 comments on commit 06afd58

Please sign in to comment.