From ab7bf4aa54f5273dd425d0f11dd9f059d9c89dc8 Mon Sep 17 00:00:00 2001 From: Andrew Bates Date: Thu, 26 Sep 2024 11:52:37 -0400 Subject: [PATCH 1/2] DiffSync deprecation fix --- diffsync/__init__.py | 10 +++------- tests/unit/test_deprecation.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 tests/unit/test_deprecation.py diff --git a/diffsync/__init__.py b/diffsync/__init__.py index 788b8e6..de18b2d 100644 --- a/diffsync/__init__.py +++ b/diffsync/__init__.py @@ -28,6 +28,7 @@ Any, Set, ) +from typing_extensions import deprecated import warnings from pydantic import ConfigDict, BaseModel, PrivateAttr @@ -894,15 +895,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() diff --git a/tests/unit/test_deprecation.py b/tests/unit/test_deprecation.py new file mode 100644 index 0000000..86726c1 --- /dev/null +++ b/tests/unit/test_deprecation.py @@ -0,0 +1,10 @@ + +from diffsync import DiffSync + +import pytest + +def test_diffsync_deprecation_warning(): + with pytest.deprecated_call(): + class TestAdapter(DiffSync): + pass + TestAdapter() From e4656261f537dfa906b22ec73373fc8ac400affd Mon Sep 17 00:00:00 2001 From: Andrew Bates Date: Thu, 26 Sep 2024 12:07:14 -0400 Subject: [PATCH 2/2] Formatting --- diffsync/__init__.py | 1 - tests/unit/test_deprecation.py | 24 ++++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/diffsync/__init__.py b/diffsync/__init__.py index de18b2d..db404ea 100644 --- a/diffsync/__init__.py +++ b/diffsync/__init__.py @@ -29,7 +29,6 @@ Set, ) from typing_extensions import deprecated -import warnings from pydantic import ConfigDict, BaseModel, PrivateAttr import structlog # type: ignore diff --git a/tests/unit/test_deprecation.py b/tests/unit/test_deprecation.py index 86726c1..c85345b 100644 --- a/tests/unit/test_deprecation.py +++ b/tests/unit/test_deprecation.py @@ -1,10 +1,30 @@ +"""Unit tests for the DiffSync deprecation warning. -from diffsync import DiffSync +Copyright (c) 2020-2024 Network To Code, LLC + +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): + + class TestAdapter(DiffSync): # pylint:disable=missing-class-docstring pass + TestAdapter()