Skip to content

Commit d7ea41b

Browse files
authored
Few Updates to Prep for SSoT Refactor (#303)
* Adding dunder new to Adapter to copy meta kwargs to instance for later retrieval * fix: Ensure that dict_type has a default for OrderedDefaultDict to work with deepcopy. * build: Update project dependencies * Ignore mypy complaints * test: ✅ Add tests validating __new__ function. * test: 🚨 Ignore pylint warning
1 parent c58590d commit d7ea41b

File tree

4 files changed

+1080
-712
lines changed

4 files changed

+1080
-712
lines changed

diffsync/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""
1717

1818
import sys
19+
from copy import deepcopy
1920
from inspect import isclass
2021
from typing import (
2122
Any,
@@ -480,6 +481,13 @@ def __init_subclass__(cls) -> None:
480481
if not isclass(value) or not issubclass(value, DiffSyncModel):
481482
raise AttributeError(f'top_level references attribute "{name}" but it is not a DiffSyncModel subclass!')
482483

484+
def __new__(cls, **kwargs): # type: ignore[no-untyped-def]
485+
"""Document keyword arguments that were used to initialize Adapter."""
486+
meta_kwargs = deepcopy(kwargs)
487+
instance = super().__new__(cls)
488+
instance._meta_kwargs = meta_kwargs
489+
return instance
490+
483491
def __str__(self) -> StrType:
484492
"""String representation of an Adapter."""
485493
if self.type != self.name:

diffsync/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"""
1717

1818
from collections import OrderedDict
19-
from typing import Iterator, List, Dict, Optional, TypeVar, Callable, Generic
19+
from typing import Callable, Dict, Generic, Iterator, List, Optional, TypeVar
2020

2121
SPACE = " "
2222
BRANCH = "│ "
@@ -44,7 +44,7 @@ def symmetric_difference(lst1: List[T], lst2: List[T]) -> List[T]:
4444
class OrderedDefaultDict(OrderedDict, Generic[K, V]):
4545
"""A combination of collections.OrderedDict and collections.DefaultDict behavior."""
4646

47-
def __init__(self, dict_type: Callable[[], V]) -> None:
47+
def __init__(self, dict_type: Callable[[], V] = dict) -> None: # type: ignore[assignment]
4848
"""Create a new OrderedDefaultDict."""
4949
self.factory = dict_type
5050
super().__init__(self)

0 commit comments

Comments
 (0)