GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fixing tests across python versions. · benthomasson/deepdiff@569baa4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • deepdiff
    • anyset.py
    • deephash.py
    • delta.py
    • diff.py
    • distance.py
    • helper.py
    • lfucache.py
    • model.py
    • search.py
  • tests
    • test_delta.py
    • test_serialization.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎deepdiff/anyset.py‎

Copy file name to clipboardExpand all lines: deepdiff/anyset.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from ordered_set import OrderedSet
22
from deepdiff.deephash import DeepHash
3+
from deepdiff.helper import dict_
34

45

56
class AnySet:
@@ -11,8 +12,8 @@ class AnySet:
1112
"""
1213
def __init__(self, items=None):
1314
self._set = OrderedSet()
14-
self._hashes = {}
15-
self._hash_to_objects = {}
15+
self._hashes = dict_()
16+
self._hash_to_objects = dict_()
1617
if items:
1718
for item in items:
1819
self.add(item)
Collapse file

‎deepdiff/deephash.py‎

Copy file name to clipboardExpand all lines: deepdiff/deephash.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
convert_item_or_items_into_compiled_regexes_else_none,
1010
get_id, type_is_subclass_of_type_group, type_in_type_group,
1111
number_to_string, datetime_normalize, KEY_TO_VAL_STR, short_repr,
12-
get_truncate_datetime, )
12+
get_truncate_datetime, dict_)
1313
from deepdiff.base import Base
1414
logger = logging.getLogger(__name__)
1515

@@ -22,7 +22,7 @@
2222
MURMUR_SEED = 1203
2323

2424
RESERVED_DICT_KEYS = {UNPROCESSED_KEY}
25-
EMPTY_FROZENSET = frozenset({})
25+
EMPTY_FROZENSET = frozenset()
2626

2727
INDEX_VS_ATTRIBUTE = ('[%s]', '.%s')
2828

@@ -146,7 +146,7 @@ def __init__(self,
146146
elif isinstance(hashes, DeepHash):
147147
self.hashes = hashes.hashes
148148
else:
149-
self.hashes = {}
149+
self.hashes = dict_()
150150
exclude_types = set() if exclude_types is None else set(exclude_types)
151151
self.exclude_types_tuple = tuple(exclude_types) # we need tuple for checking isinstance
152152
self.ignore_repetition = ignore_repetition
@@ -256,7 +256,7 @@ def _get_objects_to_hashes_dict(self, extract_index=0):
256256
or a dictionary of objects to the count of items that went to build them.
257257
extract_index=0 for hashes and extract_index=1 for counts.
258258
"""
259-
result = {}
259+
result = dict_()
260260
for key, value in self.hashes.items():
261261
if key in RESERVED_DICT_KEYS:
262262
result[key] = value
Collapse file

‎deepdiff/delta.py‎

Copy file name to clipboardExpand all lines: deepdiff/delta.py
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from deepdiff.helper import (
77
DICT_IS_SORTED, MINIMUM_PY_DICT_TYPE_SORTED, strings, short_repr, numbers,
88
np_ndarray, np_array_factory, numpy_dtypes,
9-
not_found, numpy_dtype_string_to_type)
9+
not_found, numpy_dtype_string_to_type, dict_)
1010
from deepdiff.path import _path_to_elements, _get_nested_obj, GET, GETATTR
1111
from deepdiff.anyset import AnySet
1212

@@ -140,7 +140,7 @@ def __repr__(self):
140140
return "<Delta: {}>".format(short_repr(self.diff, max_length=100))
141141

142142
def reset(self):
143-
self.post_process_paths_to_convert = {}
143+
self.post_process_paths_to_convert = dict_()
144144

145145
def __add__(self, other):
146146
if isinstance(other, numbers) and self._numpy_paths:
@@ -332,7 +332,7 @@ def _do_post_process(self):
332332

333333
def _do_pre_process(self):
334334
if self._numpy_paths and ('iterable_item_added' in self.diff or 'iterable_item_removed' in self.diff):
335-
preprocess_paths = {}
335+
preprocess_paths = dict_()
336336
for path, type_ in self._numpy_paths.items():
337337
preprocess_paths[path] = {'old_type': np_ndarray, 'new_type': list}
338338
try:
@@ -497,8 +497,8 @@ def _do_ignore_order(self):
497497
}
498498
499499
"""
500-
fixed_indexes = self.diff.get('iterable_items_added_at_indexes', {})
501-
remove_indexes = self.diff.get('iterable_items_removed_at_indexes', {})
500+
fixed_indexes = self.diff.get('iterable_items_added_at_indexes', dict_())
501+
remove_indexes = self.diff.get('iterable_items_removed_at_indexes', dict_())
502502
paths = set(fixed_indexes.keys()) | set(remove_indexes.keys())
503503
for path in paths:
504504
# In the case of ignore_order reports, we are pointing to the container object.
@@ -509,8 +509,8 @@ def _do_ignore_order(self):
509509
else:
510510
continue # pragma: no cover. Due to cPython peephole optimizer, this line doesn't get covered. https://github.com/nedbat/coveragepy/issues/198
511511
# copying both these dictionaries since we don't want to mutate them.
512-
fixed_indexes_per_path = fixed_indexes.get(path, {}).copy()
513-
remove_indexes_per_path = remove_indexes.get(path, {}).copy()
512+
fixed_indexes_per_path = fixed_indexes.get(path, dict_()).copy()
513+
remove_indexes_per_path = remove_indexes.get(path, dict_()).copy()
514514
fixed_indexes_values = AnySet(fixed_indexes_per_path.values())
515515

516516
new_obj = []
Collapse file

‎deepdiff/diff.py‎

Copy file name to clipboardExpand all lines: deepdiff/diff.py
+14-13Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
number_to_string, datetime_normalize, KEY_TO_VAL_STR, booleans,
2121
np_ndarray, get_numpy_ndarray_rows, OrderedSetPlus, RepeatedTimer,
2222
skipped, TEXT_VIEW, TREE_VIEW, DELTA_VIEW,
23-
np, get_truncate_datetime)
23+
np, get_truncate_datetime, dict_)
2424
from deepdiff.serialization import SerializationMixin
2525
from deepdiff.distance import DistanceMixin
2626
from deepdiff.model import (
@@ -133,6 +133,7 @@ def __init__(self,
133133
_numpy_paths=None,
134134
_original_type=None,
135135
**kwargs):
136+
super().__init__()
136137
if kwargs:
137138
raise ValueError((
138139
"The following parameter(s) are not valid: %s\n"
@@ -145,7 +146,7 @@ def __init__(self,
145146
"_numpy_paths, _original_type, parameters and shared_parameters.") % ', '.join(kwargs.keys()))
146147

147148
if parameters:
148-
self.__dict__ = deepcopy(parameters)
149+
self.__dict__.update(deepcopy(parameters))
149150
else:
150151
self.ignore_order = ignore_order
151152
ignore_type_in_groups = ignore_type_in_groups or []
@@ -220,8 +221,8 @@ def __init__(self,
220221
MAX_PASS_LIMIT_REACHED: False,
221222
MAX_DIFF_LIMIT_REACHED: False,
222223
}
223-
self.hashes = {} if hashes is None else hashes
224-
self._numpy_paths = {} if _numpy_paths is None else _numpy_paths
224+
self.hashes = dict_() if hashes is None else hashes
225+
self._numpy_paths = dict_() if _numpy_paths is None else _numpy_paths
225226
self.shared_parameters = {
226227
'hashes': self.hashes,
227228
'_stats': self._stats,
@@ -323,7 +324,7 @@ def unmangle(attribute):
323324

324325
return {i: getattr(object, unmangle(i)) for i in all_slots}
325326

326-
def __diff_obj(self, level, parents_ids=frozenset({}),
327+
def __diff_obj(self, level, parents_ids=frozenset(),
327328
is_namedtuple=False):
328329
"""Difference of 2 objects"""
329330
try:
@@ -376,7 +377,7 @@ def __get_clean_to_keys_mapping(self, keys, level):
376377
377378
TODO: needs also some key conversion for groups of types other than the built-in strings and numbers.
378379
"""
379-
result = {}
380+
result = dict_()
380381
for key in keys:
381382
if self.ignore_string_type_changes and isinstance(key, bytes):
382383
clean_key = key.decode('utf-8')
@@ -523,14 +524,14 @@ def __iterables_subscriptable(t1, t2):
523524
except AttributeError:
524525
return False
525526

526-
def __diff_iterable(self, level, parents_ids=frozenset({}), _original_type=None):
527+
def __diff_iterable(self, level, parents_ids=frozenset(), _original_type=None):
527528
"""Difference of iterables"""
528529
if self.ignore_order:
529530
self.__diff_iterable_with_deephash(level, parents_ids, _original_type=_original_type)
530531
else:
531532
self.__diff_iterable_in_order(level, parents_ids, _original_type=_original_type)
532533

533-
def __diff_iterable_in_order(self, level, parents_ids=frozenset({}), _original_type=None):
534+
def __diff_iterable_in_order(self, level, parents_ids=frozenset(), _original_type=None):
534535
# We're handling both subscriptable and non-subscriptable iterables. Which one is it?
535536
subscriptable = self.__iterables_subscriptable(level.t1, level.t2)
536537
if subscriptable:
@@ -636,7 +637,7 @@ def __create_hashtable(self, level, t):
636637
"""Create hashtable of {item_hash: (indexes, item)}"""
637638
obj = getattr(level, t)
638639

639-
local_hashes = {}
640+
local_hashes = dict_()
640641
for (i, item) in enumerate(obj):
641642
try:
642643
parent = "{}[{}]".format(level.path(), i)
@@ -745,7 +746,7 @@ def __get_most_in_common_pairs_in_iterables(
745746
# It also includes a "max" key that is just the value of the biggest current distance in the
746747
# most_in_common_pairs dictionary.
747748
most_in_common_pairs = defaultdict(lambda: defaultdict(OrderedSetPlus))
748-
pairs = {}
749+
pairs = dict_()
749750

750751
pre_calced_distances = None
751752

@@ -848,7 +849,7 @@ def __diff_iterable_with_deephash(self, level, parents_ids, _original_type=None)
848849
if not self._stats[MAX_PASS_LIMIT_REACHED]:
849850
self._stats[MAX_PASS_LIMIT_REACHED] = True
850851
logger.warning(MAX_PASSES_REACHED_MSG.format(self.max_passes))
851-
pairs = {}
852+
pairs = dict_()
852853

853854
def get_other_pair(hash_value, in_t1=True):
854855
"""
@@ -1014,7 +1015,7 @@ def __diff_datetimes(self, level):
10141015
if level.t1 != level.t2:
10151016
self.__report_result('values_changed', level)
10161017

1017-
def __diff_numpy_array(self, level, parents_ids=frozenset({})):
1018+
def __diff_numpy_array(self, level, parents_ids=frozenset()):
10181019
"""Diff numpy arrays"""
10191020
if level.path() not in self._numpy_paths:
10201021
self._numpy_paths[level.path()] = get_type(level.t2).__name__
@@ -1092,7 +1093,7 @@ def __count_diff(self):
10921093
return StopIteration
10931094
self._stats[DIFF_COUNT] += 1
10941095

1095-
def __diff(self, level, parents_ids=frozenset({}), _original_type=None):
1096+
def __diff(self, level, parents_ids=frozenset(), _original_type=None):
10961097
"""The main diff method"""
10971098
if self.__count_diff() is StopIteration:
10981099
return
Collapse file

‎deepdiff/distance.py‎

Copy file name to clipboardExpand all lines: deepdiff/distance.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from deepdiff.deephash import DeepHash
33
from deepdiff.helper import (
44
DELTA_VIEW, numbers, strings, add_to_frozen_set, not_found, only_numbers, np, np_float64, time_to_seconds,
5-
cartesian_product_numpy, np_ndarray, np_array_factory, get_homogeneous_numpy_compatible_type_of_seq)
5+
cartesian_product_numpy, np_ndarray, np_array_factory, get_homogeneous_numpy_compatible_type_of_seq, dict_)
66
from collections.abc import Mapping, Iterable
77

88

@@ -79,7 +79,7 @@ def _precalculate_numpy_arrays_distance(
7979
if isinstance(t2_hashtable[hashes_added[0]].item, (np_ndarray, list)):
8080
return
8181

82-
pre_calced_distances = {}
82+
pre_calced_distances = dict_()
8383
added = [t2_hashtable[k].item for k in hashes_added]
8484
removed = [t1_hashtable[k].item for k in hashes_removed]
8585

@@ -121,10 +121,10 @@ def _get_item_length(item, parents_ids=frozenset([])):
121121
for key, subitem in item.items():
122122
# dedupe the repetition report so the number of times items have shown up does not affect the distance.
123123
if key in {'iterable_items_added_at_indexes', 'iterable_items_removed_at_indexes'}:
124-
new_subitem = {}
124+
new_subitem = dict_()
125125
for path_, indexes_to_items in subitem.items():
126126
used_value_ids = set()
127-
new_indexes_to_items = {}
127+
new_indexes_to_items = dict_()
128128
for k, v in indexes_to_items.items():
129129
v_id = id(v)
130130
if v_id not in used_value_ids:
Collapse file

‎deepdiff/helper.py‎

Copy file name to clipboardExpand all lines: deepdiff/helper.py
+23-3Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import time
88
from ast import literal_eval
99
from decimal import Decimal, localcontext
10-
from collections import namedtuple
10+
from collections import namedtuple, OrderedDict
1111
from itertools import repeat
1212
from ordered_set import OrderedSet
1313
from threading import Timer
@@ -88,6 +88,25 @@ class np_type:
8888
MINIMUM_PY_DICT_TYPE_SORTED = Decimal('3.6')
8989
DICT_IS_SORTED = py_current_version >= MINIMUM_PY_DICT_TYPE_SORTED
9090

91+
92+
class OrderedDictPlus(OrderedDict):
93+
94+
def __repr__(self):
95+
return str(dict(self))
96+
97+
def copy(self):
98+
result = OrderedDict()
99+
for k, v in self.items():
100+
result[k] = v
101+
return result
102+
103+
104+
if DICT_IS_SORTED:
105+
dict_ = dict
106+
else:
107+
dict_ = OrderedDictPlus
108+
109+
91110
if py4:
92111
logger.warning('Python 4 is not supported yet. Switching logic to Python 3.') # pragma: no cover
93112
py3 = True # pragma: no cover
@@ -96,6 +115,7 @@ class np_type:
96115
sys.exit('Python 2 is not supported anymore. The last version of DeepDiff that supported Py2 was 3.3.0')
97116

98117
pypy3 = py3 and hasattr(sys, "pypy_translation_info")
118+
PY_3_5 = py_current_version == Decimal('3.5')
99119

100120
strings = (str, bytes) # which are both basestring
101121
unicode_type = str
@@ -172,10 +192,10 @@ def __repr__(self):
172192

173193

174194
# Disabling remapping from old to new keys since the mapping is deprecated.
175-
RemapDict = dict
195+
RemapDict = dict_
176196

177197

178-
# class RemapDict(dict):
198+
# class RemapDict(dict_):
179199
# """
180200
# DISABLED
181201
# Remap Dictionary.
Collapse file

‎deepdiff/lfucache.py‎

Copy file name to clipboardExpand all lines: deepdiff/lfucache.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from collections import defaultdict
88
from ordered_set import OrderedSet
99
from threading import Lock
10-
from deepdiff.helper import not_found
10+
from deepdiff.helper import not_found, dict_
1111

1212

1313
class CacheNode:
@@ -113,7 +113,7 @@ def insert_before_me(self, freq_node):
113113
class LFUCache:
114114

115115
def __init__(self, capacity):
116-
self.cache = {} # {key: cache_node}
116+
self.cache = dict_() # {key: cache_node}
117117
if capacity <= 0:
118118
raise ValueError('Capacity of LFUCache needs to be positive.') # pragma: no cover.
119119
self.capacity = capacity

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.