GeezerVison is showing github.com — Merge pull request #152 from seperman/dev · flowolf/deepdiff@269fa49
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: AUTHORS +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,3 +20,4 @@ Authors: | 20 | 20 | - Brian Maissy (brianmaissy) for fixing classes which inherit from classes with slots didn't have all of their slots compared | 21 | 21 | - Juan Soler (Soleronline) for adding ignore_type_number | 22 | 22 | - mthaddon for adding timedelta diffing support | | 23 | +- Necrophagos for Hashing of the number 1 vs. True |
Collapse file Copy file name to clipboardExpand all lines: README.md +3-2Lines changed: 3 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -# DeepDiff v 4.0.6 | | 1 | +# DeepDiff v 4.0.7 | 2 | 2 |
| 3 | 3 | <!--  --> | 4 | 4 |  | @@ -417,7 +417,7 @@ And then running | 417 | 417 |
| 418 | 418 | # ChangeLog | 419 | 419 |
| 420 | | - | | 420 | +- v4-0-7: Hashing of the number 1 vs. True | 421 | 421 | - v4-0-6: found a tiny bug in Python formatting of numbers in scientific notation. Added a workaround. | 422 | 422 | - v4-0-5: Fixing number diffing. Adding number_format_notation and number_to_string_func. | 423 | 423 | - v4-0-4: Adding ignore_string_case and ignore_type_subclasses | @@ -503,3 +503,4 @@ Thank you! | 503 | 503 | - Brian Maissy (brianmaissy) for fixing classes which inherit from classes with slots didn't have all of their slots compared | 504 | 504 | - Juan Soler (Soleronline) for adding ignore_type_number | 505 | 505 | - mthaddon for adding timedelta diffing support | | 506 | +- Necrophagos for Hashing of the number 1 vs. True |
Collapse file Copy file name to clipboardExpand all lines: deepdiff/__init__.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | """This module offers the DeepDiff, DeepSearch, grep and DeepHash classes.""" | 2 | 2 | # flake8: noqa | 3 | | -__version__ = '4.0.6' | | 3 | +__version__ = '4.0.7' | 4 | 4 | import logging | 5 | 5 |
| 6 | 6 | if __name__ == '__main__': | |
Collapse file Copy file name to clipboardExpand all lines: deepdiff/deephash.py +17-3Lines changed: 17 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | from collections.abc import Iterable, MutableMapping | 5 | 5 | from collections import defaultdict | 6 | 6 | from hashlib import sha1, sha256 | 7 | | - | | 7 | +from enum import Enum | 8 | 8 | from deepdiff.helper import (strings, numbers, unprocessed, not_hashed, add_to_frozen_set, | 9 | 9 | convert_item_or_items_into_set_else_none, get_doc, | 10 | 10 | convert_item_or_items_into_compiled_regexes_else_none, | | 27 | 27 | INDEX_VS_ATTRIBUTE = ('[%s]', '.%s') | 28 | 28 |
| 29 | 29 |
| | 30 | +class BoolObj(Enum): | | 31 | + TRUE = 1 | | 32 | + FALSE = 0 | | 33 | + | | 34 | + | 30 | 35 | def prepare_string_for_hashing(obj, ignore_string_type_changes=False, ignore_string_case=False): | 31 | 36 | """ | 32 | 37 | Clean type conversions | @@ -259,6 +264,9 @@ def _prep_iterable(self, obj, parent, parents_ids=EMPTY_FROZENSET): | 259 | 264 |
| 260 | 265 | return result | 261 | 266 |
| | 267 | + def _prep_bool(self, obj): | | 268 | + return BoolObj.TRUE if obj else BoolObj.FALSE | | 269 | + | 262 | 270 | def _prep_number(self, obj): | 263 | 271 | type_ = "number" if self.ignore_numeric_type_changes else obj.__class__.__name__ | 264 | 272 | if self.significant_digits is not None: | @@ -282,15 +290,19 @@ def _prep_tuple(self, obj, parent, parents_ids): | 282 | 290 | def _hash(self, obj, parent, parents_ids=EMPTY_FROZENSET): | 283 | 291 | """The main diff method""" | 284 | 292 |
| | 293 | + if isinstance(obj, bool): | | 294 | + obj = self._prep_bool(obj) | | 295 | + result = None | | 296 | + else: | | 297 | + result = not_hashed | | 298 | + | 285 | 299 | try: | 286 | 300 | result = self[obj] | 287 | 301 | except (TypeError, KeyError): | 288 | 302 | pass | 289 | 303 | else: | 290 | 304 | return result | 291 | 305 |
| 292 | | - result = not_hashed | 293 | | - | 294 | 306 | if self._skip_this(obj, parent): | 295 | 307 | return | 296 | 308 |
| @@ -314,6 +326,8 @@ def _hash(self, obj, parent, parents_ids=EMPTY_FROZENSET): | 314 | 326 | elif isinstance(obj, Iterable): | 315 | 327 | result = self._prep_iterable(obj=obj, parent=parent, parents_ids=parents_ids) | 316 | 328 |
| | 329 | + elif obj in {BoolObj.TRUE, BoolObj.FALSE}: | | 330 | + result = 'bool:true' if obj is BoolObj.TRUE else 'bool:false' | 317 | 331 | else: | 318 | 332 | result = self._prep_obj(obj=obj, parent=parent, parents_ids=parents_ids) | 319 | 333 |
| |
Collapse file Copy file name to clipboardExpand all lines: docs/conf.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 60 | 60 | # built documents. | 61 | 61 | # | 62 | 62 | # The short X.Y version. | 63 | | -version = '4.0.6' | | 63 | +version = '4.0.7' | 64 | 64 | # The full version, including alpha/beta/rc tags. | 65 | | -release = '4.0.6' | | 65 | +release = '4.0.7' | 66 | 66 |
| 67 | 67 | # The language for content autogenerated by Sphinx. Refer to documentation | 68 | 68 | # for a list of supported languages. | |
Collapse file Copy file name to clipboardExpand all lines: docs/index.rst +2-1Lines changed: 2 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | contain the root `toctree` directive. | 5 | 5 |
| 6 | 6 |
| 7 | | -DeepDiff 4.0.6 documentation! | | 7 | +DeepDiff 4.0.7 documentation! | 8 | 8 | ============================= | 9 | 9 |
| 10 | 10 | **DeepDiff: Deep Difference of dictionaries, iterables, strings and other objects. It will recursively look for all the changes.** | @@ -281,6 +281,7 @@ Indices and tables | 281 | 281 | Changelog | 282 | 282 | ========= | 283 | 283 |
| | 284 | +- v4-0-7: Hashing of the number 1 vs. True | 284 | 285 | - v4-0-6: found a tiny bug in Python formatting of numbers in scientific notation. Added a workaround. | 285 | 286 | - v4-0-5: Fixing number diffing. Adding number_format_notation and number_to_string_func. | 286 | 287 | - v4-0-4: Adding ignore_string_case and ignore_type_subclasses | |
Collapse file Copy file name to clipboardExpand all lines: setup.cfg +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | [bumpversion] | 2 | | -current_version = 4.0.6 | | 2 | +current_version = 4.0.7 | 3 | 3 | commit = True | 4 | 4 | tag = True | 5 | 5 | tag_name = {new_version} | |
Collapse file Copy file name to clipboardExpand all lines: setup.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 10 | 10 | if os.environ.get('USER', '') == 'vagrant': | 11 | 11 | del os.link | 12 | 12 |
| 13 | | -version = '4.0.6' | | 13 | +version = '4.0.7' | 14 | 14 |
| 15 | 15 |
| 16 | 16 | def get_reqs(filename): | |
Collapse file Copy file name to clipboardExpand all lines: tests/test_diff_text.py +22-1Lines changed: 22 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | #!/usr/bin/env python | 2 | 2 | # -*- coding: utf-8 -*- | 3 | | -import math | 4 | 3 | import datetime | 5 | 4 | import pytest | 6 | 5 | import logging | @@ -1702,3 +1701,25 @@ def test_diff_when_hash_fails(self, mock_DeepHash, mock_logger): | 1702 | 1701 | t2 = {"blah": {4}, 2: 1337} | 1703 | 1702 | DeepDiff(t1, t2, ignore_order=True) | 1704 | 1703 | assert mock_logger.warning.called | | 1704 | + | | 1705 | + def test_bool_vs_number(self): | | 1706 | + t1 = { | | 1707 | + "A List": [ | | 1708 | + { | | 1709 | + "Value One": True, | | 1710 | + "Value Two": 1 | | 1711 | + } | | 1712 | + ], | | 1713 | + } | | 1714 | + | | 1715 | + t2 = { | | 1716 | + "A List": [ | | 1717 | + { | | 1718 | + "Value Two": 1, | | 1719 | + "Value One": True | | 1720 | + } | | 1721 | + ], | | 1722 | + } | | 1723 | + | | 1724 | + ddiff = DeepDiff(t1, t2, ignore_order=True) | | 1725 | + assert ddiff == {} |
Collapse file Copy file name to clipboardExpand all lines: tests/test_hash.py +16-2Lines changed: 16 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | import re | 4 | 4 | import pytest | 5 | 5 | import logging | 6 | | -import math | 7 | 6 | from deepdiff import DeepHash | 8 | | -from deepdiff.deephash import prepare_string_for_hashing, unprocessed | | 7 | +from deepdiff.deephash import prepare_string_for_hashing, unprocessed, BoolObj | 9 | 8 | from deepdiff.helper import pypy3, get_id, number_to_string | 10 | 9 | from collections import namedtuple | 11 | 10 | from functools import partial | @@ -97,6 +96,21 @@ def test_sha1_hash_not_sensitive_to_bytecode_vs_unicode(self): | 97 | 96 | class TestDeepHashPrep: | 98 | 97 | """DeepHashPrep Tests covering object serialization.""" | 99 | 98 |
| | 99 | + def test_prep_bool_vs_num1(self): | | 100 | + assert {BoolObj.TRUE: 'bool:true'} == DeepHashPrep(True) | | 101 | + assert {1: 'int:1'} == DeepHashPrep(1) | | 102 | + | | 103 | + def test_prep_bool_vs_num2(self): | | 104 | + item1 = { | | 105 | + "Value One": True, | | 106 | + "Value Two": 1, | | 107 | + } | | 108 | + item2 = { | | 109 | + "Value Two": 1, | | 110 | + "Value One": True, | | 111 | + } | | 112 | + assert DeepHashPrep(item1)[item1] == DeepHashPrep(item2)[item2] | | 113 | + | 100 | 114 | def test_prep_str(self): | 101 | 115 | obj = "a" | 102 | 116 | expected_result = {obj: prep_str(obj)} | |
|