Skip to content

Commit ae9433d

Browse files
committed
updating doc strings so they match the docstring tests
1 parent 04bc582 commit ae9433d

10 files changed

Lines changed: 152 additions & 185 deletions

File tree

deepdiff/diff.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,10 +1950,10 @@ def affected_paths(self):
19501950
'dictionary_item_removed': ['root[4]'],
19511951
'iterable_item_added': {'root[3][1]': 4},
19521952
'values_changed': {'root[2]': {'new_value': 4, 'old_value': 2}}}
1953-
>>> ddiff.affected_paths
1954-
SetOrdered(['root[3][1]', 'root[4]', 'root[5]', 'root[6]', 'root[2]'])
1955-
>>> ddiff.affected_root_keys
1956-
SetOrdered([3, 4, 5, 6, 2])
1953+
>>> sorted(ddiff.affected_paths)
1954+
['root[2]', 'root[3][1]', 'root[4]', 'root[5]', 'root[6]']
1955+
>>> sorted(ddiff.affected_root_keys)
1956+
[2, 3, 4, 5, 6]
19571957
19581958
"""
19591959
result = SetOrdered()
@@ -1982,10 +1982,10 @@ def affected_root_keys(self):
19821982
'dictionary_item_removed': ['root[4]'],
19831983
'iterable_item_added': {'root[3][1]': 4},
19841984
'values_changed': {'root[2]': {'new_value': 4, 'old_value': 2}}}
1985-
>>> ddiff.affected_paths
1986-
SetOrdered(['root[3][1]', 'root[4]', 'root[5]', 'root[6]', 'root[2]'])
1987-
>>> ddiff.affected_root_keys
1988-
SetOrdered([3, 4, 5, 6, 2])
1985+
>>> sorted(ddiff.affected_paths)
1986+
['root[2]', 'root[3][1]', 'root[4]', 'root[5]', 'root[6]']
1987+
>>> sorted(ddiff.affected_root_keys)
1988+
[2, 3, 4, 5, 6]
19891989
"""
19901990
result = SetOrdered()
19911991
for key in REPORT_KEYS:

deepdiff/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class DeepSearch(Dict[str, Union[Dict[str, Any], SetOrdered, List[str]]]):
6969
>>> item = "somewhere"
7070
>>> ds = DeepSearch(obj, item, verbose_level=2)
7171
>>> print(ds)
72-
{'matched_values': {'root[3]': 'somewhere great!', 'root[0]': 'long somewhere'}}
72+
{'matched_values': {'root[0]': 'long somewhere', 'root[3]': 'somewhere great!'}}
7373
7474
Search in nested data for string
7575
>>> obj = ["something somewhere", {"long": "somewhere", "string": 2, 0: 0, "somewhere": "around"}]

docs/_templates/about.html

Lines changed: 0 additions & 57 deletions
This file was deleted.

docs/_templates/navigation.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

docs/conf.py

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -121,34 +121,29 @@
121121

122122
# The theme to use for HTML and HTML Help pages. See the documentation for
123123
# a list of builtin themes.
124-
html_theme = 'alabaster'
124+
html_theme = 'furo'
125125

126-
# Theme options are theme-specific and customize the look and feel of a theme
127-
# further. For a list of options available for each theme, see the
128-
# documentation.
129126
html_theme_options = {
130-
'description': 'Get the deep difference of any Python objects.',
131-
'show_powered_by': False,
132-
'logo': 'qluster_grey_on_white_bg_optimized.svg',
133-
'logo_name': 'Qluster DeepDiff',
134-
'analytics_id': 'UA-59104908-2',
135-
'fixed_sidebar': True,
136-
'extra_nav_links': {
137-
'Qluster (Resolve bad data before release)': 'https://getqluster.com',
138-
'Zepworks (Blog)': 'https://zepworks.com',
139-
'Github': 'https://github.com/qlustered/deepdiff'
140-
},
141-
'show_relbars': True,
142-
# 'github_repo': 'deepdiff',
143-
'anchor': '#DDD',
144-
'touch_icon': 'Qluster_square_grey_optimized.svg',
145-
'github_button': True,
146-
'github_user': 'seperman',
147-
'github_count': True,
148-
'font_family': 'Open Sans',
149-
'canonical_url': 'https://zepworks.com/deepdiff/current/',
150-
'page_width': '1024px',
151-
'body_max_width': '1024px',
127+
'footer_icons': [
128+
{
129+
'name': 'GitHub',
130+
'url': 'https://github.com/seperman/deepdiff',
131+
'html': '<svg stroke="currentColor" fill="currentColor" stroke-width="0" '
132+
'viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 '
133+
'3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-'
134+
'2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 '
135+
'1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-'
136+
'3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 '
137+
'.67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-'
138+
'.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 '
139+
'3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46'
140+
'.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path></svg>',
141+
'class': '',
142+
},
143+
],
144+
'source_repository': 'https://github.com/seperman/deepdiff',
145+
'source_branch': 'master',
146+
'source_directory': 'docs/',
152147
}
153148

154149
# Add any paths that contain custom themes here, relative to this directory.

docs/deephash_doc.rst

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ truncate_datetime: string, default = None
160160
.. note::
161161
DeepHash output is not like conventional hash functions. It is a dictionary of object IDs to their hashes. This happens because DeepHash calculates the hash of the object and any other objects found within the object in a recursive manner. If you only need the hash of the object you are passing, all you need to do is to do:
162162

163-
>>> DeepHash(obj)[obj]
163+
>>> from deepdiff import DeepHash
164+
>>> obj = {1: 2, 'a': 'b'}
165+
>>> DeepHash(obj)[obj] # doctest: +SKIP
164166

165167

166168
**Examples**
@@ -179,8 +181,7 @@ But with DeepHash:
179181

180182
>>> from deepdiff import DeepHash
181183
>>> obj = {1: 2, 'a': 'b'}
182-
>>> DeepHash(obj)
183-
{1: 234041559348429806012597903916437026784, 2: 148655924348182454950690728321917595655, 'a': 119173504597196970070553896747624927922, 'b': 4994827227437929991738076607196210252, '!>*id4488569408': 32452838416412500686422093274247968754}
184+
>>> DeepHash(obj) # doctest: +SKIP
184185

185186
So what is exactly the hash of obj in this case?
186187
DeepHash is calculating the hash of the obj and any other object that obj contains.
@@ -189,36 +190,37 @@ But with DeepHash:
189190

190191
>>> hashes = DeepHash(obj)
191192
>>> hashes[obj]
192-
34150898645750099477987229399128149852
193+
'bf5478de322aa033da36bf3bcf9f0599e13a520773f50c6eb9f2487377a7929b'
193194

194195
Which you can write as:
195196

196197
>>> hashes = DeepHash(obj)[obj]
197198

198199
At first it might seem weird why DeepHash(obj)[obj] but remember that DeepHash(obj) is a dictionary of hashes of all other objects that obj contains too.
199200

200-
The result hash is 34150898645750099477987229399128149852. If you prefer to use another hashing algorithm, you can pass it using the hasher parameter.
201+
If you prefer to use another hashing algorithm, you can pass it using the hasher parameter.
201202

202203
If you do a deep copy of the obj, it should still give you the same hash:
203204

204205
>>> from copy import deepcopy
205206
>>> obj2 = deepcopy(obj)
206207
>>> DeepHash(obj2)[obj2]
207-
34150898645750099477987229399128149852
208+
'bf5478de322aa033da36bf3bcf9f0599e13a520773f50c6eb9f2487377a7929b'
208209

209210
Note that by default DeepHash will include string type differences. So if your strings were bytes:
210211

211212
>>> obj3 = {1: 2, b'a': b'b'}
212213
>>> DeepHash(obj3)[obj3]
213-
64067525765846024488103933101621212760
214+
'71db3231177d49f78b52a356ca206e6179417b681604d00ed703a077049e3300'
214215

215216
But if you want the same hash if string types are different, set ignore_string_type_changes to True:
216217

217218
>>> DeepHash(obj3, ignore_string_type_changes=True)[obj3]
218-
34150898645750099477987229399128149852
219+
'e60c2befb84be625037c75e1e26d0bfc85a0ffc1f3cde9500f68f6eac55e5ad6'
219220

220221
ignore_numeric_type_changes is by default False too.
221222

223+
>>> from decimal import Decimal
222224
>>> obj1 = {4:10}
223225
>>> obj2 = {4.0: Decimal(10.0)}
224226
>>> DeepHash(obj1)[4] == DeepHash(obj2)[4.0]
@@ -236,10 +238,10 @@ number_format_notation: String, default = "f"
236238
ignore_string_type_changes: Boolean, default = True
237239
By setting it to True, both the string and bytes of hello return the same hash.
238240

239-
>>> DeepHash(b'hello', ignore_string_type_changes=True)
240-
{b'hello': 221860156526691709602818861774599422448}
241-
>>> DeepHash('hello', ignore_string_type_changes=True)
242-
{'hello': 221860156526691709602818861774599422448}
241+
>>> DeepHash(b'hello', ignore_string_type_changes=True)[b'hello']
242+
'2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'
243+
>>> DeepHash('hello', ignore_string_type_changes=True)['hello']
244+
'2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'
243245

244246

245247
ignore_numeric_type_changes: Boolean, default = False
@@ -248,11 +250,10 @@ ignore_numeric_type_changes: Boolean, default = False
248250
That way they both produce the same hash.
249251

250252
>>> t1 = {1: 1, 2: 2.22}
251-
>>> t2 = {1: 1.0, 2: 2.22}
252253
>>> DeepHash(t1)[1]
253-
231678797214551245419120414857003063149
254-
>>> DeepHash(t1)[1.0]
255-
231678797214551245419120414857003063149
254+
'c1800a30c736483f13615542e7096f7973631fef8ca935ee1ed9f35fb06fd44e'
255+
>>> DeepHash(t1, ignore_numeric_type_changes=True)[1] == DeepHash(t1, ignore_numeric_type_changes=True)[1.0]
256+
True
256257

257258
You can pass a list of tuples or list of lists if you have various type groups. When t1 and t2 both fall under one of these type groups, the type change will be ignored. DeepDiff already comes with 2 groups: DeepDiff.strings and DeepDiff.numbers . If you want to pass both:
258259

@@ -305,19 +306,18 @@ ignore_type_subclasses
305306
>>> obj_b = ClassB(1)
306307
>>> obj_c = ClassC(1)
307308
>>>
308-
>>> # Since these 2 objects are from 2 different classes, the hashes are different by default.
309-
... # ignore_type_in_groups is set to [(ClassB, )] which means to ignore any type conversion between
310-
... # objects of classB and itself which does not make sense but it illustrates a better point when
311-
... # ignore_type_subclasses is set to be True.
309+
>>> # By default, subclasses are considered part of the type group.
310+
... # ignore_type_in_groups=[(ClassB, )] matches ClassC too since it's a subclass.
312311
... hashes_b = DeepHash(obj_b, ignore_type_in_groups=[(ClassB, )])
313312
>>> hashes_c = DeepHash(obj_c, ignore_type_in_groups=[(ClassB, )])
314-
>>> hashes_b[obj_b] != hashes_c[obj_c]
313+
>>> hashes_b[obj_b] == hashes_c[obj_c]
315314
True
316315
>>>
317-
>>> # Hashes of these 2 objects will be the same when ignore_type_subclasses is set to True
316+
>>> # With ignore_type_subclasses=True, only exact type matches count.
317+
... # ClassC no longer matches (ClassB, ) group, so hashes differ.
318318
... hashes_b = DeepHash(obj_b, ignore_type_in_groups=[(ClassB, )], ignore_type_subclasses=True)
319319
>>> hashes_c = DeepHash(obj_c, ignore_type_in_groups=[(ClassB, )], ignore_type_subclasses=True)
320-
>>> hashes_b[obj_b] == hashes_c[obj_c]
320+
>>> hashes_b[obj_b] != hashes_c[obj_c]
321321
True
322322

323323
ignore_string_case
@@ -334,6 +334,9 @@ exclude_obj_callback
334334
A function that takes the object and its path and returns a Boolean. If True is returned, the object is excluded from the results, otherwise it is included.
335335
This is to give the user a higher level of control than one can achieve via exclude_paths, exclude_regex_paths or other means.
336336

337+
>>> def exclude_obj_callback(obj, path):
338+
... return True if isinstance(obj, str) and obj in ('x', 'y') else False
339+
...
337340
>>> dic1 = {"x": 1, "y": 2, "z": 3}
338341
>>> t1 = [dic1]
339342
>>> t1_hash = DeepHash(t1, exclude_obj_callback=exclude_obj_callback)

0 commit comments

Comments
 (0)