Skip to content

Commit 9c75dc2

Browse files
corona10erlend-aasland
authored andcommitted
pythongh-112205: Support docstring for @getter (python#113160)
--------- Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent 0a82d12 commit 9c75dc2

File tree

7 files changed

+265
-61
lines changed

7 files changed

+265
-61
lines changed

Lib/test/clinic.test.c

+15-5
Original file line numberDiff line numberDiff line change
@@ -4956,11 +4956,16 @@ Test_meth_coexist_impl(TestObj *self)
49564956
Test.property
49574957
[clinic start generated code]*/
49584958

4959+
#if defined(Test_property_HAS_DOCSTR)
4960+
# define Test_property_DOCSTR Test_property__doc__
4961+
#else
4962+
# define Test_property_DOCSTR NULL
4963+
#endif
49594964
#if defined(TEST_PROPERTY_GETSETDEF)
49604965
# undef TEST_PROPERTY_GETSETDEF
4961-
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, (setter)Test_property_set, NULL},
4966+
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, (setter)Test_property_set, Test_property_DOCSTR},
49624967
#else
4963-
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, NULL, NULL},
4968+
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, NULL, Test_property_DOCSTR},
49644969
#endif
49654970

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

49754980
static PyObject *
49764981
Test_property_get_impl(TestObj *self)
4977-
/*[clinic end generated code: output=af8140b692e0e2f1 input=2d92b3449fbc7d2b]*/
4982+
/*[clinic end generated code: output=27b519719d992e03 input=2d92b3449fbc7d2b]*/
49784983

49794984
/*[clinic input]
49804985
@setter
49814986
Test.property
49824987
[clinic start generated code]*/
49834988

4989+
#if defined(TEST_PROPERTY_HAS_DOCSTR)
4990+
# define Test_property_DOCSTR Test_property__doc__
4991+
#else
4992+
# define Test_property_DOCSTR NULL
4993+
#endif
49844994
#if defined(TEST_PROPERTY_GETSETDEF)
49854995
# undef TEST_PROPERTY_GETSETDEF
4986-
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, (setter)Test_property_set, NULL},
4996+
# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, (setter)Test_property_set, Test_property_DOCSTR},
49874997
#else
49884998
# define TEST_PROPERTY_GETSETDEF {"property", NULL, (setter)Test_property_set, NULL},
49894999
#endif
@@ -4999,7 +5009,7 @@ Test_property_set(TestObj *self, PyObject *value, void *Py_UNUSED(context))
49995009

50005010
static int
50015011
Test_property_set_impl(TestObj *self, PyObject *value)
5002-
/*[clinic end generated code: output=f3eba6487d7550e2 input=3bc3f46a23c83a88]*/
5012+
/*[clinic end generated code: output=9797cd03c5204ddb input=3bc3f46a23c83a88]*/
50035013

50045014
/*[clinic input]
50055015
output push

Lib/test/test_clinic.py

+15
Original file line numberDiff line numberDiff line change
@@ -2221,6 +2221,21 @@ class Foo "" ""
22212221
expected_error = f"{annotation} method cannot define parameters"
22222222
self.expect_failure(block, expected_error)
22232223

2224+
def test_setter_docstring(self):
2225+
block = """
2226+
module foo
2227+
class Foo "" ""
2228+
@setter
2229+
Foo.property
2230+
2231+
foo
2232+
2233+
bar
2234+
[clinic start generated code]*/
2235+
"""
2236+
expected_error = "docstrings are only supported for @getter, not @setter"
2237+
self.expect_failure(block, expected_error)
2238+
22242239
def test_duplicate_getset(self):
22252240
annotations = ["@getter", "@setter"]
22262241
for annotation in annotations:

Modules/_io/clinic/bufferedio.c.h

+22-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_io/clinic/stringio.c.h

+22-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)