From e9c99499be2ebf284f2a0e9e25d4c47d5beecb31 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Fri, 15 Dec 2023 13:19:16 +0900 Subject: [PATCH 01/11] gh-112205: Support docstring for `@getter` --- Lib/test/clinic.test.c | 13 ++-- Lib/test/test_clinic.py | 15 +++++ Modules/_io/clinic/bufferedio.c.h | 23 +++++-- Modules/_io/clinic/stringio.c.h | 23 +++++-- Modules/_io/clinic/textio.c.h | 104 ++++++++++++++++++++++++++---- Modules/_io/textio.c | 58 ++++++++++------- Tools/clinic/clinic.py | 25 +++++-- 7 files changed, 202 insertions(+), 59 deletions(-) diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c index a6a21664bb82a1..bcb80781407dc0 100644 --- a/Lib/test/clinic.test.c +++ b/Lib/test/clinic.test.c @@ -4956,11 +4956,14 @@ Test_meth_coexist_impl(TestObj *self) Test.property [clinic start generated code]*/ +PyDoc_STRVAR(Test_property__doc__, +""); + #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__doc__}, #else -# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, NULL, NULL}, +# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, NULL, Test_property__doc__}, #endif static PyObject * @@ -4974,7 +4977,7 @@ 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=6066ef293041bb7f input=2d92b3449fbc7d2b]*/ /*[clinic input] @setter @@ -4983,7 +4986,7 @@ Test.property #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__doc__}, #else # define TEST_PROPERTY_GETSETDEF {"property", NULL, (setter)Test_property_set, NULL}, #endif @@ -4999,7 +5002,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=06bfbaf593f8b62b input=3bc3f46a23c83a88]*/ /*[clinic input] output push diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index d3dbde88dd82a9..bcee215126fc6a 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -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 = "@setter can not set docstring" + self.expect_failure(block, expected_error) + def test_duplicate_getset(self): annotations = ["@getter", "@setter"] for annotation in annotations: diff --git a/Modules/_io/clinic/bufferedio.c.h b/Modules/_io/clinic/bufferedio.c.h index ec46d5409a3d82..7ab5743beefde9 100644 --- a/Modules/_io/clinic/bufferedio.c.h +++ b/Modules/_io/clinic/bufferedio.c.h @@ -327,11 +327,14 @@ _io__Buffered_simple_flush(buffered *self, PyObject *Py_UNUSED(ignored)) return return_value; } +PyDoc_STRVAR(_io__Buffered_closed__doc__, +""); + #if defined(_IO__BUFFERED_CLOSED_GETSETDEF) # undef _IO__BUFFERED_CLOSED_GETSETDEF -# define _IO__BUFFERED_CLOSED_GETSETDEF {"closed", (getter)_io__Buffered_closed_get, (setter)_io__Buffered_closed_set, NULL}, +# define _IO__BUFFERED_CLOSED_GETSETDEF {"closed", (getter)_io__Buffered_closed_get, (setter)_io__Buffered_closed_set, _io__Buffered_closed__doc__}, #else -# define _IO__BUFFERED_CLOSED_GETSETDEF {"closed", (getter)_io__Buffered_closed_get, NULL, NULL}, +# define _IO__BUFFERED_CLOSED_GETSETDEF {"closed", (getter)_io__Buffered_closed_get, NULL, _io__Buffered_closed__doc__}, #endif static PyObject * @@ -464,11 +467,14 @@ _io__Buffered_writable(buffered *self, PyObject *Py_UNUSED(ignored)) return return_value; } +PyDoc_STRVAR(_io__Buffered_name__doc__, +""); + #if defined(_IO__BUFFERED_NAME_GETSETDEF) # undef _IO__BUFFERED_NAME_GETSETDEF -# define _IO__BUFFERED_NAME_GETSETDEF {"name", (getter)_io__Buffered_name_get, (setter)_io__Buffered_name_set, NULL}, +# define _IO__BUFFERED_NAME_GETSETDEF {"name", (getter)_io__Buffered_name_get, (setter)_io__Buffered_name_set, _io__Buffered_name__doc__}, #else -# define _IO__BUFFERED_NAME_GETSETDEF {"name", (getter)_io__Buffered_name_get, NULL, NULL}, +# define _IO__BUFFERED_NAME_GETSETDEF {"name", (getter)_io__Buffered_name_get, NULL, _io__Buffered_name__doc__}, #endif static PyObject * @@ -486,11 +492,14 @@ _io__Buffered_name_get(buffered *self, void *Py_UNUSED(context)) return return_value; } +PyDoc_STRVAR(_io__Buffered_mode__doc__, +""); + #if defined(_IO__BUFFERED_MODE_GETSETDEF) # undef _IO__BUFFERED_MODE_GETSETDEF -# define _IO__BUFFERED_MODE_GETSETDEF {"mode", (getter)_io__Buffered_mode_get, (setter)_io__Buffered_mode_set, NULL}, +# define _IO__BUFFERED_MODE_GETSETDEF {"mode", (getter)_io__Buffered_mode_get, (setter)_io__Buffered_mode_set, _io__Buffered_mode__doc__}, #else -# define _IO__BUFFERED_MODE_GETSETDEF {"mode", (getter)_io__Buffered_mode_get, NULL, NULL}, +# define _IO__BUFFERED_MODE_GETSETDEF {"mode", (getter)_io__Buffered_mode_get, NULL, _io__Buffered_mode__doc__}, #endif static PyObject * @@ -1230,4 +1239,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=0999c33f666dc692 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c8f5c48e1c48010d input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/stringio.c.h b/Modules/_io/clinic/stringio.c.h index fc2962d1c9c9a7..1c1088de75d60f 100644 --- a/Modules/_io/clinic/stringio.c.h +++ b/Modules/_io/clinic/stringio.c.h @@ -475,11 +475,14 @@ _io_StringIO___setstate__(stringio *self, PyObject *state) return return_value; } +PyDoc_STRVAR(_io_StringIO_closed__doc__, +""); + #if defined(_IO_STRINGIO_CLOSED_GETSETDEF) # undef _IO_STRINGIO_CLOSED_GETSETDEF -# define _IO_STRINGIO_CLOSED_GETSETDEF {"closed", (getter)_io_StringIO_closed_get, (setter)_io_StringIO_closed_set, NULL}, +# define _IO_STRINGIO_CLOSED_GETSETDEF {"closed", (getter)_io_StringIO_closed_get, (setter)_io_StringIO_closed_set, _io_StringIO_closed__doc__}, #else -# define _IO_STRINGIO_CLOSED_GETSETDEF {"closed", (getter)_io_StringIO_closed_get, NULL, NULL}, +# define _IO_STRINGIO_CLOSED_GETSETDEF {"closed", (getter)_io_StringIO_closed_get, NULL, _io_StringIO_closed__doc__}, #endif static PyObject * @@ -497,11 +500,14 @@ _io_StringIO_closed_get(stringio *self, void *Py_UNUSED(context)) return return_value; } +PyDoc_STRVAR(_io_StringIO_line_buffering__doc__, +""); + #if defined(_IO_STRINGIO_LINE_BUFFERING_GETSETDEF) # undef _IO_STRINGIO_LINE_BUFFERING_GETSETDEF -# define _IO_STRINGIO_LINE_BUFFERING_GETSETDEF {"line_buffering", (getter)_io_StringIO_line_buffering_get, (setter)_io_StringIO_line_buffering_set, NULL}, +# define _IO_STRINGIO_LINE_BUFFERING_GETSETDEF {"line_buffering", (getter)_io_StringIO_line_buffering_get, (setter)_io_StringIO_line_buffering_set, _io_StringIO_line_buffering__doc__}, #else -# define _IO_STRINGIO_LINE_BUFFERING_GETSETDEF {"line_buffering", (getter)_io_StringIO_line_buffering_get, NULL, NULL}, +# define _IO_STRINGIO_LINE_BUFFERING_GETSETDEF {"line_buffering", (getter)_io_StringIO_line_buffering_get, NULL, _io_StringIO_line_buffering__doc__}, #endif static PyObject * @@ -519,11 +525,14 @@ _io_StringIO_line_buffering_get(stringio *self, void *Py_UNUSED(context)) return return_value; } +PyDoc_STRVAR(_io_StringIO_newlines__doc__, +""); + #if defined(_IO_STRINGIO_NEWLINES_GETSETDEF) # undef _IO_STRINGIO_NEWLINES_GETSETDEF -# define _IO_STRINGIO_NEWLINES_GETSETDEF {"newlines", (getter)_io_StringIO_newlines_get, (setter)_io_StringIO_newlines_set, NULL}, +# define _IO_STRINGIO_NEWLINES_GETSETDEF {"newlines", (getter)_io_StringIO_newlines_get, (setter)_io_StringIO_newlines_set, _io_StringIO_newlines__doc__}, #else -# define _IO_STRINGIO_NEWLINES_GETSETDEF {"newlines", (getter)_io_StringIO_newlines_get, NULL, NULL}, +# define _IO_STRINGIO_NEWLINES_GETSETDEF {"newlines", (getter)_io_StringIO_newlines_get, NULL, _io_StringIO_newlines__doc__}, #endif static PyObject * @@ -540,4 +549,4 @@ _io_StringIO_newlines_get(stringio *self, void *Py_UNUSED(context)) return return_value; } -/*[clinic end generated code: output=27726751d98ab617 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=9515b0d4411f7390 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index f24f65f0c1d4f9..bbc8858881391f 100644 --- a/Modules/_io/clinic/textio.c.h +++ b/Modules/_io/clinic/textio.c.h @@ -201,6 +201,71 @@ _io__TextIOBase_write(PyObject *self, PyTypeObject *cls, PyObject *const *args, return return_value; } +PyDoc_STRVAR(_io__TextIOBase_encoding__doc__, +"Encoding of the text stream.\n" +"\n" +"Subclasses should override."); + +#if defined(_IO__TEXTIOBASE_ENCODING_GETSETDEF) +# undef _IO__TEXTIOBASE_ENCODING_GETSETDEF +# define _IO__TEXTIOBASE_ENCODING_GETSETDEF {"encoding", (getter)_io__TextIOBase_encoding_get, (setter)_io__TextIOBase_encoding_set, _io__TextIOBase_encoding__doc__}, +#else +# define _IO__TEXTIOBASE_ENCODING_GETSETDEF {"encoding", (getter)_io__TextIOBase_encoding_get, NULL, _io__TextIOBase_encoding__doc__}, +#endif + +static PyObject * +_io__TextIOBase_encoding_get_impl(PyObject *self); + +static PyObject * +_io__TextIOBase_encoding_get(PyObject *self, void *Py_UNUSED(context)) +{ + return _io__TextIOBase_encoding_get_impl(self); +} + +PyDoc_STRVAR(_io__TextIOBase_newlines__doc__, +"Line endings translated so far.\n" +"\n" +"Only line endings translated during reading are considered.\n" +"\n" +"Subclasses should override."); + +#if defined(_IO__TEXTIOBASE_NEWLINES_GETSETDEF) +# undef _IO__TEXTIOBASE_NEWLINES_GETSETDEF +# define _IO__TEXTIOBASE_NEWLINES_GETSETDEF {"newlines", (getter)_io__TextIOBase_newlines_get, (setter)_io__TextIOBase_newlines_set, _io__TextIOBase_newlines__doc__}, +#else +# define _IO__TEXTIOBASE_NEWLINES_GETSETDEF {"newlines", (getter)_io__TextIOBase_newlines_get, NULL, _io__TextIOBase_newlines__doc__}, +#endif + +static PyObject * +_io__TextIOBase_newlines_get_impl(PyObject *self); + +static PyObject * +_io__TextIOBase_newlines_get(PyObject *self, void *Py_UNUSED(context)) +{ + return _io__TextIOBase_newlines_get_impl(self); +} + +PyDoc_STRVAR(_io__TextIOBase_errors__doc__, +"The error setting of the decoder or encoder.\n" +"\n" +"Subclasses should override."); + +#if defined(_IO__TEXTIOBASE_ERRORS_GETSETDEF) +# undef _IO__TEXTIOBASE_ERRORS_GETSETDEF +# define _IO__TEXTIOBASE_ERRORS_GETSETDEF {"errors", (getter)_io__TextIOBase_errors_get, (setter)_io__TextIOBase_errors_set, _io__TextIOBase_errors__doc__}, +#else +# define _IO__TEXTIOBASE_ERRORS_GETSETDEF {"errors", (getter)_io__TextIOBase_errors_get, NULL, _io__TextIOBase_errors__doc__}, +#endif + +static PyObject * +_io__TextIOBase_errors_get_impl(PyObject *self); + +static PyObject * +_io__TextIOBase_errors_get(PyObject *self, void *Py_UNUSED(context)) +{ + return _io__TextIOBase_errors_get_impl(self); +} + PyDoc_STRVAR(_io_IncrementalNewlineDecoder___init____doc__, "IncrementalNewlineDecoder(decoder, translate, errors=\'strict\')\n" "--\n" @@ -1048,11 +1113,14 @@ _io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored)) return return_value; } +PyDoc_STRVAR(_io_TextIOWrapper_name__doc__, +""); + #if defined(_IO_TEXTIOWRAPPER_NAME_GETSETDEF) # undef _IO_TEXTIOWRAPPER_NAME_GETSETDEF -# define _IO_TEXTIOWRAPPER_NAME_GETSETDEF {"name", (getter)_io_TextIOWrapper_name_get, (setter)_io_TextIOWrapper_name_set, NULL}, +# define _IO_TEXTIOWRAPPER_NAME_GETSETDEF {"name", (getter)_io_TextIOWrapper_name_get, (setter)_io_TextIOWrapper_name_set, _io_TextIOWrapper_name__doc__}, #else -# define _IO_TEXTIOWRAPPER_NAME_GETSETDEF {"name", (getter)_io_TextIOWrapper_name_get, NULL, NULL}, +# define _IO_TEXTIOWRAPPER_NAME_GETSETDEF {"name", (getter)_io_TextIOWrapper_name_get, NULL, _io_TextIOWrapper_name__doc__}, #endif static PyObject * @@ -1070,11 +1138,14 @@ _io_TextIOWrapper_name_get(textio *self, void *Py_UNUSED(context)) return return_value; } +PyDoc_STRVAR(_io_TextIOWrapper_closed__doc__, +""); + #if defined(_IO_TEXTIOWRAPPER_CLOSED_GETSETDEF) # undef _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF -# define _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF {"closed", (getter)_io_TextIOWrapper_closed_get, (setter)_io_TextIOWrapper_closed_set, NULL}, +# define _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF {"closed", (getter)_io_TextIOWrapper_closed_get, (setter)_io_TextIOWrapper_closed_set, _io_TextIOWrapper_closed__doc__}, #else -# define _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF {"closed", (getter)_io_TextIOWrapper_closed_get, NULL, NULL}, +# define _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF {"closed", (getter)_io_TextIOWrapper_closed_get, NULL, _io_TextIOWrapper_closed__doc__}, #endif static PyObject * @@ -1092,11 +1163,14 @@ _io_TextIOWrapper_closed_get(textio *self, void *Py_UNUSED(context)) return return_value; } +PyDoc_STRVAR(_io_TextIOWrapper_newlines__doc__, +""); + #if defined(_IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF) # undef _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF -# define _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF {"newlines", (getter)_io_TextIOWrapper_newlines_get, (setter)_io_TextIOWrapper_newlines_set, NULL}, +# define _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF {"newlines", (getter)_io_TextIOWrapper_newlines_get, (setter)_io_TextIOWrapper_newlines_set, _io_TextIOWrapper_newlines__doc__}, #else -# define _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF {"newlines", (getter)_io_TextIOWrapper_newlines_get, NULL, NULL}, +# define _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF {"newlines", (getter)_io_TextIOWrapper_newlines_get, NULL, _io_TextIOWrapper_newlines__doc__}, #endif static PyObject * @@ -1114,11 +1188,14 @@ _io_TextIOWrapper_newlines_get(textio *self, void *Py_UNUSED(context)) return return_value; } +PyDoc_STRVAR(_io_TextIOWrapper_errors__doc__, +""); + #if defined(_IO_TEXTIOWRAPPER_ERRORS_GETSETDEF) # undef _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF -# define _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF {"errors", (getter)_io_TextIOWrapper_errors_get, (setter)_io_TextIOWrapper_errors_set, NULL}, +# define _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF {"errors", (getter)_io_TextIOWrapper_errors_get, (setter)_io_TextIOWrapper_errors_set, _io_TextIOWrapper_errors__doc__}, #else -# define _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF {"errors", (getter)_io_TextIOWrapper_errors_get, NULL, NULL}, +# define _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF {"errors", (getter)_io_TextIOWrapper_errors_get, NULL, _io_TextIOWrapper_errors__doc__}, #endif static PyObject * @@ -1136,11 +1213,14 @@ _io_TextIOWrapper_errors_get(textio *self, void *Py_UNUSED(context)) return return_value; } +PyDoc_STRVAR(_io_TextIOWrapper__CHUNK_SIZE__doc__, +""); + #if defined(_IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF) # undef _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF -# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, NULL}, +# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, _io_TextIOWrapper__CHUNK_SIZE__doc__}, #else -# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, NULL, NULL}, +# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, NULL, _io_TextIOWrapper__CHUNK_SIZE__doc__}, #endif static PyObject * @@ -1160,7 +1240,7 @@ _io_TextIOWrapper__CHUNK_SIZE_get(textio *self, void *Py_UNUSED(context)) #if defined(_IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF) # undef _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF -# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, NULL}, +# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, _io_TextIOWrapper__CHUNK_SIZE__doc__}, #else # define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", NULL, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, NULL}, #endif @@ -1179,4 +1259,4 @@ _io_TextIOWrapper__CHUNK_SIZE_set(textio *self, PyObject *value, void *Py_UNUSED return return_value; } -/*[clinic end generated code: output=7af87bf848a5d3f3 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=58f7174c0a2c28e8 input=a9049054013a1b77]*/ diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 702336ca2aeb06..4507930c14bb50 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -131,40 +131,52 @@ _io__TextIOBase_write_impl(PyObject *self, PyTypeObject *cls, return _unsupported(state, "write"); } -PyDoc_STRVAR(textiobase_encoding_doc, - "Encoding of the text stream.\n" - "\n" - "Subclasses should override.\n" - ); +/*[clinic input] +@getter +_io._TextIOBase.encoding + +Encoding of the text stream. + +Subclasses should override. +[clinic start generated code]*/ static PyObject * -textiobase_encoding_get(PyObject *self, void *context) +_io__TextIOBase_encoding_get_impl(PyObject *self) +/*[clinic end generated code: output=e0f5d8f548b92432 input=4736d7621dd38f43]*/ { Py_RETURN_NONE; } -PyDoc_STRVAR(textiobase_newlines_doc, - "Line endings translated so far.\n" - "\n" - "Only line endings translated during reading are considered.\n" - "\n" - "Subclasses should override.\n" - ); +/*[clinic input] +@getter +_io._TextIOBase.newlines + +Line endings translated so far. + +Only line endings translated during reading are considered. + +Subclasses should override. +[clinic start generated code]*/ static PyObject * -textiobase_newlines_get(PyObject *self, void *context) +_io__TextIOBase_newlines_get_impl(PyObject *self) +/*[clinic end generated code: output=46ec147fb9f00c2a input=a5b196d076af1164]*/ { Py_RETURN_NONE; } -PyDoc_STRVAR(textiobase_errors_doc, - "The error setting of the decoder or encoder.\n" - "\n" - "Subclasses should override.\n" - ); +/*[clinic input] +@getter +_io._TextIOBase.errors + +The error setting of the decoder or encoder. + +Subclasses should override. +[clinic start generated code]*/ static PyObject * -textiobase_errors_get(PyObject *self, void *context) +_io__TextIOBase_errors_get_impl(PyObject *self) +/*[clinic end generated code: output=c6623d6addcd087d input=974aa52d1db93a82]*/ { Py_RETURN_NONE; } @@ -179,9 +191,9 @@ static PyMethodDef textiobase_methods[] = { }; static PyGetSetDef textiobase_getset[] = { - {"encoding", (getter)textiobase_encoding_get, NULL, textiobase_encoding_doc}, - {"newlines", (getter)textiobase_newlines_get, NULL, textiobase_newlines_doc}, - {"errors", (getter)textiobase_errors_get, NULL, textiobase_errors_doc}, + _IO__TEXTIOBASE_ENCODING_GETSETDEF + _IO__TEXTIOBASE_NEWLINES_GETSETDEF + _IO__TEXTIOBASE_ERRORS_GETSETDEF {NULL} }; diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index a9bf110291eadd..2e996caf2f28de 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -865,6 +865,13 @@ class CLanguage(Language): PyDoc_STRVAR({c_basename}__doc__, {docstring}); """) + GETSET_DOCSTRING_PROTOTYPE_VAR: Final[str] = normalize_snippet(""" + PyDoc_VAR({getset_basename}__doc__); + """) + GETSET_DOCSTRING_PROTOTYPE_STRVAR: Final[str] = normalize_snippet(""" + PyDoc_STRVAR({getset_basename}__doc__, + {docstring}); + """) IMPL_DEFINITION_PROTOTYPE: Final[str] = normalize_snippet(""" static {impl_return_type} {c_basename}_impl({impl_parameters}) @@ -876,15 +883,15 @@ class CLanguage(Language): GETTERDEF_PROTOTYPE_DEFINE: Final[str] = normalize_snippet(r""" #if defined({getset_name}_GETSETDEF) # undef {getset_name}_GETSETDEF - # define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, (setter){getset_basename}_set, NULL}}, + # define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, (setter){getset_basename}_set, {getset_basename}__doc__}}, #else - # define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, NULL, NULL}}, + # define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, NULL, {getset_basename}__doc__}}, #endif """) SETTERDEF_PROTOTYPE_DEFINE: Final[str] = normalize_snippet(r""" #if defined({getset_name}_GETSETDEF) # undef {getset_name}_GETSETDEF - # define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, (setter){getset_basename}_set, NULL}}, + # define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, (setter){getset_basename}_set, {getset_basename}__doc__}}, #else # define {getset_name}_GETSETDEF {{"{name}", NULL, (setter){getset_basename}_set, NULL}}, #endif @@ -1187,11 +1194,14 @@ def output_templates( docstring_prototype = docstring_definition = '' elif f.kind is GETTER: methoddef_define = self.GETTERDEF_PROTOTYPE_DEFINE - docstring_prototype = docstring_definition = '' + docstring_prototype = self.GETSET_DOCSTRING_PROTOTYPE_VAR + docstring_definition = self.GETSET_DOCSTRING_PROTOTYPE_STRVAR elif f.kind is SETTER: + if f.docstring: + fail("@setter can not set docstring") return_value_declaration = "int {return_value};" methoddef_define = self.SETTERDEF_PROTOTYPE_DEFINE - docstring_prototype = docstring_prototype = docstring_definition = '' + docstring_prototype = docstring_definition = '' else: docstring_prototype = self.DOCSTRING_PROTOTYPE_VAR docstring_definition = self.DOCSTRING_PROTOTYPE_STRVAR @@ -6251,6 +6261,8 @@ def format_docstring_signature( add(f.displayname) if self.forced_text_signature: add(self.forced_text_signature) + elif f.kind in {GETTER, SETTER}: + return '' else: add('(') @@ -6426,6 +6438,9 @@ def format_docstring(self) -> str: if f.kind.new_or_init and not f.docstring: # don't render a docstring at all, no signature, nothing. return f.docstring + if f.kind in {GETTER, SETTER} and not f.docstring: + # don't render a docstring at all, no signature, nothing. + return f.docstring # Enforce the summary line! # The first line of a docstring should be a summary of the function. From bc2ee26d5ce58fa5e42f5e165469509b3dbabc31 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 16 Dec 2023 00:15:29 +0900 Subject: [PATCH 02/11] Resolve regression --- Lib/test/clinic.test.c | 23 ++++--- Modules/_io/clinic/bufferedio.c.h | 38 +++++++----- Modules/_io/clinic/stringio.c.h | 38 +++++++----- Modules/_io/clinic/textio.c.h | 99 ++++++++++++++++++++----------- Tools/clinic/clinic.py | 24 ++++++-- 5 files changed, 144 insertions(+), 78 deletions(-) diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c index bcb80781407dc0..e7fcdafa56d02b 100644 --- a/Lib/test/clinic.test.c +++ b/Lib/test/clinic.test.c @@ -4956,14 +4956,16 @@ Test_meth_coexist_impl(TestObj *self) Test.property [clinic start generated code]*/ -PyDoc_STRVAR(Test_property__doc__, -""); - +#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, Test_property__doc__}, +# 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, Test_property__doc__}, +# define TEST_PROPERTY_GETSETDEF {"property", (getter)Test_property_get, NULL, Test_property_DOCSTR}, #endif static PyObject * @@ -4977,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=6066ef293041bb7f input=2d92b3449fbc7d2b]*/ +/*[clinic end generated code: output=1bfac7190f65014a 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, Test_property__doc__}, +# 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 @@ -5002,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=06bfbaf593f8b62b input=3bc3f46a23c83a88]*/ +/*[clinic end generated code: output=44050814a89e3dc5 input=3bc3f46a23c83a88]*/ /*[clinic input] output push diff --git a/Modules/_io/clinic/bufferedio.c.h b/Modules/_io/clinic/bufferedio.c.h index 7ab5743beefde9..34f9b2e69944a6 100644 --- a/Modules/_io/clinic/bufferedio.c.h +++ b/Modules/_io/clinic/bufferedio.c.h @@ -327,14 +327,16 @@ _io__Buffered_simple_flush(buffered *self, PyObject *Py_UNUSED(ignored)) return return_value; } -PyDoc_STRVAR(_io__Buffered_closed__doc__, -""); - +#if defined(_io__Buffered_closed_HAS_DOCSTR) +# define _io__Buffered_closed_DOCSTR _io__Buffered_closed__doc__ +#else +# define _io__Buffered_closed_DOCSTR NULL +#endif #if defined(_IO__BUFFERED_CLOSED_GETSETDEF) # undef _IO__BUFFERED_CLOSED_GETSETDEF -# define _IO__BUFFERED_CLOSED_GETSETDEF {"closed", (getter)_io__Buffered_closed_get, (setter)_io__Buffered_closed_set, _io__Buffered_closed__doc__}, +# define _IO__BUFFERED_CLOSED_GETSETDEF {"closed", (getter)_io__Buffered_closed_get, (setter)_io__Buffered_closed_set, _io__Buffered_closed_DOCSTR}, #else -# define _IO__BUFFERED_CLOSED_GETSETDEF {"closed", (getter)_io__Buffered_closed_get, NULL, _io__Buffered_closed__doc__}, +# define _IO__BUFFERED_CLOSED_GETSETDEF {"closed", (getter)_io__Buffered_closed_get, NULL, _io__Buffered_closed_DOCSTR}, #endif static PyObject * @@ -467,14 +469,16 @@ _io__Buffered_writable(buffered *self, PyObject *Py_UNUSED(ignored)) return return_value; } -PyDoc_STRVAR(_io__Buffered_name__doc__, -""); - +#if defined(_io__Buffered_name_HAS_DOCSTR) +# define _io__Buffered_name_DOCSTR _io__Buffered_name__doc__ +#else +# define _io__Buffered_name_DOCSTR NULL +#endif #if defined(_IO__BUFFERED_NAME_GETSETDEF) # undef _IO__BUFFERED_NAME_GETSETDEF -# define _IO__BUFFERED_NAME_GETSETDEF {"name", (getter)_io__Buffered_name_get, (setter)_io__Buffered_name_set, _io__Buffered_name__doc__}, +# define _IO__BUFFERED_NAME_GETSETDEF {"name", (getter)_io__Buffered_name_get, (setter)_io__Buffered_name_set, _io__Buffered_name_DOCSTR}, #else -# define _IO__BUFFERED_NAME_GETSETDEF {"name", (getter)_io__Buffered_name_get, NULL, _io__Buffered_name__doc__}, +# define _IO__BUFFERED_NAME_GETSETDEF {"name", (getter)_io__Buffered_name_get, NULL, _io__Buffered_name_DOCSTR}, #endif static PyObject * @@ -492,14 +496,16 @@ _io__Buffered_name_get(buffered *self, void *Py_UNUSED(context)) return return_value; } -PyDoc_STRVAR(_io__Buffered_mode__doc__, -""); - +#if defined(_io__Buffered_mode_HAS_DOCSTR) +# define _io__Buffered_mode_DOCSTR _io__Buffered_mode__doc__ +#else +# define _io__Buffered_mode_DOCSTR NULL +#endif #if defined(_IO__BUFFERED_MODE_GETSETDEF) # undef _IO__BUFFERED_MODE_GETSETDEF -# define _IO__BUFFERED_MODE_GETSETDEF {"mode", (getter)_io__Buffered_mode_get, (setter)_io__Buffered_mode_set, _io__Buffered_mode__doc__}, +# define _IO__BUFFERED_MODE_GETSETDEF {"mode", (getter)_io__Buffered_mode_get, (setter)_io__Buffered_mode_set, _io__Buffered_mode_DOCSTR}, #else -# define _IO__BUFFERED_MODE_GETSETDEF {"mode", (getter)_io__Buffered_mode_get, NULL, _io__Buffered_mode__doc__}, +# define _IO__BUFFERED_MODE_GETSETDEF {"mode", (getter)_io__Buffered_mode_get, NULL, _io__Buffered_mode_DOCSTR}, #endif static PyObject * @@ -1239,4 +1245,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=c8f5c48e1c48010d input=a9049054013a1b77]*/ +/*[clinic end generated code: output=5a3a8dd6e473eb79 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/stringio.c.h b/Modules/_io/clinic/stringio.c.h index 1c1088de75d60f..3d6a6b70d28b44 100644 --- a/Modules/_io/clinic/stringio.c.h +++ b/Modules/_io/clinic/stringio.c.h @@ -475,14 +475,16 @@ _io_StringIO___setstate__(stringio *self, PyObject *state) return return_value; } -PyDoc_STRVAR(_io_StringIO_closed__doc__, -""); - +#if defined(_io_StringIO_closed_HAS_DOCSTR) +# define _io_StringIO_closed_DOCSTR _io_StringIO_closed__doc__ +#else +# define _io_StringIO_closed_DOCSTR NULL +#endif #if defined(_IO_STRINGIO_CLOSED_GETSETDEF) # undef _IO_STRINGIO_CLOSED_GETSETDEF -# define _IO_STRINGIO_CLOSED_GETSETDEF {"closed", (getter)_io_StringIO_closed_get, (setter)_io_StringIO_closed_set, _io_StringIO_closed__doc__}, +# define _IO_STRINGIO_CLOSED_GETSETDEF {"closed", (getter)_io_StringIO_closed_get, (setter)_io_StringIO_closed_set, _io_StringIO_closed_DOCSTR}, #else -# define _IO_STRINGIO_CLOSED_GETSETDEF {"closed", (getter)_io_StringIO_closed_get, NULL, _io_StringIO_closed__doc__}, +# define _IO_STRINGIO_CLOSED_GETSETDEF {"closed", (getter)_io_StringIO_closed_get, NULL, _io_StringIO_closed_DOCSTR}, #endif static PyObject * @@ -500,14 +502,16 @@ _io_StringIO_closed_get(stringio *self, void *Py_UNUSED(context)) return return_value; } -PyDoc_STRVAR(_io_StringIO_line_buffering__doc__, -""); - +#if defined(_io_StringIO_line_buffering_HAS_DOCSTR) +# define _io_StringIO_line_buffering_DOCSTR _io_StringIO_line_buffering__doc__ +#else +# define _io_StringIO_line_buffering_DOCSTR NULL +#endif #if defined(_IO_STRINGIO_LINE_BUFFERING_GETSETDEF) # undef _IO_STRINGIO_LINE_BUFFERING_GETSETDEF -# define _IO_STRINGIO_LINE_BUFFERING_GETSETDEF {"line_buffering", (getter)_io_StringIO_line_buffering_get, (setter)_io_StringIO_line_buffering_set, _io_StringIO_line_buffering__doc__}, +# define _IO_STRINGIO_LINE_BUFFERING_GETSETDEF {"line_buffering", (getter)_io_StringIO_line_buffering_get, (setter)_io_StringIO_line_buffering_set, _io_StringIO_line_buffering_DOCSTR}, #else -# define _IO_STRINGIO_LINE_BUFFERING_GETSETDEF {"line_buffering", (getter)_io_StringIO_line_buffering_get, NULL, _io_StringIO_line_buffering__doc__}, +# define _IO_STRINGIO_LINE_BUFFERING_GETSETDEF {"line_buffering", (getter)_io_StringIO_line_buffering_get, NULL, _io_StringIO_line_buffering_DOCSTR}, #endif static PyObject * @@ -525,14 +529,16 @@ _io_StringIO_line_buffering_get(stringio *self, void *Py_UNUSED(context)) return return_value; } -PyDoc_STRVAR(_io_StringIO_newlines__doc__, -""); - +#if defined(_io_StringIO_newlines_HAS_DOCSTR) +# define _io_StringIO_newlines_DOCSTR _io_StringIO_newlines__doc__ +#else +# define _io_StringIO_newlines_DOCSTR NULL +#endif #if defined(_IO_STRINGIO_NEWLINES_GETSETDEF) # undef _IO_STRINGIO_NEWLINES_GETSETDEF -# define _IO_STRINGIO_NEWLINES_GETSETDEF {"newlines", (getter)_io_StringIO_newlines_get, (setter)_io_StringIO_newlines_set, _io_StringIO_newlines__doc__}, +# define _IO_STRINGIO_NEWLINES_GETSETDEF {"newlines", (getter)_io_StringIO_newlines_get, (setter)_io_StringIO_newlines_set, _io_StringIO_newlines_DOCSTR}, #else -# define _IO_STRINGIO_NEWLINES_GETSETDEF {"newlines", (getter)_io_StringIO_newlines_get, NULL, _io_StringIO_newlines__doc__}, +# define _IO_STRINGIO_NEWLINES_GETSETDEF {"newlines", (getter)_io_StringIO_newlines_get, NULL, _io_StringIO_newlines_DOCSTR}, #endif static PyObject * @@ -549,4 +555,4 @@ _io_StringIO_newlines_get(stringio *self, void *Py_UNUSED(context)) return return_value; } -/*[clinic end generated code: output=9515b0d4411f7390 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=9814a7ebc7ed94af input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index bbc8858881391f..be9c820132bfa8 100644 --- a/Modules/_io/clinic/textio.c.h +++ b/Modules/_io/clinic/textio.c.h @@ -205,12 +205,18 @@ PyDoc_STRVAR(_io__TextIOBase_encoding__doc__, "Encoding of the text stream.\n" "\n" "Subclasses should override."); +#define _io__TextIOBase_encoding_HAS_DOCSTR +#if defined(_io__TextIOBase_encoding_HAS_DOCSTR) +# define _io__TextIOBase_encoding_DOCSTR _io__TextIOBase_encoding__doc__ +#else +# define _io__TextIOBase_encoding_DOCSTR NULL +#endif #if defined(_IO__TEXTIOBASE_ENCODING_GETSETDEF) # undef _IO__TEXTIOBASE_ENCODING_GETSETDEF -# define _IO__TEXTIOBASE_ENCODING_GETSETDEF {"encoding", (getter)_io__TextIOBase_encoding_get, (setter)_io__TextIOBase_encoding_set, _io__TextIOBase_encoding__doc__}, +# define _IO__TEXTIOBASE_ENCODING_GETSETDEF {"encoding", (getter)_io__TextIOBase_encoding_get, (setter)_io__TextIOBase_encoding_set, _io__TextIOBase_encoding_DOCSTR}, #else -# define _IO__TEXTIOBASE_ENCODING_GETSETDEF {"encoding", (getter)_io__TextIOBase_encoding_get, NULL, _io__TextIOBase_encoding__doc__}, +# define _IO__TEXTIOBASE_ENCODING_GETSETDEF {"encoding", (getter)_io__TextIOBase_encoding_get, NULL, _io__TextIOBase_encoding_DOCSTR}, #endif static PyObject * @@ -228,12 +234,18 @@ PyDoc_STRVAR(_io__TextIOBase_newlines__doc__, "Only line endings translated during reading are considered.\n" "\n" "Subclasses should override."); +#define _io__TextIOBase_newlines_HAS_DOCSTR +#if defined(_io__TextIOBase_newlines_HAS_DOCSTR) +# define _io__TextIOBase_newlines_DOCSTR _io__TextIOBase_newlines__doc__ +#else +# define _io__TextIOBase_newlines_DOCSTR NULL +#endif #if defined(_IO__TEXTIOBASE_NEWLINES_GETSETDEF) # undef _IO__TEXTIOBASE_NEWLINES_GETSETDEF -# define _IO__TEXTIOBASE_NEWLINES_GETSETDEF {"newlines", (getter)_io__TextIOBase_newlines_get, (setter)_io__TextIOBase_newlines_set, _io__TextIOBase_newlines__doc__}, +# define _IO__TEXTIOBASE_NEWLINES_GETSETDEF {"newlines", (getter)_io__TextIOBase_newlines_get, (setter)_io__TextIOBase_newlines_set, _io__TextIOBase_newlines_DOCSTR}, #else -# define _IO__TEXTIOBASE_NEWLINES_GETSETDEF {"newlines", (getter)_io__TextIOBase_newlines_get, NULL, _io__TextIOBase_newlines__doc__}, +# define _IO__TEXTIOBASE_NEWLINES_GETSETDEF {"newlines", (getter)_io__TextIOBase_newlines_get, NULL, _io__TextIOBase_newlines_DOCSTR}, #endif static PyObject * @@ -249,12 +261,18 @@ PyDoc_STRVAR(_io__TextIOBase_errors__doc__, "The error setting of the decoder or encoder.\n" "\n" "Subclasses should override."); +#define _io__TextIOBase_errors_HAS_DOCSTR +#if defined(_io__TextIOBase_errors_HAS_DOCSTR) +# define _io__TextIOBase_errors_DOCSTR _io__TextIOBase_errors__doc__ +#else +# define _io__TextIOBase_errors_DOCSTR NULL +#endif #if defined(_IO__TEXTIOBASE_ERRORS_GETSETDEF) # undef _IO__TEXTIOBASE_ERRORS_GETSETDEF -# define _IO__TEXTIOBASE_ERRORS_GETSETDEF {"errors", (getter)_io__TextIOBase_errors_get, (setter)_io__TextIOBase_errors_set, _io__TextIOBase_errors__doc__}, +# define _IO__TEXTIOBASE_ERRORS_GETSETDEF {"errors", (getter)_io__TextIOBase_errors_get, (setter)_io__TextIOBase_errors_set, _io__TextIOBase_errors_DOCSTR}, #else -# define _IO__TEXTIOBASE_ERRORS_GETSETDEF {"errors", (getter)_io__TextIOBase_errors_get, NULL, _io__TextIOBase_errors__doc__}, +# define _IO__TEXTIOBASE_ERRORS_GETSETDEF {"errors", (getter)_io__TextIOBase_errors_get, NULL, _io__TextIOBase_errors_DOCSTR}, #endif static PyObject * @@ -1113,14 +1131,16 @@ _io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored)) return return_value; } -PyDoc_STRVAR(_io_TextIOWrapper_name__doc__, -""); - +#if defined(_io_TextIOWrapper_name_HAS_DOCSTR) +# define _io_TextIOWrapper_name_DOCSTR _io_TextIOWrapper_name__doc__ +#else +# define _io_TextIOWrapper_name_DOCSTR NULL +#endif #if defined(_IO_TEXTIOWRAPPER_NAME_GETSETDEF) # undef _IO_TEXTIOWRAPPER_NAME_GETSETDEF -# define _IO_TEXTIOWRAPPER_NAME_GETSETDEF {"name", (getter)_io_TextIOWrapper_name_get, (setter)_io_TextIOWrapper_name_set, _io_TextIOWrapper_name__doc__}, +# define _IO_TEXTIOWRAPPER_NAME_GETSETDEF {"name", (getter)_io_TextIOWrapper_name_get, (setter)_io_TextIOWrapper_name_set, _io_TextIOWrapper_name_DOCSTR}, #else -# define _IO_TEXTIOWRAPPER_NAME_GETSETDEF {"name", (getter)_io_TextIOWrapper_name_get, NULL, _io_TextIOWrapper_name__doc__}, +# define _IO_TEXTIOWRAPPER_NAME_GETSETDEF {"name", (getter)_io_TextIOWrapper_name_get, NULL, _io_TextIOWrapper_name_DOCSTR}, #endif static PyObject * @@ -1138,14 +1158,16 @@ _io_TextIOWrapper_name_get(textio *self, void *Py_UNUSED(context)) return return_value; } -PyDoc_STRVAR(_io_TextIOWrapper_closed__doc__, -""); - +#if defined(_io_TextIOWrapper_closed_HAS_DOCSTR) +# define _io_TextIOWrapper_closed_DOCSTR _io_TextIOWrapper_closed__doc__ +#else +# define _io_TextIOWrapper_closed_DOCSTR NULL +#endif #if defined(_IO_TEXTIOWRAPPER_CLOSED_GETSETDEF) # undef _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF -# define _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF {"closed", (getter)_io_TextIOWrapper_closed_get, (setter)_io_TextIOWrapper_closed_set, _io_TextIOWrapper_closed__doc__}, +# define _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF {"closed", (getter)_io_TextIOWrapper_closed_get, (setter)_io_TextIOWrapper_closed_set, _io_TextIOWrapper_closed_DOCSTR}, #else -# define _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF {"closed", (getter)_io_TextIOWrapper_closed_get, NULL, _io_TextIOWrapper_closed__doc__}, +# define _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF {"closed", (getter)_io_TextIOWrapper_closed_get, NULL, _io_TextIOWrapper_closed_DOCSTR}, #endif static PyObject * @@ -1163,14 +1185,16 @@ _io_TextIOWrapper_closed_get(textio *self, void *Py_UNUSED(context)) return return_value; } -PyDoc_STRVAR(_io_TextIOWrapper_newlines__doc__, -""); - +#if defined(_io_TextIOWrapper_newlines_HAS_DOCSTR) +# define _io_TextIOWrapper_newlines_DOCSTR _io_TextIOWrapper_newlines__doc__ +#else +# define _io_TextIOWrapper_newlines_DOCSTR NULL +#endif #if defined(_IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF) # undef _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF -# define _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF {"newlines", (getter)_io_TextIOWrapper_newlines_get, (setter)_io_TextIOWrapper_newlines_set, _io_TextIOWrapper_newlines__doc__}, +# define _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF {"newlines", (getter)_io_TextIOWrapper_newlines_get, (setter)_io_TextIOWrapper_newlines_set, _io_TextIOWrapper_newlines_DOCSTR}, #else -# define _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF {"newlines", (getter)_io_TextIOWrapper_newlines_get, NULL, _io_TextIOWrapper_newlines__doc__}, +# define _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF {"newlines", (getter)_io_TextIOWrapper_newlines_get, NULL, _io_TextIOWrapper_newlines_DOCSTR}, #endif static PyObject * @@ -1188,14 +1212,16 @@ _io_TextIOWrapper_newlines_get(textio *self, void *Py_UNUSED(context)) return return_value; } -PyDoc_STRVAR(_io_TextIOWrapper_errors__doc__, -""); - +#if defined(_io_TextIOWrapper_errors_HAS_DOCSTR) +# define _io_TextIOWrapper_errors_DOCSTR _io_TextIOWrapper_errors__doc__ +#else +# define _io_TextIOWrapper_errors_DOCSTR NULL +#endif #if defined(_IO_TEXTIOWRAPPER_ERRORS_GETSETDEF) # undef _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF -# define _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF {"errors", (getter)_io_TextIOWrapper_errors_get, (setter)_io_TextIOWrapper_errors_set, _io_TextIOWrapper_errors__doc__}, +# define _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF {"errors", (getter)_io_TextIOWrapper_errors_get, (setter)_io_TextIOWrapper_errors_set, _io_TextIOWrapper_errors_DOCSTR}, #else -# define _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF {"errors", (getter)_io_TextIOWrapper_errors_get, NULL, _io_TextIOWrapper_errors__doc__}, +# define _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF {"errors", (getter)_io_TextIOWrapper_errors_get, NULL, _io_TextIOWrapper_errors_DOCSTR}, #endif static PyObject * @@ -1213,14 +1239,16 @@ _io_TextIOWrapper_errors_get(textio *self, void *Py_UNUSED(context)) return return_value; } -PyDoc_STRVAR(_io_TextIOWrapper__CHUNK_SIZE__doc__, -""); - +#if defined(_io_TextIOWrapper__CHUNK_SIZE_HAS_DOCSTR) +# define _io_TextIOWrapper__CHUNK_SIZE_DOCSTR _io_TextIOWrapper__CHUNK_SIZE__doc__ +#else +# define _io_TextIOWrapper__CHUNK_SIZE_DOCSTR NULL +#endif #if defined(_IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF) # undef _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF -# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, _io_TextIOWrapper__CHUNK_SIZE__doc__}, +# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, _io_TextIOWrapper__CHUNK_SIZE_DOCSTR}, #else -# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, NULL, _io_TextIOWrapper__CHUNK_SIZE__doc__}, +# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, NULL, _io_TextIOWrapper__CHUNK_SIZE_DOCSTR}, #endif static PyObject * @@ -1238,9 +1266,14 @@ _io_TextIOWrapper__CHUNK_SIZE_get(textio *self, void *Py_UNUSED(context)) return return_value; } +#if defined(_IO_TEXTIOWRAPPER__CHUNK_SIZE_HAS_DOCSTR) +# define _io_TextIOWrapper__CHUNK_SIZE_DOCSTR _io_TextIOWrapper__CHUNK_SIZE__doc__ +#else +# define _io_TextIOWrapper__CHUNK_SIZE_DOCSTR NULL +#endif #if defined(_IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF) # undef _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF -# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, _io_TextIOWrapper__CHUNK_SIZE__doc__}, +# define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", (getter)_io_TextIOWrapper__CHUNK_SIZE_get, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, _io_TextIOWrapper__CHUNK_SIZE_DOCSTR}, #else # define _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF {"_CHUNK_SIZE", NULL, (setter)_io_TextIOWrapper__CHUNK_SIZE_set, NULL}, #endif @@ -1259,4 +1292,4 @@ _io_TextIOWrapper__CHUNK_SIZE_set(textio *self, PyObject *value, void *Py_UNUSED return return_value; } -/*[clinic end generated code: output=58f7174c0a2c28e8 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3807f278e1656e16 input=a9049054013a1b77]*/ diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 2e996caf2f28de..65705e8c36cd07 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -871,6 +871,7 @@ class CLanguage(Language): GETSET_DOCSTRING_PROTOTYPE_STRVAR: Final[str] = normalize_snippet(""" PyDoc_STRVAR({getset_basename}__doc__, {docstring}); + #define {getset_basename}_HAS_DOCSTR """) IMPL_DEFINITION_PROTOTYPE: Final[str] = normalize_snippet(""" static {impl_return_type} @@ -881,17 +882,27 @@ class CLanguage(Language): {{"{name}", {methoddef_cast}{c_basename}{methoddef_cast_end}, {methoddef_flags}, {c_basename}__doc__}}, """) GETTERDEF_PROTOTYPE_DEFINE: Final[str] = normalize_snippet(r""" + #if defined({getset_basename}_HAS_DOCSTR) + # define {getset_basename}_DOCSTR {getset_basename}__doc__ + #else + # define {getset_basename}_DOCSTR NULL + #endif #if defined({getset_name}_GETSETDEF) # undef {getset_name}_GETSETDEF - # define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, (setter){getset_basename}_set, {getset_basename}__doc__}}, + # define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, (setter){getset_basename}_set, {getset_basename}_DOCSTR}}, #else - # define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, NULL, {getset_basename}__doc__}}, + # define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, NULL, {getset_basename}_DOCSTR}}, #endif """) SETTERDEF_PROTOTYPE_DEFINE: Final[str] = normalize_snippet(r""" + #if defined({getset_name}_HAS_DOCSTR) + # define {getset_basename}_DOCSTR {getset_basename}__doc__ + #else + # define {getset_basename}_DOCSTR NULL + #endif #if defined({getset_name}_GETSETDEF) # undef {getset_name}_GETSETDEF - # define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, (setter){getset_basename}_set, {getset_basename}__doc__}}, + # define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, (setter){getset_basename}_set, {getset_basename}_DOCSTR}}, #else # define {getset_name}_GETSETDEF {{"{name}", NULL, (setter){getset_basename}_set, NULL}}, #endif @@ -1194,8 +1205,11 @@ def output_templates( docstring_prototype = docstring_definition = '' elif f.kind is GETTER: methoddef_define = self.GETTERDEF_PROTOTYPE_DEFINE - docstring_prototype = self.GETSET_DOCSTRING_PROTOTYPE_VAR - docstring_definition = self.GETSET_DOCSTRING_PROTOTYPE_STRVAR + if f.docstring: + docstring_prototype = self.GETSET_DOCSTRING_PROTOTYPE_VAR + docstring_definition = self.GETSET_DOCSTRING_PROTOTYPE_STRVAR + else: + docstring_prototype = docstring_definition = '' elif f.kind is SETTER: if f.docstring: fail("@setter can not set docstring") From cf1a3a52e62f94cda50cc294d5c10669e72484ba Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 16 Dec 2023 00:20:13 +0900 Subject: [PATCH 03/11] nit --- Lib/test/clinic.test.c | 12 +++++----- Modules/_io/clinic/bufferedio.c.h | 14 ++++++------ Modules/_io/clinic/stringio.c.h | 14 ++++++------ Modules/_io/clinic/textio.c.h | 38 +++++++++++++++---------------- Tools/clinic/clinic.py | 8 +++---- 5 files changed, 43 insertions(+), 43 deletions(-) diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c index e7fcdafa56d02b..b15aeb898d35a1 100644 --- a/Lib/test/clinic.test.c +++ b/Lib/test/clinic.test.c @@ -4957,9 +4957,9 @@ Test.property [clinic start generated code]*/ #if defined(Test_property_HAS_DOCSTR) -# define Test_property_DOCSTR Test_property__doc__ +# define Test_property_DOCSTR Test_property__doc__ #else -# define Test_property_DOCSTR NULL +# define Test_property_DOCSTR NULL #endif #if defined(TEST_PROPERTY_GETSETDEF) # undef TEST_PROPERTY_GETSETDEF @@ -4979,7 +4979,7 @@ Test_property_get(TestObj *self, void *Py_UNUSED(context)) static PyObject * Test_property_get_impl(TestObj *self) -/*[clinic end generated code: output=1bfac7190f65014a input=2d92b3449fbc7d2b]*/ +/*[clinic end generated code: output=27b519719d992e03 input=2d92b3449fbc7d2b]*/ /*[clinic input] @setter @@ -4987,9 +4987,9 @@ Test.property [clinic start generated code]*/ #if defined(TEST_PROPERTY_HAS_DOCSTR) -# define Test_property_DOCSTR Test_property__doc__ +# define Test_property_DOCSTR Test_property__doc__ #else -# define Test_property_DOCSTR NULL +# define Test_property_DOCSTR NULL #endif #if defined(TEST_PROPERTY_GETSETDEF) # undef TEST_PROPERTY_GETSETDEF @@ -5009,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=44050814a89e3dc5 input=3bc3f46a23c83a88]*/ +/*[clinic end generated code: output=9797cd03c5204ddb input=3bc3f46a23c83a88]*/ /*[clinic input] output push diff --git a/Modules/_io/clinic/bufferedio.c.h b/Modules/_io/clinic/bufferedio.c.h index 34f9b2e69944a6..d5bec5f71f5be8 100644 --- a/Modules/_io/clinic/bufferedio.c.h +++ b/Modules/_io/clinic/bufferedio.c.h @@ -328,9 +328,9 @@ _io__Buffered_simple_flush(buffered *self, PyObject *Py_UNUSED(ignored)) } #if defined(_io__Buffered_closed_HAS_DOCSTR) -# define _io__Buffered_closed_DOCSTR _io__Buffered_closed__doc__ +# define _io__Buffered_closed_DOCSTR _io__Buffered_closed__doc__ #else -# define _io__Buffered_closed_DOCSTR NULL +# define _io__Buffered_closed_DOCSTR NULL #endif #if defined(_IO__BUFFERED_CLOSED_GETSETDEF) # undef _IO__BUFFERED_CLOSED_GETSETDEF @@ -470,9 +470,9 @@ _io__Buffered_writable(buffered *self, PyObject *Py_UNUSED(ignored)) } #if defined(_io__Buffered_name_HAS_DOCSTR) -# define _io__Buffered_name_DOCSTR _io__Buffered_name__doc__ +# define _io__Buffered_name_DOCSTR _io__Buffered_name__doc__ #else -# define _io__Buffered_name_DOCSTR NULL +# define _io__Buffered_name_DOCSTR NULL #endif #if defined(_IO__BUFFERED_NAME_GETSETDEF) # undef _IO__BUFFERED_NAME_GETSETDEF @@ -497,9 +497,9 @@ _io__Buffered_name_get(buffered *self, void *Py_UNUSED(context)) } #if defined(_io__Buffered_mode_HAS_DOCSTR) -# define _io__Buffered_mode_DOCSTR _io__Buffered_mode__doc__ +# define _io__Buffered_mode_DOCSTR _io__Buffered_mode__doc__ #else -# define _io__Buffered_mode_DOCSTR NULL +# define _io__Buffered_mode_DOCSTR NULL #endif #if defined(_IO__BUFFERED_MODE_GETSETDEF) # undef _IO__BUFFERED_MODE_GETSETDEF @@ -1245,4 +1245,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=5a3a8dd6e473eb79 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=442b05b9a117df6c input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/stringio.c.h b/Modules/_io/clinic/stringio.c.h index 3d6a6b70d28b44..6bdb2181985f7d 100644 --- a/Modules/_io/clinic/stringio.c.h +++ b/Modules/_io/clinic/stringio.c.h @@ -476,9 +476,9 @@ _io_StringIO___setstate__(stringio *self, PyObject *state) } #if defined(_io_StringIO_closed_HAS_DOCSTR) -# define _io_StringIO_closed_DOCSTR _io_StringIO_closed__doc__ +# define _io_StringIO_closed_DOCSTR _io_StringIO_closed__doc__ #else -# define _io_StringIO_closed_DOCSTR NULL +# define _io_StringIO_closed_DOCSTR NULL #endif #if defined(_IO_STRINGIO_CLOSED_GETSETDEF) # undef _IO_STRINGIO_CLOSED_GETSETDEF @@ -503,9 +503,9 @@ _io_StringIO_closed_get(stringio *self, void *Py_UNUSED(context)) } #if defined(_io_StringIO_line_buffering_HAS_DOCSTR) -# define _io_StringIO_line_buffering_DOCSTR _io_StringIO_line_buffering__doc__ +# define _io_StringIO_line_buffering_DOCSTR _io_StringIO_line_buffering__doc__ #else -# define _io_StringIO_line_buffering_DOCSTR NULL +# define _io_StringIO_line_buffering_DOCSTR NULL #endif #if defined(_IO_STRINGIO_LINE_BUFFERING_GETSETDEF) # undef _IO_STRINGIO_LINE_BUFFERING_GETSETDEF @@ -530,9 +530,9 @@ _io_StringIO_line_buffering_get(stringio *self, void *Py_UNUSED(context)) } #if defined(_io_StringIO_newlines_HAS_DOCSTR) -# define _io_StringIO_newlines_DOCSTR _io_StringIO_newlines__doc__ +# define _io_StringIO_newlines_DOCSTR _io_StringIO_newlines__doc__ #else -# define _io_StringIO_newlines_DOCSTR NULL +# define _io_StringIO_newlines_DOCSTR NULL #endif #if defined(_IO_STRINGIO_NEWLINES_GETSETDEF) # undef _IO_STRINGIO_NEWLINES_GETSETDEF @@ -555,4 +555,4 @@ _io_StringIO_newlines_get(stringio *self, void *Py_UNUSED(context)) return return_value; } -/*[clinic end generated code: output=9814a7ebc7ed94af input=a9049054013a1b77]*/ +/*[clinic end generated code: output=9ffea20cd32d4cd8 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index be9c820132bfa8..23b3cc8d71e098 100644 --- a/Modules/_io/clinic/textio.c.h +++ b/Modules/_io/clinic/textio.c.h @@ -208,9 +208,9 @@ PyDoc_STRVAR(_io__TextIOBase_encoding__doc__, #define _io__TextIOBase_encoding_HAS_DOCSTR #if defined(_io__TextIOBase_encoding_HAS_DOCSTR) -# define _io__TextIOBase_encoding_DOCSTR _io__TextIOBase_encoding__doc__ +# define _io__TextIOBase_encoding_DOCSTR _io__TextIOBase_encoding__doc__ #else -# define _io__TextIOBase_encoding_DOCSTR NULL +# define _io__TextIOBase_encoding_DOCSTR NULL #endif #if defined(_IO__TEXTIOBASE_ENCODING_GETSETDEF) # undef _IO__TEXTIOBASE_ENCODING_GETSETDEF @@ -237,9 +237,9 @@ PyDoc_STRVAR(_io__TextIOBase_newlines__doc__, #define _io__TextIOBase_newlines_HAS_DOCSTR #if defined(_io__TextIOBase_newlines_HAS_DOCSTR) -# define _io__TextIOBase_newlines_DOCSTR _io__TextIOBase_newlines__doc__ +# define _io__TextIOBase_newlines_DOCSTR _io__TextIOBase_newlines__doc__ #else -# define _io__TextIOBase_newlines_DOCSTR NULL +# define _io__TextIOBase_newlines_DOCSTR NULL #endif #if defined(_IO__TEXTIOBASE_NEWLINES_GETSETDEF) # undef _IO__TEXTIOBASE_NEWLINES_GETSETDEF @@ -264,9 +264,9 @@ PyDoc_STRVAR(_io__TextIOBase_errors__doc__, #define _io__TextIOBase_errors_HAS_DOCSTR #if defined(_io__TextIOBase_errors_HAS_DOCSTR) -# define _io__TextIOBase_errors_DOCSTR _io__TextIOBase_errors__doc__ +# define _io__TextIOBase_errors_DOCSTR _io__TextIOBase_errors__doc__ #else -# define _io__TextIOBase_errors_DOCSTR NULL +# define _io__TextIOBase_errors_DOCSTR NULL #endif #if defined(_IO__TEXTIOBASE_ERRORS_GETSETDEF) # undef _IO__TEXTIOBASE_ERRORS_GETSETDEF @@ -1132,9 +1132,9 @@ _io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored)) } #if defined(_io_TextIOWrapper_name_HAS_DOCSTR) -# define _io_TextIOWrapper_name_DOCSTR _io_TextIOWrapper_name__doc__ +# define _io_TextIOWrapper_name_DOCSTR _io_TextIOWrapper_name__doc__ #else -# define _io_TextIOWrapper_name_DOCSTR NULL +# define _io_TextIOWrapper_name_DOCSTR NULL #endif #if defined(_IO_TEXTIOWRAPPER_NAME_GETSETDEF) # undef _IO_TEXTIOWRAPPER_NAME_GETSETDEF @@ -1159,9 +1159,9 @@ _io_TextIOWrapper_name_get(textio *self, void *Py_UNUSED(context)) } #if defined(_io_TextIOWrapper_closed_HAS_DOCSTR) -# define _io_TextIOWrapper_closed_DOCSTR _io_TextIOWrapper_closed__doc__ +# define _io_TextIOWrapper_closed_DOCSTR _io_TextIOWrapper_closed__doc__ #else -# define _io_TextIOWrapper_closed_DOCSTR NULL +# define _io_TextIOWrapper_closed_DOCSTR NULL #endif #if defined(_IO_TEXTIOWRAPPER_CLOSED_GETSETDEF) # undef _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF @@ -1186,9 +1186,9 @@ _io_TextIOWrapper_closed_get(textio *self, void *Py_UNUSED(context)) } #if defined(_io_TextIOWrapper_newlines_HAS_DOCSTR) -# define _io_TextIOWrapper_newlines_DOCSTR _io_TextIOWrapper_newlines__doc__ +# define _io_TextIOWrapper_newlines_DOCSTR _io_TextIOWrapper_newlines__doc__ #else -# define _io_TextIOWrapper_newlines_DOCSTR NULL +# define _io_TextIOWrapper_newlines_DOCSTR NULL #endif #if defined(_IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF) # undef _IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF @@ -1213,9 +1213,9 @@ _io_TextIOWrapper_newlines_get(textio *self, void *Py_UNUSED(context)) } #if defined(_io_TextIOWrapper_errors_HAS_DOCSTR) -# define _io_TextIOWrapper_errors_DOCSTR _io_TextIOWrapper_errors__doc__ +# define _io_TextIOWrapper_errors_DOCSTR _io_TextIOWrapper_errors__doc__ #else -# define _io_TextIOWrapper_errors_DOCSTR NULL +# define _io_TextIOWrapper_errors_DOCSTR NULL #endif #if defined(_IO_TEXTIOWRAPPER_ERRORS_GETSETDEF) # undef _IO_TEXTIOWRAPPER_ERRORS_GETSETDEF @@ -1240,9 +1240,9 @@ _io_TextIOWrapper_errors_get(textio *self, void *Py_UNUSED(context)) } #if defined(_io_TextIOWrapper__CHUNK_SIZE_HAS_DOCSTR) -# define _io_TextIOWrapper__CHUNK_SIZE_DOCSTR _io_TextIOWrapper__CHUNK_SIZE__doc__ +# define _io_TextIOWrapper__CHUNK_SIZE_DOCSTR _io_TextIOWrapper__CHUNK_SIZE__doc__ #else -# define _io_TextIOWrapper__CHUNK_SIZE_DOCSTR NULL +# define _io_TextIOWrapper__CHUNK_SIZE_DOCSTR NULL #endif #if defined(_IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF) # undef _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF @@ -1267,9 +1267,9 @@ _io_TextIOWrapper__CHUNK_SIZE_get(textio *self, void *Py_UNUSED(context)) } #if defined(_IO_TEXTIOWRAPPER__CHUNK_SIZE_HAS_DOCSTR) -# define _io_TextIOWrapper__CHUNK_SIZE_DOCSTR _io_TextIOWrapper__CHUNK_SIZE__doc__ +# define _io_TextIOWrapper__CHUNK_SIZE_DOCSTR _io_TextIOWrapper__CHUNK_SIZE__doc__ #else -# define _io_TextIOWrapper__CHUNK_SIZE_DOCSTR NULL +# define _io_TextIOWrapper__CHUNK_SIZE_DOCSTR NULL #endif #if defined(_IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF) # undef _IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF @@ -1292,4 +1292,4 @@ _io_TextIOWrapper__CHUNK_SIZE_set(textio *self, PyObject *value, void *Py_UNUSED return return_value; } -/*[clinic end generated code: output=3807f278e1656e16 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d01aa598647c1385 input=a9049054013a1b77]*/ diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 65705e8c36cd07..1637ca1428c11b 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -883,9 +883,9 @@ class CLanguage(Language): """) GETTERDEF_PROTOTYPE_DEFINE: Final[str] = normalize_snippet(r""" #if defined({getset_basename}_HAS_DOCSTR) - # define {getset_basename}_DOCSTR {getset_basename}__doc__ + # define {getset_basename}_DOCSTR {getset_basename}__doc__ #else - # define {getset_basename}_DOCSTR NULL + # define {getset_basename}_DOCSTR NULL #endif #if defined({getset_name}_GETSETDEF) # undef {getset_name}_GETSETDEF @@ -896,9 +896,9 @@ class CLanguage(Language): """) SETTERDEF_PROTOTYPE_DEFINE: Final[str] = normalize_snippet(r""" #if defined({getset_name}_HAS_DOCSTR) - # define {getset_basename}_DOCSTR {getset_basename}__doc__ + # define {getset_basename}_DOCSTR {getset_basename}__doc__ #else - # define {getset_basename}_DOCSTR NULL + # define {getset_basename}_DOCSTR NULL #endif #if defined({getset_name}_GETSETDEF) # undef {getset_name}_GETSETDEF From 6bb8272eaf2d7acf141e94a95ab3a0212a5724d5 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Tue, 19 Dec 2023 21:46:16 +0900 Subject: [PATCH 04/11] Update Tools/clinic/clinic.py Co-authored-by: Erlend E. Aasland --- Tools/clinic/clinic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index c230cfa3e31574..b0d9af02eca415 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -1212,7 +1212,7 @@ def output_templates( docstring_prototype = docstring_definition = '' elif f.kind is SETTER: if f.docstring: - fail("@setter can not set docstring") + fail("docstrings are only supported for @getter, not @setter") return_value_declaration = "int {return_value};" methoddef_define = self.SETTERDEF_PROTOTYPE_DEFINE docstring_prototype = docstring_definition = '' From c1b6901f528fba88cfe052aa248aa2fe529a5593 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Tue, 19 Dec 2023 21:56:29 +0900 Subject: [PATCH 05/11] Address code review --- Lib/test/test_clinic.py | 2 +- Tools/clinic/clinic.py | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index 8b95502c5ba73c..714fa6d7cb328f 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -2233,7 +2233,7 @@ class Foo "" "" bar [clinic start generated code]*/ """ - expected_error = "@setter can not set docstring" + expected_error = "docstrings are only supported for @getter, not @setter" self.expect_failure(block, expected_error) def test_duplicate_getset(self): diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index b0d9af02eca415..9aebc56f399630 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -6280,6 +6280,7 @@ def format_docstring_signature( if self.forced_text_signature: add(self.forced_text_signature) elif f.kind in {GETTER, SETTER}: + # @getter and @setter do not need signatures like a method or a function. return '' else: add('(') @@ -6453,11 +6454,12 @@ def format_docstring_parameters(params: list[Parameter]) -> str: def format_docstring(self) -> str: assert self.function is not None f = self.function - if f.kind.new_or_init and not f.docstring: - # don't render a docstring at all, no signature, nothing. - return f.docstring - if f.kind in {GETTER, SETTER} and not f.docstring: - # don't render a docstring at all, no signature, nothing. + k = f.kind + if (k.new_or_init or k in {GETTER, SETTER}) and not f.docstring: + # If the following methods have a empty docstring, + # Do not render a docstring at all, no signature, nothing. + # 1. __init__ / __new__ + # 2. @getter / @setter properties return f.docstring # Enforce the summary line! From 9a021aecd2b7b7a623e9b273a660d388aae727a9 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Tue, 19 Dec 2023 22:01:33 +0900 Subject: [PATCH 06/11] Address code review --- Tools/clinic/clinic.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 9aebc56f399630..466a2b0506fee6 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -865,9 +865,6 @@ class CLanguage(Language): PyDoc_STRVAR({c_basename}__doc__, {docstring}); """) - GETSET_DOCSTRING_PROTOTYPE_VAR: Final[str] = normalize_snippet(""" - PyDoc_VAR({getset_basename}__doc__); - """) GETSET_DOCSTRING_PROTOTYPE_STRVAR: Final[str] = normalize_snippet(""" PyDoc_STRVAR({getset_basename}__doc__, {docstring}); @@ -1206,7 +1203,7 @@ def output_templates( elif f.kind is GETTER: methoddef_define = self.GETTERDEF_PROTOTYPE_DEFINE if f.docstring: - docstring_prototype = self.GETSET_DOCSTRING_PROTOTYPE_VAR + docstring_prototype = '' docstring_definition = self.GETSET_DOCSTRING_PROTOTYPE_STRVAR else: docstring_prototype = docstring_definition = '' From 2cffe259c7f0d94f2196eecd48cc01ef07a27c1e Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Tue, 19 Dec 2023 22:04:51 +0900 Subject: [PATCH 07/11] nit style --- Lib/test/test_clinic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index 714fa6d7cb328f..daa2e2abba56f6 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -2265,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"): with self.subTest(annotation=annotation): block = f""" module m From 18d178672d683da3a86add397ae695413dd57f78 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Tue, 19 Dec 2023 22:30:25 +0900 Subject: [PATCH 08/11] nit --- Tools/clinic/clinic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 466a2b0506fee6..e39e25569e1079 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -6453,7 +6453,7 @@ def format_docstring(self) -> str: f = self.function k = f.kind if (k.new_or_init or k in {GETTER, SETTER}) and not f.docstring: - # If the following methods have a empty docstring, + # If following cases have a empty docstring, # Do not render a docstring at all, no signature, nothing. # 1. __init__ / __new__ # 2. @getter / @setter properties From cb6f499619c1637326b525e4eb6a13b8a632973b Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 20 Dec 2023 00:21:40 +0900 Subject: [PATCH 09/11] Update Lib/test/test_clinic.py Co-authored-by: Erlend E. Aasland --- Lib/test/test_clinic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index daa2e2abba56f6..714fa6d7cb328f 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -2265,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": with self.subTest(annotation=annotation): block = f""" module m From 547643162beb7c603165cff924a995ece78b593a Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 20 Dec 2023 17:57:44 +0900 Subject: [PATCH 10/11] Improve readblility --- Tools/clinic/clinic.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index e39e25569e1079..5b38a80801c5d8 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -6451,8 +6451,7 @@ def format_docstring_parameters(params: list[Parameter]) -> str: def format_docstring(self) -> str: assert self.function is not None f = self.function - k = f.kind - if (k.new_or_init or k in {GETTER, SETTER}) and not f.docstring: + if f.kind in {METHOD_INIT, METHOD_NEW, GETTER, SETTER} and not f.docstring: # If following cases have a empty docstring, # Do not render a docstring at all, no signature, nothing. # 1. __init__ / __new__ From 15d61e92c96d1574750c5fdde95495f865aaf63b Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 20 Dec 2023 18:46:22 +0900 Subject: [PATCH 11/11] Update Tools/clinic/clinic.py Co-authored-by: Erlend E. Aasland --- Tools/clinic/clinic.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 5b38a80801c5d8..345459cf2fd623 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -6451,11 +6451,8 @@ def format_docstring_parameters(params: list[Parameter]) -> str: def format_docstring(self) -> str: assert self.function is not None f = self.function + # For the following special cases, it does not make sense to render a docstring. if f.kind in {METHOD_INIT, METHOD_NEW, GETTER, SETTER} and not f.docstring: - # If following cases have a empty docstring, - # Do not render a docstring at all, no signature, nothing. - # 1. __init__ / __new__ - # 2. @getter / @setter properties return f.docstring # Enforce the summary line!