Skip to content

Commit 75c2d8f

Browse files
authored
DiffSync deprecation fix (#281)
* DiffSync deprecation fix * Formatting
1 parent 7ca1717 commit 75c2d8f

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

diffsync/__init__.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
Any,
2929
Set,
3030
)
31-
import warnings
31+
from typing_extensions import deprecated
3232

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

896896

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

900-
warnings.warn(
901-
"'diffsync.DiffSync' is deprecated and will be removed with 2.1, use 'diffsync.Adapter' instead.",
902-
DeprecationWarning,
903-
)
904-
return Adapter(*args, **kwargs)
905-
906901

907902
# DiffSyncModel references Adapter and Adapter references DiffSyncModel. Break the typing loop:
908903
DiffSyncModel.model_rebuild()

tests/unit/test_deprecation.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Unit tests for the DiffSync deprecation warning.
2+
3+
Copyright (c) 2020-2024 Network To Code, LLC <[email protected]>
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
"""
17+
18+
import pytest
19+
20+
from diffsync import DiffSync
21+
22+
23+
def test_diffsync_deprecation_warning():
24+
"""Test that `DiffSync` causes a deprecation warning."""
25+
with pytest.deprecated_call():
26+
27+
class TestAdapter(DiffSync): # pylint:disable=missing-class-docstring
28+
pass
29+
30+
TestAdapter()

0 commit comments

Comments
 (0)