Repository: seperman/deepdiff

Issue:
object with __slots__ and __weakref__ is not compared properly
If I compare two objects with __slots__, which have __weakref__ in their slots (like ipaddress objects), deepdiff tries to unmangle the __weakref__.  It should probably just ignore it, or at least not try to unmangle the name.

```
In [1]: import deepdiff
In [2]: from ipaddress import ip_address
In [3]: deepdiff.DeepDiff(ip_address('1.2.3.4'), ip_address('5.6.7.8'))
Out[3]: {'unprocessed': ['root: 1.2.3.4 and 5.6.7.8']}
```


Discussion:

Patch:
diff --git a/deepdiff/diff.py b/deepdiff/diff.py
old mode 100644
new mode 100755
index 073dccd..29017f6
--- a/deepdiff/diff.py
+++ b/deepdiff/diff.py
@@ -743,7 +743,7 @@ class DeepDiff(ResultDict):
     @staticmethod
     def __dict_from_slots(object):
         def unmangle(attribute):
-            if attribute.startswith('__'):
+            if attribute.startswith('__') and attribute != '__weakref__':
                 return '_{type}{attribute}'.format(
                     type=type(object).__name__,
                     attribute=attribute


Test patch:
diff --git a/tests/test_diff_text.py b/tests/test_diff_text.py
old mode 100644
new mode 100755
index eb84faa..5b410e9
--- a/tests/test_diff_text.py
+++ b/tests/test_diff_text.py
@@ -836,6 +836,26 @@ class DeepDiffTextTestCase(unittest.TestCase):
         diff = DeepDiff(t1, t2)
         self.assertEqual(diff, {})
 
+    def test_custom_objects_with_weakref_in_slots(self):
+        class ClassA(object):
+            __slots__ = ['a', '__weakref__']
+
+            def __init__(self, a):
+                self.a = a
+
+        t1 = ClassA(1)
+        t2 = ClassA(2)
+        diff = DeepDiff(t1, t2)
+        result = {
+            'values_changed': {
+                'root.a': {
+                    'new_value': 2,
+                    'old_value': 1
+                }
+            },
+        }
+        self.assertEqual(diff, result)
+
     def get_custom_objects_add_and_remove(self):
         class ClassA(object):
             a = 1