Skip to content

Commit 5e4f8b5

Browse files
committed
Merge branch 'master' into dev
2 parents 356c01c + e07e8bc commit 5e4f8b5

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

deepdiff/search.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ def __search_obj(self,
138138
if is_namedtuple:
139139
obj = obj._asdict()
140140
else:
141-
obj = obj.__dict__
141+
# Skip magic methods. Slightly hacky, but unless people are defining
142+
# new magic methods they want to search, it should work fine.
143+
obj = {i: getattr(obj, i) for i in dir(obj)
144+
if not (i.startswith('__') and i.endswith('__'))}
142145
except AttributeError:
143146
try:
144147
obj = {i: getattr(obj, i) for i in obj.__slots__}

tests/test_search.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,17 @@ def __eq__(self, other):
312312
obj = AlwaysEqual()
313313
item = AlwaysEqual()
314314
result = {'matched_values': {'root', 'root.some_attr'}}
315+
316+
def test_search_inherited_attributes(self):
317+
class Parent(object):
318+
a = 1
319+
320+
class Child(Parent):
321+
b = 2
322+
323+
obj = Child()
324+
item = 1
325+
result = {'matched_values': {'root.a'}}
315326
self.assertEqual(DeepSearch(obj, item, verbose_level=1), result)
316327

317328

0 commit comments

Comments
 (0)