Repository: seperman/deepdiff

Issue:
Feature: Search for types/objects
Currently when encountering an object, `DeepSearch` examines that object's `__dict__` without testing whether the object is what's being searched for. By example:

```
>>> from deepdiff import DeepSearch
>>> from uuid import uuid4()
>>> foo = uuid4()
>>> DeepSearch({1: foo}, foo)
{}
```

This would also allow global singletons like `None` and functions to be searched for.

This seems like it'd be a fairly small change, just an `if item == obj` check at the top of `DeepSearch.__search_obj`. If you think this a good idea, I'm happy to make a PR.

Comments:

Patch:
diff --git a/AUTHORS b/AUTHORS
index 163de47..6250384 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,13 +1,15 @@
 Authors:
-    * Seperman
-    * Victor Hahn Castell @ Flexoptix
+- Seperman
+- Victor Hahn Castell @ Flexoptix
 
 Also thanks to:
-    * nfvs for Travis-CI setup script.
-    * brbsix for initial Py3 porting.
-    * 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.
-    * finnhughes for fixing __slots__
-    * moloney for Unicode vs. Bytes default
+- nfvs for Travis-CI setup script.
+- brbsix for initial Py3 porting.
+- 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.
+- finnhughes for fixing __slots__
+- moloney for Unicode vs. Bytes default
+- serv-inc for adding help(deepdiff)
+- movermeyer for updating docs
diff --git a/README.md b/README.md
index 8f5b62f..104b040 100644
--- a/README.md
+++ b/README.md
@@ -165,7 +165,7 @@ Let's say you have a huge nested object and want to see if any item with the wor
 ```py
 from deepdiff import DeepSearch
 obj = {"long": "somewhere", "string": 2, 0: 0, "somewhere": "around"}
-ds = DeepSearch(obj, item, verbose_level=2)
+ds = DeepSearch(obj, "somewhere", verbose_level=2)
 print(ds)
 ```
 
@@ -187,7 +187,7 @@ Just grep through your objects as you would in shell!
 ```py
 from deepdiff import grep
 obj = {"long": "somewhere", "string": 2, 0: 0, "somewhere": "around"}
-ds = obj | grep(item)
+ds = obj | grep("somewhere")
 print(ds)
 ```
 
@@ -788,12 +788,13 @@ I was honored to give a talk about how DeepDiff does what it does at Pycon 2016.
 And here is more info: <http://zepworks.com/blog/diff-it-to-digg-it/>
 
 
-##Documentation
+## Documentation
 
 <http://deepdiff.readthedocs.io/en/latest/>
 
-##Changelog
+## Change log
 
+- v3-2-2: Adding help(deepdiff)
 - v3-2-1: Fixing hash of None
 - v3-2-0: Adding grep for search: object | grep(item)
 - v3-1-3: Unicode vs. Bytes default fix
@@ -845,3 +846,5 @@ Also thanks to:
 - b-jazz for PEP257 cleanup, Standardize on full names, fixing line endings.
 - finnhughes for fixing __slots__
 - moloney for Unicode vs. Bytes default
+- serv-inc for adding help(deepdiff)
+- movermeyer for updating docs
diff --git a/README.txt b/README.txt
index d33f293..a5c2329 100644
--- a/README.txt
+++ b/README.txt
@@ -240,6 +240,7 @@ http://zepworks.com/blog/diff-it-to-digg-it/
 
 **Changelog**
 
+- v3-2-2: Adding help(deepdiff)
 - v3-2-1: Fixing hash of None
 - v3-2-0: Adding grep for search: object | grep(item)
 - v3-1-3: Unicode vs. Bytes default fix
@@ -291,3 +292,5 @@ Also thanks to:
 - b-jazz for PEP257 cleanup, Standardize on full names, fixing line endings.
 - finnhughes for fixing __slots__
 - moloney for Unicode vs. Bytes default
+- serv-inc for adding help(deepdiff)
+- movermeyer for updating docs
diff --git a/deepdiff/__init__.py b/deepdiff/__init__.py
index 6e608d0..95ad688 100644
--- a/deepdiff/__init__.py
+++ b/deepdiff/__init__.py
@@ -1,3 +1,4 @@
+"""This module offers the DeepDiff, DeepSearch, grep and DeepHash classes."""
 import logging
 
 if __name__ == '__main__':
diff --git a/deepdiff/search.py b/deepdiff/search.py
index 26ba882..8c826d8 100644
--- a/deepdiff/search.py
+++ b/deepdiff/search.py
@@ -127,6 +127,11 @@ class DeepSearch(dict):
                      parents_ids=frozenset({}),
                      is_namedtuple=False):
         """Search objects"""
+        found = False
+        if obj == item:
+            found = True
+            self.__report(report_key='matched_values', key=parent, value=obj)
+        
         try:
             if is_namedtuple:
                 obj = obj._asdict()
@@ -136,7 +141,9 @@ class DeepSearch(dict):
             try:
                 obj = {i: getattr(obj, i) for i in obj.__slots__}
             except AttributeError:
-                self['unprocessed'].append("%s" % parent)
+                if not found:
+                    self['unprocessed'].append("%s" % parent)
+                
                 return
 
         self.__search_dict(
diff --git a/docs/index.rst b/docs/index.rst
index 269932a..43b1a1d 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -346,6 +346,7 @@ Indices and tables
 Changelog
 =========
 
+- v3-2-2: Adding help(deepdiff)
 - v3-2-1: Fixing hash of None
 - v3-2-0: Adding grep for search: object | grep(item)
 - v3-1-3: Unicode vs. Bytes default fix


Test patch:
diff --git a/tests/test_search.py b/tests/test_search.py
index 49929c6..3f56ceb 100644
--- a/tests/test_search.py
+++ b/tests/test_search.py
@@ -15,6 +15,7 @@ To run a specific test, run this from the root of repo:
 """
 import unittest
 from deepdiff import DeepSearch, grep
+from datetime import datetime
 import logging
 logging.disable(logging.CRITICAL)
 
@@ -286,6 +287,30 @@ class DeepSearchTestCase(unittest.TestCase):
         result = {'matched_values': {'root'}}
         self.assertEqual(DeepSearch(obj, item, verbose_level=1, case_sensitive=False), result)
 
+    def test_none(self):
+        obj = item = None
+        result = {'matched_values': {'root'}}
+        self.assertEqual(DeepSearch(obj, item, verbose_level=1), result)
+
+    def test_complex_obj(self):
+        obj  = datetime(2017, 5, 4, 1, 1, 1)
+        item = datetime(2017, 5, 4, 1, 1, 1)
+        result = {'matched_values': {'root'}}
+        self.assertEqual(DeepSearch(obj, item, verbose_level=1), result)
+
+    def test_keep_searching_after_obj_match(self):
+        class AlwaysEqual:
+            def __init__(self, recurse=True):
+                if recurse:
+                    self.some_attr = AlwaysEqual(recurse=False)
+            def __eq__(self, other):
+                return True
+
+        obj = AlwaysEqual()
+        item = AlwaysEqual()
+        result = {'matched_values': {'root', 'root.some_attr'}}
+        self.assertEqual(DeepSearch(obj, item, verbose_level=1), result)
+
 
 class GrepTestCase(unittest.TestCase):