Repository: python-attrs/attrs (python)

Issue:
@attr.define fails to auto-detect __eq__
`@attr.define` is failing to auto-detect `__eq__`. My understanding from the docs is that this _should_ work, but `ValueError` is not being raised unless I use `@attr.define(eq=False)`.

```python
import attr

@attr.define
class Treatment:
    treatment: str

    def __eq__(self, other):
        raise ValueError


assert Treatment("foo") == "foo"
```

```console
$ pytest t.py
================================ test session starts ================================
platform darwin -- Python 3.8.5, pytest-6.0.1, py-1.8.2, pluggy-0.13.1
rootdir: /Users/andy/tmp
plugins: Faker-4.1.1
collected 0 items / 1 error                                                         

====================================== ERRORS =======================================
_______________________________ ERROR collecting t.py _______________________________
t.py:11: in <module>
    assert Treatment("foo") == "foo"
E   AssertionError: assert Treatment(treatment='foo') == 'foo'
E    +  where Treatment(treatment='foo') = <class 't.Treatment'>('foo')
============================== short test summary info ==============================
ERROR t.py - AssertionError: assert Treatment(treatment='foo') == 'foo'
!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!
```

Pull request:
Fix auto-detection of eq/ne in NG APIs
By setting eq to True by default, it forces `__eq__`/`__ne__` to be written. Setting to None fixes it.

fixes #670

Patch:
diff --git a/src/attr/_next_gen.py b/src/attr/_next_gen.py
index b0aefe3..57e8635 100644
--- a/src/attr/_next_gen.py
+++ b/src/attr/_next_gen.py
@@ -28,7 +28,7 @@ def define(
     kw_only=False,
     cache_hash=False,
     auto_exc=True,
-    eq=True,
+    eq=None,
     order=False,
     auto_detect=True,
     getstate_setstate=None,


Test patch:
diff --git a/tests/test_next_gen.py b/tests/test_next_gen.py
index e350498..a4460b1 100644
--- a/tests/test_next_gen.py
+++ b/tests/test_next_gen.py
@@ -133,3 +133,18 @@ class TestNextGen:
 
         with pytest.raises(attr.exceptions.FrozenInstanceError):
             f.x = 2
+
+    def test_auto_detect_eq(self):
+        """
+        auto_detect=True works for eq.
+
+        Regression test for #670.
+        """
+
+        @attr.define
+        class C:
+            def __eq__(self, o):
+                raise ValueError()
+
+        with pytest.raises(ValueError):
+            C() == C()