Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-112205: Support docstring for @getter #113160

Merged
merged 12 commits into from
Dec 20, 2023
20 changes: 15 additions & 5 deletions Lib/test/clinic.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4956,11 +4956,16 @@ Test_meth_coexist_impl(TestObj *self)
Test.property
[clinic start generated code]*/

#if defined(Test_property_HAS_DOCSTR)
# define Test_property_DOCSTR Test_property__doc__
#else
# define Test_property_DOCSTR NULL
#endif
#if defined(TEST_PROPERTY_GETSETDEF)
# undef TEST_PROPERTY_GETSETDEF
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, (setter)Test_property_set, NULL},
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, (setter)Test_property_set, Test_property_DOCSTR},
#else
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, NULL, NULL},
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, NULL, Test_property_DOCSTR},
#endif

static PyObject *
Expand All @@ -4974,16 +4979,21 @@ Test_property_get(TestObj *self, void *Py_UNUSED(context))

static PyObject *
Test_property_get_impl(TestObj *self)
/*[clinic end generated code: output=af8140b692e0e2f1 input=2d92b3449fbc7d2b]*/
/*[clinic end generated code: output=27b519719d992e03 input=2d92b3449fbc7d2b]*/

/*[clinic input]
@setter
Test.property
[clinic start generated code]*/

#if defined(TEST_PROPERTY_HAS_DOCSTR)
# define Test_property_DOCSTR Test_property__doc__
#else
# define Test_property_DOCSTR NULL
#endif
#if defined(TEST_PROPERTY_GETSETDEF)
# undef TEST_PROPERTY_GETSETDEF
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, (setter)Test_property_set, NULL},
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, (setter)Test_property_set, Test_property_DOCSTR},
#else
# define TEST_PROPERTY_GETSETDEF {"property", NULL, (setter)Test_property_set, NULL},
#endif
Expand All @@ -4999,7 +5009,7 @@ Test_property_set(TestObj *self, PyObject *value, void *Py_UNUSED(context))

static int
Test_property_set_impl(TestObj *self, PyObject *value)
/*[clinic end generated code: output=f3eba6487d7550e2 input=3bc3f46a23c83a88]*/
/*[clinic end generated code: output=9797cd03c5204ddb input=3bc3f46a23c83a88]*/

/*[clinic input]
output push
Expand Down
17 changes: 16 additions & 1 deletion Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,21 @@ class Foo "" ""
expected_error = f"{annotation} method cannot define parameters"
self.expect_failure(block, expected_error)

def test_setter_docstring(self):
block = """
module foo
class Foo "" ""
@setter
Foo.property

foo

bar
[clinic start generated code]*/
"""
expected_error = "docstrings are only supported for @getter, not @setter"
self.expect_failure(block, expected_error)

def test_duplicate_getset(self):
annotations = ["@getter", "@setter"]
for annotation in annotations:
Expand Down Expand Up @@ -2250,7 +2265,7 @@ class Foo "" ""
self.expect_failure(block, expected_error, lineno=3)

def test_getset_no_class(self):
for annotation in "@getter", "@setter":
for annotation in ("@getter", "@setter"):
corona10 marked this conversation as resolved.
Show resolved Hide resolved
with self.subTest(annotation=annotation):
block = f"""
module m
Expand Down
29 changes: 22 additions & 7 deletions Modules/_io/clinic/bufferedio.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 22 additions & 7 deletions Modules/_io/clinic/stringio.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading