Skip to content

Commit

Permalink
DiffSync deprecation fix (#281)
Browse files Browse the repository at this point in the history
* DiffSync deprecation fix

* Formatting
  • Loading branch information
abates authored Sep 26, 2024
1 parent 7ca1717 commit 75c2d8f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
11 changes: 3 additions & 8 deletions diffsync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
Any,
Set,
)
import warnings
from typing_extensions import deprecated

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


def DiffSync(*args: Any, **kwargs: Any) -> Adapter: # noqa pylint: disable=invalid-name
@deprecated("'diffsync.DiffSync' is deprecated and will be removed with 2.1, use 'diffsync.Adapter' instead.")
class DiffSync(Adapter):
"""For backwards-compatibility, keep around the old name."""

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()
30 changes: 30 additions & 0 deletions tests/unit/test_deprecation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Unit tests for the DiffSync deprecation warning.
Copyright (c) 2020-2024 Network To Code, LLC <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import pytest

from diffsync import DiffSync


def test_diffsync_deprecation_warning():
"""Test that `DiffSync` causes a deprecation warning."""
with pytest.deprecated_call():

class TestAdapter(DiffSync): # pylint:disable=missing-class-docstring
pass

TestAdapter()

0 comments on commit 75c2d8f

Please sign in to comment.