Repository: python-attrs/attrs (python)

Issue:
Couldn't use numpy arrays as defaults on attrs 19.2
The following code stops working when upgrading from attrs 19.1 to 19.2:

```
@attr.s(auto_attribs=True)
class NumParams:
    N = 3
    alpha = np.zeros((N, Ng))
```

Seems that change #556 requires that default attributes should implement `__eq__`, which is not the case for numpy arrays.

Taceback is:
```
    @attr.s(auto_attribs=True)
../../../../miniconda/envs/attests/lib/python3.6/site-packages/attr/_make.py:1010: in wrap
    return builder.build_class()
../../../../miniconda/envs/attests/lib/python3.6/site-packages/attr/_make.py:498: in build_class
    return self._patch_original_class()
../../../../miniconda/envs/attests/lib/python3.6/site-packages/attr/_make.py:512: in _patch_original_class
    and getattr(cls, name, _sentinel) != _sentinel
E   ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
```

Pull request description:
Fix default values that are not comparable with '=='
Fix #585



Patch:
diff --git a/changelog.d/585.change.rst b/changelog.d/585.change.rst
new file mode 100644
index 0000000..1b31403
--- /dev/null
+++ b/changelog.d/585.change.rst
@@ -0,0 +1,1 @@
+Fixed ``auto_attribs`` usage when default values cannot be compared directly with ``==``, such as ``numpy`` arrays.
diff --git a/src/attr/_make.py b/src/attr/_make.py
index 0ddca6a..46f9c54 100644
--- a/src/attr/_make.py
+++ b/src/attr/_make.py
@@ -509,7 +509,7 @@ class _ClassBuilder(object):
             for name in self._attr_names:
                 if (
                     name not in base_names
-                    and getattr(cls, name, _sentinel) != _sentinel
+                    and getattr(cls, name, _sentinel) is not _sentinel
                 ):
                     try:
                         delattr(cls, name)


Test patch:
diff --git a/tests/test_annotations.py b/tests/test_annotations.py
index 1f23f1d..43b4d0f 100644
--- a/tests/test_annotations.py
+++ b/tests/test_annotations.py
@@ -282,3 +282,18 @@ class TestAnnotations:
 
         with pytest.raises(AttributeError):
             C.y
+
+    def test_non_comparable_defaults(self):
+        """
+        Regression test for #585: objects that are not directly comparable
+        (for example numpy arrays) would cause a crash when used as
+        default values of an attrs auto-attrib class.
+        """
+
+        class NonComparable:
+            def __eq__(self, other):
+                raise ValueError
+
+        @attr.s(auto_attribs=True)
+        class C:
+            x: typing.Any = NonComparable()