From 2b77836910c4c47efae7d42e595375e7b23528a7 Mon Sep 17 00:00:00 2001 From: Sep Dehpour Date: Fri, 8 Nov 2019 15:40:23 -0800 Subject: [PATCH 1/3] fixing Regression on objects list diff when using ignore_order=True #164 --- README.md | 1 + deepdiff/deephash.py | 2 +- deepdiff/diff.py | 6 +++--- docs/index.rst | 1 + tests/__init__.py | 9 +++++++++ tests/test_diff_text.py | 17 +++++++++++++++-- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9d918ac3..35123e92 100644 --- a/README.md +++ b/README.md @@ -417,6 +417,7 @@ And then running # ChangeLog +- v4-0-9: Fixing the bug for hashing custom unhashable objects - v4-0-8: Adding ignore_nan_inequality for float('nan') - v4-0-7: Hashing of the number 1 vs. True - v4-0-6: found a tiny bug in Python formatting of numbers in scientific notation. Added a workaround. diff --git a/deepdiff/deephash.py b/deepdiff/deephash.py index ad544a17..cd4c51d2 100644 --- a/deepdiff/deephash.py +++ b/deepdiff/deephash.py @@ -326,7 +326,7 @@ def _hash(self, obj, parent, parents_ids=EMPTY_FROZENSET): elif isinstance(obj, Iterable): result = self._prep_iterable(obj=obj, parent=parent, parents_ids=parents_ids) - elif obj in {BoolObj.TRUE, BoolObj.FALSE}: + elif obj == BoolObj.TRUE or obj == BoolObj.FALSE: result = 'bool:true' if obj is BoolObj.TRUE else 'bool:false' else: result = self._prep_obj(obj=obj, parent=parent, parents_ids=parents_ids) diff --git a/deepdiff/diff.py b/deepdiff/diff.py index b7b355fc..f4973722 100755 --- a/deepdiff/diff.py +++ b/deepdiff/diff.py @@ -478,9 +478,9 @@ def __create_hashtable(self, t, level): ) item_hash = hashes_all[item] except Exception as e: # pragma: no cover - logger.warning("Can not produce a hash for %s." - "Not counting this object.\n %s" % - (level.path(), e)) + logger.error("Can not produce a hash for %s." + "Not counting this object.\n %s" % + (level.path(), e)) else: if item_hash is unprocessed: # pragma: no cover logger.warning("Item %s was not processed while hashing " diff --git a/docs/index.rst b/docs/index.rst index 7d4b633a..e89fb820 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -281,6 +281,7 @@ Indices and tables Changelog ========= +- v4-0-9: Fixing the bug for hashing custom unhashable objects - v4-0-8: Adding ignore_nan_inequality for float('nan') - v4-0-7: Hashing of the number 1 vs. True - v4-0-6: found a tiny bug in Python formatting of numbers in scientific notation. Added a workaround. diff --git a/tests/__init__.py b/tests/__init__.py index a0010f30..de57a9f7 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -16,3 +16,12 @@ def __repr__(self): class CustomClassMisleadingRepr(CustomClass): def __str__(self): return "({}, {})".format(self.a, self.b) + + +class CustomClass2: + def __init__(self, prop1=None, prop2=None): + self.prop1 = prop1 or [] + self.prop2 = prop2 or [] + + def __eq__(self, other): + return self.__dict__ == other.__dict__ diff --git a/tests/test_diff_text.py b/tests/test_diff_text.py index 09a7af16..5b62eb8b 100755 --- a/tests/test_diff_text.py +++ b/tests/test_diff_text.py @@ -8,7 +8,7 @@ from deepdiff import DeepDiff from deepdiff.helper import number_to_string from deepdiff.helper import pypy3 -from tests import CustomClass +from tests import CustomClass, CustomClass2 logging.disable(logging.CRITICAL) @@ -858,6 +858,19 @@ def test_custom_objects_change(self): } assert result == ddiff + def test_custom_objects2(self): + cc_a = CustomClass2(prop1=["a"], prop2=["b"]) + cc_b = CustomClass2(prop1=["b"], prop2=["b"]) + t1 = [cc_a, CustomClass2(prop1=["c"], prop2=["d"])] + t2 = [cc_b, CustomClass2(prop1=["c"], prop2=["d"])] + + ddiff = DeepDiff(t1, t2, ignore_order=True) + + result = {'iterable_item_added': {'root[0]': cc_b}, + 'iterable_item_removed': {'root[0]': cc_a}} + + assert result == ddiff + def test_custom_objects_slot_change(self): class ClassA: __slots__ = ('x', 'y') @@ -1701,7 +1714,7 @@ def test_diff_when_hash_fails(self, mock_DeepHash, mock_logger): t1 = {"blah": {4}, 2: 1337} t2 = {"blah": {4}, 2: 1337} DeepDiff(t1, t2, ignore_order=True) - assert mock_logger.warning.called + assert mock_logger.error.called def test_bool_vs_number(self): t1 = { From a98b8490314826e543de0a674b574cf010e13589 Mon Sep 17 00:00:00 2001 From: Sep Dehpour Date: Fri, 8 Nov 2019 15:41:25 -0800 Subject: [PATCH 2/3] =?UTF-8?q?Bump=20version:=204.0.8=20=E2=86=92=204.0.9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- deepdiff/__init__.py | 2 +- docs/conf.py | 4 ++-- docs/index.rst | 2 +- setup.cfg | 2 +- setup.py | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 35123e92..cef8b4f1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# DeepDiff v 4.0.8 +# DeepDiff v 4.0.9 ![Python Versions](https://img.shields.io/pypi/pyversions/deepdiff.svg?style=flat) diff --git a/deepdiff/__init__.py b/deepdiff/__init__.py index 8910fb9a..24d63750 100644 --- a/deepdiff/__init__.py +++ b/deepdiff/__init__.py @@ -1,6 +1,6 @@ """This module offers the DeepDiff, DeepSearch, grep and DeepHash classes.""" # flake8: noqa -__version__ = '4.0.8' +__version__ = '4.0.9' import logging if __name__ == '__main__': diff --git a/docs/conf.py b/docs/conf.py index 5fbfdf8f..55c69fb1 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -60,9 +60,9 @@ # built documents. # # The short X.Y version. -version = '4.0.8' +version = '4.0.9' # The full version, including alpha/beta/rc tags. -release = '4.0.8' +release = '4.0.9' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/index.rst b/docs/index.rst index e89fb820..3c1b6b8f 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -4,7 +4,7 @@ contain the root `toctree` directive. -DeepDiff 4.0.8 documentation! +DeepDiff 4.0.9 documentation! ============================= **DeepDiff: Deep Difference of dictionaries, iterables, strings and other objects. It will recursively look for all the changes.** diff --git a/setup.cfg b/setup.cfg index 84d90157..bf3f2e28 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 4.0.8 +current_version = 4.0.9 commit = True tag = True tag_name = {new_version} diff --git a/setup.py b/setup.py index b126425f..ca7dea52 100755 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ if os.environ.get('USER', '') == 'vagrant': del os.link -version = '4.0.8' +version = '4.0.9' def get_reqs(filename): From b2cf107cf87038d4e6518bdeadd7618c0e36e596 Mon Sep 17 00:00:00 2001 From: Sep Dehpour Date: Fri, 8 Nov 2019 15:43:58 -0800 Subject: [PATCH 3/3] add python 3.8 to the test cases --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index bcbb06e6..9c8cae48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ matrix: - python: 3.6 - python: pypy3 - python: 3.7 + - python: 3.8 dist: xenial sudo: true