diff options
author | Donghee Na <donghee.na@python.org> | 2023-12-20 12:52:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-20 12:52:12 (GMT) |
commit | 57b7e52790ae56309832497a1ce17e3e731b920e (patch) | |
tree | 28fd9c7dcac2b8cdfd9497c950c4e8043b755b5f /Lib/test | |
parent | 5a7cc667f816f0377f763322c2367301ea3379ee (diff) | |
download | cpython-57b7e52790ae56309832497a1ce17e3e731b920e.zip cpython-57b7e52790ae56309832497a1ce17e3e731b920e.tar.gz cpython-57b7e52790ae56309832497a1ce17e3e731b920e.tar.bz2 |
gh-112205: Support docstring for `@getter` (#113160)
---------
Co-authored-by: Erlend E. Aasland <erlend@python.org>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/clinic.test.c | 20 | ||||
-rw-r--r-- | Lib/test/test_clinic.py | 15 |
2 files changed, 30 insertions, 5 deletions
diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c index a6a2166..b15aeb8 100644 --- a/Lib/test/clinic.test.c +++ b/Lib/test/clinic.test.c @@ -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 * @@ -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 @@ -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 diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index 6c6bd4e..714fa6d 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -2221,6 +2221,21 @@ class ClinicParserTest(TestCase): 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: |