added first doc stub (#506)

* added first doc stub

* fixed test

* review

* added newsfragment

* improved docs

Co-authored-by: Simone Robutti <simone.robutti@teraki.com>
This commit is contained in:
Simone Robutti 2020-03-06 13:54:27 +01:00 committed by GitHub
parent 9fcfe3479f
commit 4dea97e633
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1 @@
The documentation of generated methods is now created automatically using the method name.

View File

@ -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

View File

@ -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__