Skip to content

Commit

Permalink
pythongh-112205: Support docstring for @getter (python#113160)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Erlend E. Aasland <[email protected]>
  • Loading branch information
2 people authored and aisk committed Feb 11, 2024
1 parent 0a82d12 commit 9c75dc2
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 61 deletions.
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
15 changes: 15 additions & 0 deletions 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
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

0 comments on commit 9c75dc2

Please sign in to comment.