Skip to content

Commit

Permalink
Merge pull request #173 from seperman/dev
Browse files Browse the repository at this point in the history
4.2.0
  • Loading branch information
seperman authored Jan 30, 2020
2 parents c8e61d1 + 5709f22 commit c2bd1f1
Show file tree
Hide file tree
Showing 24 changed files with 131 additions and 139 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
language: python
cache: pip

matrix:
include:
- python: 3.4
- python: 3.5
- python: 3.6
- python: pypy3
- python: 3.7
- python: 3.8
dist: xenial
sudo: true

install:
- pip install -r requirements-dev.txt
Expand Down
7 changes: 5 additions & 2 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Authors:
Many thanks to the following people for their contributions to DeepDiff:

- Seperman
- Victor Hahn Castell @ Flexoptix
- nfvs for Travis-CI setup script.
- brbsix for initial Py3 porting.
- WangFenjin for unicode support.
- WangFenjin for Unicode support.
- timoilya for comparing list of sets when ignoring order.
- Bernhard10 for significant digits comparison.
- b-jazz for PEP257 cleanup, Standardize on full names, fixing line endings.
Expand All @@ -21,3 +22,5 @@ Authors:
- Juan Soler (Soleronline) for adding ignore_type_number
- mthaddon for adding timedelta diffing support
- Necrophagos for Hashing of the number 1 vs. True
- Hugo (hugovk) for fixes for Python 3.10 and dropping support for EOL Python 3.4
- Andrey Gavrilin (gaal-dev) for hashing classes.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# DeepDiff v 4.0.9
# DeepDiff v 4.2.0

<!-- ![Downloads](https://img.shields.io/pypi/dm/deepdiff.svg?style=flat) -->
![Python Versions](https://img.shields.io/pypi/pyversions/deepdiff.svg?style=flat)
Expand All @@ -11,7 +11,7 @@
- DeepSearch: Search for objects within other objects.
- DeepHash: Hash any object based on their content.

Tested on Python 3.4, 3.5, 3.6, 3.7, Pypy3
Tested on Python 3.5+ and PyPy3.

**NOTE: Python 2 is not supported any more. DeepDiff v3.3.0 was the last version to support Python 2**

Expand Down Expand Up @@ -417,6 +417,7 @@ And then running

# ChangeLog

- v4-2-0: .json property is finally removed. Fix for Py3.10. Dropping support for EOL Python 3.4. Ignoring private keys when calculating hashes. For example __init__ is not a part of hash calculation anymore. Fix for #166 Problem with comparing lists, with an boolean as element.
- 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
Expand Down
2 changes: 1 addition & 1 deletion deepdiff/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""This module offers the DeepDiff, DeepSearch, grep and DeepHash classes."""
# flake8: noqa
__version__ = '4.0.9'
__version__ = '4.2.0'
import logging

if __name__ == '__main__':
Expand Down
10 changes: 6 additions & 4 deletions deepdiff/deephash.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
from collections.abc import Iterable, MutableMapping
from collections import defaultdict
Expand Down Expand Up @@ -171,8 +170,8 @@ def __contains__(self, obj):
return super().__contains__(key)

def _prep_obj(self, obj, parent, parents_ids=EMPTY_FROZENSET, is_namedtuple=False):
"""Difference of 2 objects"""
original_type = type(obj)
"""prepping objects"""
original_type = type(obj) if not isinstance(obj, type) else obj
try:
if is_namedtuple:
obj = obj._asdict()
Expand Down Expand Up @@ -209,6 +208,9 @@ def _prep_dict(self, obj, parent, parents_ids=EMPTY_FROZENSET, print_as_attribut

key_text = "%s{}".format(INDEX_VS_ATTRIBUTE[print_as_attribute])
for key, item in obj.items():
# ignore private variables
if isinstance(key, str) and key.startswith('__'):
continue
key_formatted = "'%s'" % key if not print_as_attribute and isinstance(key, strings) else key
key_in_report = key_text % (parent, key_formatted)

Expand All @@ -232,7 +234,7 @@ def _prep_dict(self, obj, parent, parents_ids=EMPTY_FROZENSET, print_as_attribut
break
else:
type_str = 'dict'
return "%s:{%s}" % (type_str, result)
return "{}:{{{}}}".format(type_str, result)

def _prep_iterable(self, obj, parent, parents_ids=EMPTY_FROZENSET):

Expand Down
56 changes: 24 additions & 32 deletions deepdiff/diff.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# In order to run the docstrings:
# python3 -m deepdiff.diff
Expand All @@ -10,7 +9,6 @@
import difflib
import logging
import json
import jsonpickle
import warnings

from itertools import zip_longest
Expand All @@ -27,12 +25,19 @@
from deepdiff.model import RemapDict, ResultDict, TextResult, TreeResult, DiffLevel
from deepdiff.model import DictRelationship, AttributeRelationship
from deepdiff.model import SubscriptableIterableRelationship, NonSubscriptableIterableRelationship, SetRelationship
from deepdiff.deephash import DeepHash
from deepdiff.deephash import DeepHash, BoolObj
from deepdiff.base import Base

logger = logging.getLogger(__name__)
warnings.simplefilter('once', DeprecationWarning)

try:
import jsonpickle
except ImportError:
jsonpickle = None
logger.info('jsonpickle is not installed. The to_json_pickle and from_json_pickle functions will not work.'
'If you dont need those functions, there is nothing to do.')

TREE_VIEW = 'tree'
TEXT_VIEW = 'text'

Expand Down Expand Up @@ -476,7 +481,13 @@ def __create_hashtable(self, t, level):
ignore_string_case=self.ignore_string_case,
number_to_string_func=self.number_to_string,
)
item_hash = hashes_all[item]
# import pytest; pytest.set_trace()
key = item
if item is True:
key = BoolObj.TRUE
elif item is False:
key = BoolObj.FALSE
item_hash = hashes_all[key]
except Exception as e: # pragma: no cover
logger.error("Can not produce a hash for %s."
"Not counting this object.\n %s" %
Expand Down Expand Up @@ -642,45 +653,26 @@ def __diff(self, level, parents_ids=frozenset({})):
else:
self.__diff_obj(level, parents_ids)

@property
def json(self):
warnings.warn(
"json property will be deprecated. Instead use: to_json_pickle() to get the json pickle or to_json() for bare-bone json.",
DeprecationWarning
)
if not hasattr(self, '_json'):
# copy of self removes all the extra attributes since it assumes
# we have only a simple dictionary.
copied = self.copy()
self._json = jsonpickle.encode(copied)
return self._json

def to_json_pickle(self):
"""
Get the json pickle of the diff object. Unless you need all the attributes and functionality of DeepDiff, running to_json() is the safer option that json pickle.
"""
copied = self.copy()
return jsonpickle.encode(copied)

@json.deleter
def json(self):
del self._json

@classmethod
def from_json(cls, value):
warnings.warn(
"from_json is renamed to from_json_pickle",
DeprecationWarning
)
return cls.from_json_pickle(value)
if jsonpickle:
copied = self.copy()
return jsonpickle.encode(copied)
else:
logger.error('jsonpickle library needs to be installed in order to run to_json_pickle')

@classmethod
def from_json_pickle(cls, value):
"""
Load DeepDiff object with all the bells and whistles from the json pickle dump.
Note that json pickle dump comes from to_json_pickle
"""
return jsonpickle.decode(value)
if jsonpickle:
return jsonpickle.decode(value)
else:
logger.error('jsonpickle library needs to be installed in order to run from_json_pickle')

def to_json(self, default_mapping=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion deepdiff/diff_doc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ ignore_type_in_groups
1. Set ignore_string_type_changes=True.
2. Or set ignore_type_in_groups=[(str, bytes)]. Here you are saying if we detect one type to be str and the other one bytes, do not report them as type change. It is exactly as passing ignore_type_in_groups=[DeepDiff.strings] or ignore_type_in_groups=DeepDiff.strings .

Now what if you want also typeA and typeB to be ignored when comparing agains each other?
Now what if you want also typeA and typeB to be ignored when comparing against each other?

1. ignore_type_in_groups=[DeepDiff.strings, (typeA, typeB)]
2. or ignore_type_in_groups=[(str, bytes), (typeA, typeB)]
Expand Down
12 changes: 5 additions & 7 deletions deepdiff/helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import sys
import datetime
import re
Expand All @@ -10,12 +9,11 @@

logger = logging.getLogger(__name__)

py_major_version = sys.version[0]
py_minor_version = sys.version[2]
py_major_version = sys.version_info.major

py2 = py_major_version == '2'
py3 = py_major_version == '3'
py4 = py_major_version == '4'
py2 = py_major_version == 2
py3 = py_major_version == 3
py4 = py_major_version == 4

if py4:
logger.warning('Python 4 is not supported yet. Switching logic to Python 3.') # pragma: no cover
Expand Down Expand Up @@ -166,7 +164,7 @@ def add_to_frozen_set(parents_ids, item_id):
def convert_item_or_items_into_set_else_none(items):
if items:
if isinstance(items, strings):
items = set([items])
items = {items}
else:
items = set(items)
else:
Expand Down
12 changes: 5 additions & 7 deletions deepdiff/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from deepdiff.helper import RemapDict, strings, short_repr, Verbose, notpresent
from ast import literal_eval
from copy import copy
Expand Down Expand Up @@ -156,7 +154,7 @@ def _from_tree_value_changed(self, tree):
def _from_tree_unprocessed(self, tree):
if 'unprocessed' in tree:
for change in tree['unprocessed']:
self['unprocessed'].append("%s: %s and %s" % (change.path(
self['unprocessed'].append("{}: {} and {}".format(change.path(
force=FORCE_DEFAULT), change.t1, change.t2))

def _from_tree_set_item_removed(self, tree):
Expand All @@ -167,7 +165,7 @@ def _from_tree_set_item_removed(self, tree):
item = change.t1
if isinstance(item, strings):
item = "'%s'" % item
self['set_item_removed'].add("%s[%s]" % (path, str(item)))
self['set_item_removed'].add("{}[{}]".format(path, str(item)))
# this syntax is rather peculiar, but it's DeepDiff 2.x compatible

def _from_tree_set_item_added(self, tree):
Expand All @@ -178,7 +176,7 @@ def _from_tree_set_item_added(self, tree):
item = change.t2
if isinstance(item, strings):
item = "'%s'" % item
self['set_item_added'].add("%s[%s]" % (path, str(item)))
self['set_item_added'].add("{}[{}]".format(path, str(item)))
# this syntax is rather peculiar, but it's DeepDiff 2.x compatible)

def _from_tree_repetition_change(self, tree):
Expand All @@ -190,7 +188,7 @@ def _from_tree_repetition_change(self, tree):
self['repetition_change'][path]['value'] = change.t1


class DiffLevel(object):
class DiffLevel:
"""
An object of this class represents a single object-tree-level in a reported change.
A double-linked list of these object describes a single change on all of its levels.
Expand Down Expand Up @@ -523,7 +521,7 @@ def copy(self):
return result


class ChildRelationship(object):
class ChildRelationship:
"""
Describes the relationship between a container object (the "parent") and the contained
"child" object.
Expand Down
3 changes: 1 addition & 2 deletions deepdiff/search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
from collections.abc import MutableMapping, Iterable
import logging
Expand Down Expand Up @@ -225,7 +224,7 @@ def __search_iterable(self,
"""Search iterables except dictionaries, sets and strings."""

for i, thing in enumerate(obj):
new_parent = "%s[%s]" % (parent, i)
new_parent = "{}[{}]".format(parent, i)
if self.__skip_this(thing, parent=new_parent):
continue

Expand Down
5 changes: 2 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# DeepDiff documentation build configuration file, created by
# sphinx-quickstart on Mon Jul 20 06:06:44 2015.
Expand Down Expand Up @@ -60,9 +59,9 @@
# built documents.
#
# The short X.Y version.
version = '4.0.9'
version = '4.2.0'
# The full version, including alpha/beta/rc tags.
release = '4.0.9'
release = '4.2.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
4 changes: 3 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
contain the root `toctree` directive.
DeepDiff 4.0.9 documentation!
DeepDiff 4.2.0 documentation!
=============================

**DeepDiff: Deep Difference of dictionaries, iterables, strings and other objects. It will recursively look for all the changes.**
Expand Down Expand Up @@ -281,6 +281,8 @@ Indices and tables
Changelog
=========

- v4-2-0: .json property is finally removed. Fix for Py3.10. Dropping support for EOL Python 3.4. Ignoring private keys when calculating hashes. For example __init__ is not a part of hash calculation anymore. Fix for #166 Problem with comparing lists, with an boolean as element.
- v4-1-0: .json property is finally removed.
- 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
Expand Down
11 changes: 6 additions & 5 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
-r requirements.txt
pytest==4.3.1
pytest-cov==2.6.1
numpy==1.16.2
bump2version==0.5.11
jsonpickle==1.2
ipdb==0.12.3
mmh3==2.5.1
ipdb==0.11
bump2version==0.5.10
numpy==1.18.1
pytest==5.3.2
pytest-cov==2.8.1
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
jsonpickle==1.0
ordered-set==3.1.1
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 4.0.9
current_version = 4.2.0
commit = True
tag = True
tag_name = {new_version}
Expand Down
Loading

0 comments on commit c2bd1f1

Please # to comment.