diff --git a/changelog.d/506.change.rst b/changelog.d/506.change.rst new file mode 100644 index 00000000..038b78ed --- /dev/null +++ b/changelog.d/506.change.rst @@ -0,0 +1 @@ +The documentation of generated methods is now created automatically using the method name. diff --git a/src/attr/_make.py b/src/attr/_make.py index 5f794882..ef2f43f2 100644 --- a/src/attr/_make.py +++ b/src/attr/_make.py @@ -732,6 +732,13 @@ class _ClassBuilder(object): except AttributeError: pass + try: + method.__doc__ = "Method generated by attrs for class {}.".format( + self._cls.__qualname__ + ) + except AttributeError: + pass + return method diff --git a/tests/test_make.py b/tests/test_make.py index 1aa7335d..b484207f 100644 --- a/tests/test_make.py +++ b/tests/test_make.py @@ -1630,3 +1630,35 @@ class TestDetermineEqOrder(object): "2021-06-01. Please use `eq` and `order` instead." == w.message.args[0] ) + + +class TestDocs: + @pytest.mark.parametrize( + "meth_name", + [ + "__init__", + "__repr__", + "__eq__", + "__ne__", + "__lt__", + "__le__", + "__gt__", + "__ge__", + ], + ) + def test_docs(self, meth_name): + """ + Tests the presence and correctness of the documentation + for the generated methods + """ + + @attr.s + class A(object): + pass + + if hasattr(A, "__qualname__"): + method = getattr(A, meth_name) + expected = "Method generated by attrs for class {}.".format( + A.__qualname__ + ) + assert expected == method.__doc__