From b1fedf9b7b4fc8e7d90cfa5f47fecd76c036cd00 Mon Sep 17 00:00:00 2001 From: Sep Dehpour Date: Wed, 26 Mar 2025 20:12:07 -0600 Subject: [PATCH 1/2] fixes #532 type hints typo --- deepdiff/operator.py | 6 ++++-- docs/custom.rst | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/deepdiff/operator.py b/deepdiff/operator.py index 018fa3c..6ecc191 100644 --- a/deepdiff/operator.py +++ b/deepdiff/operator.py @@ -1,8 +1,10 @@ import re -from typing import Any, Optional, List +from typing import Any, Optional, List, TYPE_CHECKING from abc import ABCMeta, abstractmethod from deepdiff.helper import convert_item_or_items_into_compiled_regexes_else_none +if TYPE_CHECKING: + from deepdiff import DeepDiff class BaseOperatorPlus(metaclass=ABCMeta): @@ -16,7 +18,7 @@ def match(self, level) -> bool: pass @abstractmethod - def give_up_diffing(self, level, diff_instance: float) -> bool: + def give_up_diffing(self, level, diff_instance: "DeepDiff") -> bool: """ Given a level which includes t1 and t2 in the tree view, and the "distance" between l1 and l2. do we consider t1 and t2 to be equal or not. The distance is a number between zero to one and is calculated by DeepDiff to measure how similar objects are. diff --git a/docs/custom.rst b/docs/custom.rst index 5c676ff..97b14e4 100644 --- a/docs/custom.rst +++ b/docs/custom.rst @@ -202,7 +202,7 @@ Base Operator Plus pass @abstractmethod - def give_up_diffing(self, level, diff_instance: float) -> bool: + def give_up_diffing(self, level, diff_instance: "DeepDiff") -> bool: """ Given a level which includes t1 and t2 in the tree view, and the "distance" between l1 and l2. do we consider t1 and t2 to be equal or not. The distance is a number between zero to one and is calculated by DeepDiff to measure how similar objects are. From bd6b60b12bb648225cc09b8e8613de49baeea4b6 Mon Sep 17 00:00:00 2001 From: Sep Dehpour Date: Thu, 17 Apr 2025 11:17:06 -0700 Subject: [PATCH 2/2] fixing deprecated pydantic calls --- deepdiff/helper.py | 6 +++++- deepdiff/serialization.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/deepdiff/helper.py b/deepdiff/helper.py index 63a4e31..f91dda5 100644 --- a/deepdiff/helper.py +++ b/deepdiff/helper.py @@ -733,13 +733,17 @@ def detailed__dict__(obj, ignore_private_variables=True, ignore_keys=frozenset() ignore_private_variables and key.startswith('__') and not key.startswith(private_var_prefix) ): del result[key] + if isinstance(obj, PydanticBaseModel): + getter = lambda x, y: getattr(type(x), y) + else: + getter = getattr for key in dir(obj): if key not in result and key not in ignore_keys and ( not ignore_private_variables or ( ignore_private_variables and not key.startswith('__') and not key.startswith(private_var_prefix) ) ): - value = getattr(obj, key) + value = getter(obj, key) if not callable(value): result[key] = value return result diff --git a/deepdiff/serialization.py b/deepdiff/serialization.py index c148aad..857565c 100644 --- a/deepdiff/serialization.py +++ b/deepdiff/serialization.py @@ -616,7 +616,7 @@ def _serialize_tuple(value): } if PydanticBaseModel is not pydantic_base_model_type: - JSON_CONVERTOR[PydanticBaseModel] = lambda x: x.dict() + JSON_CONVERTOR[PydanticBaseModel] = lambda x: x.model_dump() def json_convertor_default(default_mapping=None):