From 3479b2f133d5e96357001fd9d446145dca3b2c64 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 7 Aug 2023 13:42:09 +0200 Subject: [PATCH 1/8] gh-95065: Argument Clinic: Pretty-print long C strings in generated code --- Lib/test/clinic.test.c | 360 +++++++++++++++++++++++++---------------- Tools/clinic/clinic.py | 40 ++++- 2 files changed, 258 insertions(+), 142 deletions(-) diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c index 321ac69273189f..062207f8201654 100644 --- a/Lib/test/clinic.test.c +++ b/Lib/test/clinic.test.c @@ -5520,20 +5520,29 @@ test_deprecate_positional_pos1_len1_optional(PyObject *module, PyObject *const * PyObject *a; PyObject *b = Py_None; - #if PY_VERSION_HEX >= 0x030e00C0 - # error "In clinic.test.c, update parameter(s) 'b' in the clinic input of 'test_deprecate_positional_pos1_len1_optional' to be keyword-only." - #elif PY_VERSION_HEX >= 0x030e00A0 - # ifdef _MSC_VER - # pragma message ("In clinic.test.c, update parameter(s) 'b' in the clinic input of 'test_deprecate_positional_pos1_len1_optional' to be keyword-only.") - # else - # warning "In clinic.test.c, update parameter(s) 'b' in the clinic input of 'test_deprecate_positional_pos1_len1_optional' to be keyword-only." - # endif - #endif - if (nargs == 2) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, "Passing 2 positional arguments to test_deprecate_positional_pos1_len1_optional() is deprecated. Parameter 'b' will become a keyword-only parameter in Python 3.14.", 1)) { - goto exit; - } - } + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ + "'test_deprecate_positional_pos1_len1_optional' to be keyword-only." + #elif PY_VERSION_HEX >= 0x030e00A0 + # ifdef _MSC_VER + # pragma message ( \ + "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ + "'test_deprecate_positional_pos1_len1_optional' to be keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ + "'test_deprecate_positional_pos1_len1_optional' to be keyword-only." + # endif + #endif + if (nargs == 2) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, \ + "Passing 2 positional arguments to " \ + "test_deprecate_positional_pos1_len1_optional() is deprecated. " \ + "Parameter 'b' will become a keyword-only parameter in Python 3.14.", 1)) + { + goto exit; + } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); if (!args) { goto exit; @@ -5553,7 +5562,7 @@ test_deprecate_positional_pos1_len1_optional(PyObject *module, PyObject *const * static PyObject * test_deprecate_positional_pos1_len1_optional_impl(PyObject *module, PyObject *a, PyObject *b) -/*[clinic end generated code: output=20bdea6a2960ddf3 input=89099f3dacd757da]*/ +/*[clinic end generated code: output=14fb8aaae77d1722 input=89099f3dacd757da]*/ /*[clinic input] @@ -5608,20 +5617,29 @@ test_deprecate_positional_pos1_len1(PyObject *module, PyObject *const *args, Py_ PyObject *a; PyObject *b; - #if PY_VERSION_HEX >= 0x030e00C0 - # error "In clinic.test.c, update parameter(s) 'b' in the clinic input of 'test_deprecate_positional_pos1_len1' to be keyword-only." - #elif PY_VERSION_HEX >= 0x030e00A0 - # ifdef _MSC_VER - # pragma message ("In clinic.test.c, update parameter(s) 'b' in the clinic input of 'test_deprecate_positional_pos1_len1' to be keyword-only.") - # else - # warning "In clinic.test.c, update parameter(s) 'b' in the clinic input of 'test_deprecate_positional_pos1_len1' to be keyword-only." - # endif - #endif - if (nargs == 2) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, "Passing 2 positional arguments to test_deprecate_positional_pos1_len1() is deprecated. Parameter 'b' will become a keyword-only parameter in Python 3.14.", 1)) { - goto exit; - } - } + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ + "'test_deprecate_positional_pos1_len1' to be keyword-only." + #elif PY_VERSION_HEX >= 0x030e00A0 + # ifdef _MSC_VER + # pragma message ( \ + "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ + "'test_deprecate_positional_pos1_len1' to be keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ + "'test_deprecate_positional_pos1_len1' to be keyword-only." + # endif + #endif + if (nargs == 2) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, \ + "Passing 2 positional arguments to " \ + "test_deprecate_positional_pos1_len1() is deprecated. Parameter 'b' " \ + "will become a keyword-only parameter in Python 3.14.", 1)) + { + goto exit; + } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); if (!args) { goto exit; @@ -5637,7 +5655,7 @@ test_deprecate_positional_pos1_len1(PyObject *module, PyObject *const *args, Py_ static PyObject * test_deprecate_positional_pos1_len1_impl(PyObject *module, PyObject *a, PyObject *b) -/*[clinic end generated code: output=22c70f8b36085758 input=1702bbab1e9b3b99]*/ +/*[clinic end generated code: output=e9652e0fd59943c1 input=1702bbab1e9b3b99]*/ /*[clinic input] @@ -5698,20 +5716,30 @@ test_deprecate_positional_pos1_len2_with_kwd(PyObject *module, PyObject *const * PyObject *c; PyObject *d; - #if PY_VERSION_HEX >= 0x030e00C0 - # error "In clinic.test.c, update parameter(s) 'b' and 'c' in the clinic input of 'test_deprecate_positional_pos1_len2_with_kwd' to be keyword-only." - #elif PY_VERSION_HEX >= 0x030e00A0 - # ifdef _MSC_VER - # pragma message ("In clinic.test.c, update parameter(s) 'b' and 'c' in the clinic input of 'test_deprecate_positional_pos1_len2_with_kwd' to be keyword-only.") - # else - # warning "In clinic.test.c, update parameter(s) 'b' and 'c' in the clinic input of 'test_deprecate_positional_pos1_len2_with_kwd' to be keyword-only." - # endif - #endif - if (nargs > 1 && nargs <= 3) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, "Passing more than 1 positional argument to test_deprecate_positional_pos1_len2_with_kwd() is deprecated. Parameters 'b' and 'c' will become keyword-only parameters in Python 3.14.", 1)) { - goto exit; - } - } + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'b' and 'c' in the clinic input " \ + "of 'test_deprecate_positional_pos1_len2_with_kwd' to be keyword-only." + #elif PY_VERSION_HEX >= 0x030e00A0 + # ifdef _MSC_VER + # pragma message ( \ + "In clinic.test.c, update parameter(s) 'b' and 'c' in the clinic input " \ + "of 'test_deprecate_positional_pos1_len2_with_kwd' to be keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'b' and 'c' in the clinic input " \ + "of 'test_deprecate_positional_pos1_len2_with_kwd' to be keyword-only." + # endif + #endif + if (nargs > 1 && nargs <= 3) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, \ + "Passing more than 1 positional argument to " \ + "test_deprecate_positional_pos1_len2_with_kwd() is deprecated. " \ + "Parameters 'b' and 'c' will become keyword-only parameters in Python " \ + "3.14.", 1)) + { + goto exit; + } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 1, argsbuf); if (!args) { goto exit; @@ -5730,7 +5758,7 @@ static PyObject * test_deprecate_positional_pos1_len2_with_kwd_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c, PyObject *d) -/*[clinic end generated code: output=79c5f04220a1f3aa input=28cdb885f6c34eab]*/ +/*[clinic end generated code: output=3f05b1810fca68c9 input=28cdb885f6c34eab]*/ /*[clinic input] @@ -5782,20 +5810,29 @@ test_deprecate_positional_pos0_len1(PyObject *module, PyObject *const *args, Py_ PyObject *argsbuf[1]; PyObject *a; - #if PY_VERSION_HEX >= 0x030e00C0 - # error "In clinic.test.c, update parameter(s) 'a' in the clinic input of 'test_deprecate_positional_pos0_len1' to be keyword-only." - #elif PY_VERSION_HEX >= 0x030e00A0 - # ifdef _MSC_VER - # pragma message ("In clinic.test.c, update parameter(s) 'a' in the clinic input of 'test_deprecate_positional_pos0_len1' to be keyword-only.") - # else - # warning "In clinic.test.c, update parameter(s) 'a' in the clinic input of 'test_deprecate_positional_pos0_len1' to be keyword-only." - # endif - #endif - if (nargs == 1) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, "Passing positional arguments to test_deprecate_positional_pos0_len1() is deprecated. Parameter 'a' will become a keyword-only parameter in Python 3.14.", 1)) { - goto exit; - } - } + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'a' in the clinic input of " \ + "'test_deprecate_positional_pos0_len1' to be keyword-only." + #elif PY_VERSION_HEX >= 0x030e00A0 + # ifdef _MSC_VER + # pragma message ( \ + "In clinic.test.c, update parameter(s) 'a' in the clinic input of " \ + "'test_deprecate_positional_pos0_len1' to be keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'a' in the clinic input of " \ + "'test_deprecate_positional_pos0_len1' to be keyword-only." + # endif + #endif + if (nargs == 1) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, \ + "Passing positional arguments to test_deprecate_positional_pos0_len1() " \ + "is deprecated. Parameter 'a' will become a keyword-only parameter in " \ + "Python 3.14.", 1)) + { + goto exit; + } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); if (!args) { goto exit; @@ -5809,7 +5846,7 @@ test_deprecate_positional_pos0_len1(PyObject *module, PyObject *const *args, Py_ static PyObject * test_deprecate_positional_pos0_len1_impl(PyObject *module, PyObject *a) -/*[clinic end generated code: output=1b7f23b9ffca431b input=678206db25c0652c]*/ +/*[clinic end generated code: output=2d69d62449a64bf9 input=678206db25c0652c]*/ /*[clinic input] @@ -5864,20 +5901,29 @@ test_deprecate_positional_pos0_len2(PyObject *module, PyObject *const *args, Py_ PyObject *a; PyObject *b; - #if PY_VERSION_HEX >= 0x030e00C0 - # error "In clinic.test.c, update parameter(s) 'a' and 'b' in the clinic input of 'test_deprecate_positional_pos0_len2' to be keyword-only." - #elif PY_VERSION_HEX >= 0x030e00A0 - # ifdef _MSC_VER - # pragma message ("In clinic.test.c, update parameter(s) 'a' and 'b' in the clinic input of 'test_deprecate_positional_pos0_len2' to be keyword-only.") - # else - # warning "In clinic.test.c, update parameter(s) 'a' and 'b' in the clinic input of 'test_deprecate_positional_pos0_len2' to be keyword-only." - # endif - #endif - if (nargs > 0 && nargs <= 2) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, "Passing positional arguments to test_deprecate_positional_pos0_len2() is deprecated. Parameters 'a' and 'b' will become keyword-only parameters in Python 3.14.", 1)) { - goto exit; - } - } + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'a' and 'b' in the clinic input " \ + "of 'test_deprecate_positional_pos0_len2' to be keyword-only." + #elif PY_VERSION_HEX >= 0x030e00A0 + # ifdef _MSC_VER + # pragma message ( \ + "In clinic.test.c, update parameter(s) 'a' and 'b' in the clinic input " \ + "of 'test_deprecate_positional_pos0_len2' to be keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'a' and 'b' in the clinic input " \ + "of 'test_deprecate_positional_pos0_len2' to be keyword-only." + # endif + #endif + if (nargs > 0 && nargs <= 2) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, \ + "Passing positional arguments to test_deprecate_positional_pos0_len2() " \ + "is deprecated. Parameters 'a' and 'b' will become keyword-only " \ + "parameters in Python 3.14.", 1)) + { + goto exit; + } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); if (!args) { goto exit; @@ -5893,7 +5939,7 @@ test_deprecate_positional_pos0_len2(PyObject *module, PyObject *const *args, Py_ static PyObject * test_deprecate_positional_pos0_len2_impl(PyObject *module, PyObject *a, PyObject *b) -/*[clinic end generated code: output=31b494f2dcc016af input=fae0d0b1d480c939]*/ +/*[clinic end generated code: output=c57a186d00eaf931 input=fae0d0b1d480c939]*/ /*[clinic input] @@ -5957,20 +6003,33 @@ test_deprecate_positional_pos0_len3_with_kwdonly(PyObject *module, PyObject *con PyObject *c; PyObject *e; - #if PY_VERSION_HEX >= 0x030e00C0 - # error "In clinic.test.c, update parameter(s) 'a', 'b' and 'c' in the clinic input of 'test_deprecate_positional_pos0_len3_with_kwdonly' to be keyword-only." - #elif PY_VERSION_HEX >= 0x030e00A0 - # ifdef _MSC_VER - # pragma message ("In clinic.test.c, update parameter(s) 'a', 'b' and 'c' in the clinic input of 'test_deprecate_positional_pos0_len3_with_kwdonly' to be keyword-only.") - # else - # warning "In clinic.test.c, update parameter(s) 'a', 'b' and 'c' in the clinic input of 'test_deprecate_positional_pos0_len3_with_kwdonly' to be keyword-only." - # endif - #endif - if (nargs > 0 && nargs <= 3) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, "Passing positional arguments to test_deprecate_positional_pos0_len3_with_kwdonly() is deprecated. Parameters 'a', 'b' and 'c' will become keyword-only parameters in Python 3.14.", 1)) { - goto exit; - } - } + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'a', 'b' and 'c' in the clinic " \ + "input of 'test_deprecate_positional_pos0_len3_with_kwdonly' to be " \ + "keyword-only." + #elif PY_VERSION_HEX >= 0x030e00A0 + # ifdef _MSC_VER + # pragma message ( \ + "In clinic.test.c, update parameter(s) 'a', 'b' and 'c' in the clinic " \ + "input of 'test_deprecate_positional_pos0_len3_with_kwdonly' to be " \ + "keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'a', 'b' and 'c' in the clinic " \ + "input of 'test_deprecate_positional_pos0_len3_with_kwdonly' to be " \ + "keyword-only." + # endif + #endif + if (nargs > 0 && nargs <= 3) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, \ + "Passing positional arguments to " \ + "test_deprecate_positional_pos0_len3_with_kwdonly() is deprecated. " \ + "Parameters 'a', 'b' and 'c' will become keyword-only parameters in " \ + "Python 3.14.", 1)) + { + goto exit; + } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 1, argsbuf); if (!args) { goto exit; @@ -5991,7 +6050,7 @@ test_deprecate_positional_pos0_len3_with_kwdonly_impl(PyObject *module, PyObject *b, PyObject *c, PyObject *e) -/*[clinic end generated code: output=96978e786acfbc7b input=1b0121770c0c52e0]*/ +/*[clinic end generated code: output=cc96aff202cfcc40 input=1b0121770c0c52e0]*/ /*[clinic input] @@ -6048,20 +6107,29 @@ test_deprecate_positional_pos2_len1(PyObject *module, PyObject *const *args, Py_ PyObject *b; PyObject *c; - #if PY_VERSION_HEX >= 0x030e00C0 - # error "In clinic.test.c, update parameter(s) 'c' in the clinic input of 'test_deprecate_positional_pos2_len1' to be keyword-only." - #elif PY_VERSION_HEX >= 0x030e00A0 - # ifdef _MSC_VER - # pragma message ("In clinic.test.c, update parameter(s) 'c' in the clinic input of 'test_deprecate_positional_pos2_len1' to be keyword-only.") - # else - # warning "In clinic.test.c, update parameter(s) 'c' in the clinic input of 'test_deprecate_positional_pos2_len1' to be keyword-only." - # endif - #endif - if (nargs == 3) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, "Passing 3 positional arguments to test_deprecate_positional_pos2_len1() is deprecated. Parameter 'c' will become a keyword-only parameter in Python 3.14.", 1)) { - goto exit; - } - } + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'c' in the clinic input of " \ + "'test_deprecate_positional_pos2_len1' to be keyword-only." + #elif PY_VERSION_HEX >= 0x030e00A0 + # ifdef _MSC_VER + # pragma message ( \ + "In clinic.test.c, update parameter(s) 'c' in the clinic input of " \ + "'test_deprecate_positional_pos2_len1' to be keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'c' in the clinic input of " \ + "'test_deprecate_positional_pos2_len1' to be keyword-only." + # endif + #endif + if (nargs == 3) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, \ + "Passing 3 positional arguments to " \ + "test_deprecate_positional_pos2_len1() is deprecated. Parameter 'c' " \ + "will become a keyword-only parameter in Python 3.14.", 1)) + { + goto exit; + } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); if (!args) { goto exit; @@ -6078,7 +6146,7 @@ test_deprecate_positional_pos2_len1(PyObject *module, PyObject *const *args, Py_ static PyObject * test_deprecate_positional_pos2_len1_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c) -/*[clinic end generated code: output=ceadd05f11f7f491 input=e1d129689e69ec7c]*/ +/*[clinic end generated code: output=5ad40341de058b19 input=e1d129689e69ec7c]*/ /*[clinic input] @@ -6138,20 +6206,29 @@ test_deprecate_positional_pos2_len2(PyObject *module, PyObject *const *args, Py_ PyObject *c; PyObject *d; - #if PY_VERSION_HEX >= 0x030e00C0 - # error "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input of 'test_deprecate_positional_pos2_len2' to be keyword-only." - #elif PY_VERSION_HEX >= 0x030e00A0 - # ifdef _MSC_VER - # pragma message ("In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input of 'test_deprecate_positional_pos2_len2' to be keyword-only.") - # else - # warning "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input of 'test_deprecate_positional_pos2_len2' to be keyword-only." - # endif - #endif - if (nargs > 2 && nargs <= 4) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, "Passing more than 2 positional arguments to test_deprecate_positional_pos2_len2() is deprecated. Parameters 'c' and 'd' will become keyword-only parameters in Python 3.14.", 1)) { - goto exit; - } - } + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ + "of 'test_deprecate_positional_pos2_len2' to be keyword-only." + #elif PY_VERSION_HEX >= 0x030e00A0 + # ifdef _MSC_VER + # pragma message ( \ + "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ + "of 'test_deprecate_positional_pos2_len2' to be keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ + "of 'test_deprecate_positional_pos2_len2' to be keyword-only." + # endif + #endif + if (nargs > 2 && nargs <= 4) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, \ + "Passing more than 2 positional arguments to " \ + "test_deprecate_positional_pos2_len2() is deprecated. Parameters 'c' " \ + "and 'd' will become keyword-only parameters in Python 3.14.", 1)) + { + goto exit; + } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 4, 0, argsbuf); if (!args) { goto exit; @@ -6170,7 +6247,7 @@ static PyObject * test_deprecate_positional_pos2_len2_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c, PyObject *d) -/*[clinic end generated code: output=5693682e3fa1188b input=0d53533463a12792]*/ +/*[clinic end generated code: output=593d77137bd117cb input=0d53533463a12792]*/ /*[clinic input] @@ -6237,20 +6314,33 @@ test_deprecate_positional_pos2_len3_with_kwdonly(PyObject *module, PyObject *con PyObject *d; PyObject *e; - #if PY_VERSION_HEX >= 0x030e00C0 - # error "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input of 'test_deprecate_positional_pos2_len3_with_kwdonly' to be keyword-only." - #elif PY_VERSION_HEX >= 0x030e00A0 - # ifdef _MSC_VER - # pragma message ("In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input of 'test_deprecate_positional_pos2_len3_with_kwdonly' to be keyword-only.") - # else - # warning "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input of 'test_deprecate_positional_pos2_len3_with_kwdonly' to be keyword-only." - # endif - #endif - if (nargs > 2 && nargs <= 4) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, "Passing more than 2 positional arguments to test_deprecate_positional_pos2_len3_with_kwdonly() is deprecated. Parameters 'c' and 'd' will become keyword-only parameters in Python 3.14.", 1)) { - goto exit; - } - } + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ + "of 'test_deprecate_positional_pos2_len3_with_kwdonly' to be " \ + "keyword-only." + #elif PY_VERSION_HEX >= 0x030e00A0 + # ifdef _MSC_VER + # pragma message ( \ + "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ + "of 'test_deprecate_positional_pos2_len3_with_kwdonly' to be " \ + "keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ + "of 'test_deprecate_positional_pos2_len3_with_kwdonly' to be " \ + "keyword-only." + # endif + #endif + if (nargs > 2 && nargs <= 4) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, \ + "Passing more than 2 positional arguments to " \ + "test_deprecate_positional_pos2_len3_with_kwdonly() is deprecated. " \ + "Parameters 'c' and 'd' will become keyword-only parameters in Python " \ + "3.14.", 1)) + { + goto exit; + } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 4, 1, argsbuf); if (!args) { goto exit; @@ -6273,4 +6363,4 @@ test_deprecate_positional_pos2_len3_with_kwdonly_impl(PyObject *module, PyObject *c, PyObject *d, PyObject *e) -/*[clinic end generated code: output=00d436de747a00f3 input=154fd450448d8935]*/ +/*[clinic end generated code: output=2bbf3e16262d2012 input=154fd450448d8935]*/ diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 4dfe90b314f543..c26dc4cd1b09fd 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -221,6 +221,31 @@ def c_repr(s: str) -> str: return '"' + s + '"' +def wrapped_c_string_literal(line, width=72): + add, out = text_accumulator() + words = line.split(' ') + add(' \\\n') + while True: + add('"') + sz = 1 + while True: + try: + word = words[0] + except IndexError: + add('"') + return out() + sz += len(word) + 1 + if sz > 72: + break + add(word) + del words[0] + if words: + add(' ') + add('"') + add(' \\') + add('\n') + + is_legal_c_identifier = re.compile('^[A-Za-z_][A-Za-z0-9_]*$').match def is_legal_py_identifier(s: str) -> bool: @@ -837,18 +862,18 @@ class CLanguage(Language): """) DEPRECATED_POSITIONAL_PROTOTYPE: Final[str] = r""" #if PY_VERSION_HEX >= 0x{major:02x}{minor:02x}00C0 - # error "{cpp_message}" + # error {cpp_message} #elif PY_VERSION_HEX >= 0x{major:02x}{minor:02x}00A0 # ifdef _MSC_VER - # pragma message ("{cpp_message}") + # pragma message ({cpp_message}) # else - # warning "{cpp_message}" + # warning {cpp_message} # endif #endif if ({condition}) {{{{ - if (PyErr_WarnEx(PyExc_DeprecationWarning, "{depr_message}", 1)) {{{{ + if (PyErr_WarnEx(PyExc_DeprecationWarning, {depr_message}, 1)) + {{{{ goto exit; - }}}} }}}} """ @@ -899,6 +924,7 @@ def deprecate_positional_use( f"In {source}, update parameter(s) {pstr} in the clinic " f"input of {func.full_name!r} to be keyword-only." ) + # Format the deprecation message. if first_pos == 0: preamble = "Passing positional arguments to " @@ -926,8 +952,8 @@ def deprecate_positional_use( condition=condition, major=major, minor=minor, - cpp_message=cpp_message, - depr_message=depr_message, + cpp_message=wrapped_c_string_literal(cpp_message), + depr_message=wrapped_c_string_literal(depr_message), ) return normalize_snippet(code, indent=4) From 9dbb61a26a377f61ec85309c8cb0c8e08bc6dfba Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 7 Aug 2023 13:54:08 +0200 Subject: [PATCH 2/8] Perhaps better --- Lib/test/clinic.test.c | 450 ++++++++++++++++++++--------------------- Tools/clinic/clinic.py | 34 +++- 2 files changed, 250 insertions(+), 234 deletions(-) diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c index 062207f8201654..c6885324cf5914 100644 --- a/Lib/test/clinic.test.c +++ b/Lib/test/clinic.test.c @@ -5520,29 +5520,29 @@ test_deprecate_positional_pos1_len1_optional(PyObject *module, PyObject *const * PyObject *a; PyObject *b = Py_None; - #if PY_VERSION_HEX >= 0x030e00C0 - # error \ - "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ - "'test_deprecate_positional_pos1_len1_optional' to be keyword-only." - #elif PY_VERSION_HEX >= 0x030e00A0 - # ifdef _MSC_VER - # pragma message ( \ - "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ - "'test_deprecate_positional_pos1_len1_optional' to be keyword-only.") - # else - # warning \ - "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ - "'test_deprecate_positional_pos1_len1_optional' to be keyword-only." - # endif - #endif - if (nargs == 2) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, \ - "Passing 2 positional arguments to " \ - "test_deprecate_positional_pos1_len1_optional() is deprecated. " \ - "Parameter 'b' will become a keyword-only parameter in Python 3.14.", 1)) - { - goto exit; - } + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ + "'test_deprecate_positional_pos1_len1_optional' to be keyword-only." + #elif PY_VERSION_HEX >= 0x030e00A0 + # ifdef _MSC_VER + # pragma message ( \ + "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ + "'test_deprecate_positional_pos1_len1_optional' to be keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ + "'test_deprecate_positional_pos1_len1_optional' to be keyword-only." + # endif + #endif + if (nargs == 2) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "Passing 2 positional arguments to " \ + "test_deprecate_positional_pos1_len1_optional() is deprecated. " \ + "Parameter 'b' will become a keyword-only parameter in Python 3.14.", 1)) + { + goto exit; + } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); if (!args) { goto exit; @@ -5562,7 +5562,7 @@ test_deprecate_positional_pos1_len1_optional(PyObject *module, PyObject *const * static PyObject * test_deprecate_positional_pos1_len1_optional_impl(PyObject *module, PyObject *a, PyObject *b) -/*[clinic end generated code: output=14fb8aaae77d1722 input=89099f3dacd757da]*/ +/*[clinic end generated code: output=8ff8fda7f3f10aa6 input=89099f3dacd757da]*/ /*[clinic input] @@ -5617,29 +5617,29 @@ test_deprecate_positional_pos1_len1(PyObject *module, PyObject *const *args, Py_ PyObject *a; PyObject *b; - #if PY_VERSION_HEX >= 0x030e00C0 - # error \ - "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ - "'test_deprecate_positional_pos1_len1' to be keyword-only." - #elif PY_VERSION_HEX >= 0x030e00A0 - # ifdef _MSC_VER - # pragma message ( \ - "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ - "'test_deprecate_positional_pos1_len1' to be keyword-only.") - # else - # warning \ - "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ - "'test_deprecate_positional_pos1_len1' to be keyword-only." - # endif - #endif - if (nargs == 2) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, \ - "Passing 2 positional arguments to " \ - "test_deprecate_positional_pos1_len1() is deprecated. Parameter 'b' " \ - "will become a keyword-only parameter in Python 3.14.", 1)) - { - goto exit; - } + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ + "'test_deprecate_positional_pos1_len1' to be keyword-only." + #elif PY_VERSION_HEX >= 0x030e00A0 + # ifdef _MSC_VER + # pragma message ( \ + "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ + "'test_deprecate_positional_pos1_len1' to be keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ + "'test_deprecate_positional_pos1_len1' to be keyword-only." + # endif + #endif + if (nargs == 2) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "Passing 2 positional arguments to " \ + "test_deprecate_positional_pos1_len1() is deprecated. Parameter 'b' " \ + "will become a keyword-only parameter in Python 3.14.", 1)) + { + goto exit; + } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); if (!args) { goto exit; @@ -5655,7 +5655,7 @@ test_deprecate_positional_pos1_len1(PyObject *module, PyObject *const *args, Py_ static PyObject * test_deprecate_positional_pos1_len1_impl(PyObject *module, PyObject *a, PyObject *b) -/*[clinic end generated code: output=e9652e0fd59943c1 input=1702bbab1e9b3b99]*/ +/*[clinic end generated code: output=170fe98f2d6e2711 input=1702bbab1e9b3b99]*/ /*[clinic input] @@ -5716,30 +5716,30 @@ test_deprecate_positional_pos1_len2_with_kwd(PyObject *module, PyObject *const * PyObject *c; PyObject *d; - #if PY_VERSION_HEX >= 0x030e00C0 - # error \ - "In clinic.test.c, update parameter(s) 'b' and 'c' in the clinic input " \ - "of 'test_deprecate_positional_pos1_len2_with_kwd' to be keyword-only." - #elif PY_VERSION_HEX >= 0x030e00A0 - # ifdef _MSC_VER - # pragma message ( \ - "In clinic.test.c, update parameter(s) 'b' and 'c' in the clinic input " \ - "of 'test_deprecate_positional_pos1_len2_with_kwd' to be keyword-only.") - # else - # warning \ - "In clinic.test.c, update parameter(s) 'b' and 'c' in the clinic input " \ - "of 'test_deprecate_positional_pos1_len2_with_kwd' to be keyword-only." - # endif - #endif - if (nargs > 1 && nargs <= 3) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, \ - "Passing more than 1 positional argument to " \ - "test_deprecate_positional_pos1_len2_with_kwd() is deprecated. " \ - "Parameters 'b' and 'c' will become keyword-only parameters in Python " \ - "3.14.", 1)) - { - goto exit; - } + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'b' and 'c' in the clinic input " \ + "of 'test_deprecate_positional_pos1_len2_with_kwd' to be keyword-only." + #elif PY_VERSION_HEX >= 0x030e00A0 + # ifdef _MSC_VER + # pragma message ( \ + "In clinic.test.c, update parameter(s) 'b' and 'c' in the clinic input " \ + "of 'test_deprecate_positional_pos1_len2_with_kwd' to be keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'b' and 'c' in the clinic input " \ + "of 'test_deprecate_positional_pos1_len2_with_kwd' to be keyword-only." + # endif + #endif + if (nargs > 1 && nargs <= 3) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "Passing more than 1 positional argument to " \ + "test_deprecate_positional_pos1_len2_with_kwd() is deprecated. " \ + "Parameters 'b' and 'c' will become keyword-only parameters in Python " \ + "3.14.", 1)) + { + goto exit; + } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 1, argsbuf); if (!args) { goto exit; @@ -5758,7 +5758,7 @@ static PyObject * test_deprecate_positional_pos1_len2_with_kwd_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c, PyObject *d) -/*[clinic end generated code: output=3f05b1810fca68c9 input=28cdb885f6c34eab]*/ +/*[clinic end generated code: output=b4c0595ec15619a3 input=28cdb885f6c34eab]*/ /*[clinic input] @@ -5810,29 +5810,29 @@ test_deprecate_positional_pos0_len1(PyObject *module, PyObject *const *args, Py_ PyObject *argsbuf[1]; PyObject *a; - #if PY_VERSION_HEX >= 0x030e00C0 - # error \ - "In clinic.test.c, update parameter(s) 'a' in the clinic input of " \ - "'test_deprecate_positional_pos0_len1' to be keyword-only." - #elif PY_VERSION_HEX >= 0x030e00A0 - # ifdef _MSC_VER - # pragma message ( \ - "In clinic.test.c, update parameter(s) 'a' in the clinic input of " \ - "'test_deprecate_positional_pos0_len1' to be keyword-only.") - # else - # warning \ - "In clinic.test.c, update parameter(s) 'a' in the clinic input of " \ - "'test_deprecate_positional_pos0_len1' to be keyword-only." - # endif - #endif - if (nargs == 1) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, \ - "Passing positional arguments to test_deprecate_positional_pos0_len1() " \ - "is deprecated. Parameter 'a' will become a keyword-only parameter in " \ - "Python 3.14.", 1)) - { - goto exit; - } + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'a' in the clinic input of " \ + "'test_deprecate_positional_pos0_len1' to be keyword-only." + #elif PY_VERSION_HEX >= 0x030e00A0 + # ifdef _MSC_VER + # pragma message ( \ + "In clinic.test.c, update parameter(s) 'a' in the clinic input of " \ + "'test_deprecate_positional_pos0_len1' to be keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'a' in the clinic input of " \ + "'test_deprecate_positional_pos0_len1' to be keyword-only." + # endif + #endif + if (nargs == 1) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "Passing positional arguments to test_deprecate_positional_pos0_len1() " \ + "is deprecated. Parameter 'a' will become a keyword-only parameter in " \ + "Python 3.14.", 1)) + { + goto exit; + } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); if (!args) { goto exit; @@ -5846,7 +5846,7 @@ test_deprecate_positional_pos0_len1(PyObject *module, PyObject *const *args, Py_ static PyObject * test_deprecate_positional_pos0_len1_impl(PyObject *module, PyObject *a) -/*[clinic end generated code: output=2d69d62449a64bf9 input=678206db25c0652c]*/ +/*[clinic end generated code: output=e8df4559523e16f4 input=678206db25c0652c]*/ /*[clinic input] @@ -5901,29 +5901,29 @@ test_deprecate_positional_pos0_len2(PyObject *module, PyObject *const *args, Py_ PyObject *a; PyObject *b; - #if PY_VERSION_HEX >= 0x030e00C0 - # error \ - "In clinic.test.c, update parameter(s) 'a' and 'b' in the clinic input " \ - "of 'test_deprecate_positional_pos0_len2' to be keyword-only." - #elif PY_VERSION_HEX >= 0x030e00A0 - # ifdef _MSC_VER - # pragma message ( \ - "In clinic.test.c, update parameter(s) 'a' and 'b' in the clinic input " \ - "of 'test_deprecate_positional_pos0_len2' to be keyword-only.") - # else - # warning \ - "In clinic.test.c, update parameter(s) 'a' and 'b' in the clinic input " \ - "of 'test_deprecate_positional_pos0_len2' to be keyword-only." - # endif - #endif - if (nargs > 0 && nargs <= 2) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, \ - "Passing positional arguments to test_deprecate_positional_pos0_len2() " \ - "is deprecated. Parameters 'a' and 'b' will become keyword-only " \ - "parameters in Python 3.14.", 1)) - { - goto exit; - } + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'a' and 'b' in the clinic input " \ + "of 'test_deprecate_positional_pos0_len2' to be keyword-only." + #elif PY_VERSION_HEX >= 0x030e00A0 + # ifdef _MSC_VER + # pragma message ( \ + "In clinic.test.c, update parameter(s) 'a' and 'b' in the clinic input " \ + "of 'test_deprecate_positional_pos0_len2' to be keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'a' and 'b' in the clinic input " \ + "of 'test_deprecate_positional_pos0_len2' to be keyword-only." + # endif + #endif + if (nargs > 0 && nargs <= 2) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "Passing positional arguments to test_deprecate_positional_pos0_len2() " \ + "is deprecated. Parameters 'a' and 'b' will become keyword-only " \ + "parameters in Python 3.14.", 1)) + { + goto exit; + } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); if (!args) { goto exit; @@ -5939,7 +5939,7 @@ test_deprecate_positional_pos0_len2(PyObject *module, PyObject *const *args, Py_ static PyObject * test_deprecate_positional_pos0_len2_impl(PyObject *module, PyObject *a, PyObject *b) -/*[clinic end generated code: output=c57a186d00eaf931 input=fae0d0b1d480c939]*/ +/*[clinic end generated code: output=b2c6183a4ba100e3 input=fae0d0b1d480c939]*/ /*[clinic input] @@ -6003,33 +6003,33 @@ test_deprecate_positional_pos0_len3_with_kwdonly(PyObject *module, PyObject *con PyObject *c; PyObject *e; - #if PY_VERSION_HEX >= 0x030e00C0 - # error \ - "In clinic.test.c, update parameter(s) 'a', 'b' and 'c' in the clinic " \ - "input of 'test_deprecate_positional_pos0_len3_with_kwdonly' to be " \ - "keyword-only." - #elif PY_VERSION_HEX >= 0x030e00A0 - # ifdef _MSC_VER - # pragma message ( \ - "In clinic.test.c, update parameter(s) 'a', 'b' and 'c' in the clinic " \ - "input of 'test_deprecate_positional_pos0_len3_with_kwdonly' to be " \ - "keyword-only.") - # else - # warning \ - "In clinic.test.c, update parameter(s) 'a', 'b' and 'c' in the clinic " \ - "input of 'test_deprecate_positional_pos0_len3_with_kwdonly' to be " \ - "keyword-only." - # endif - #endif - if (nargs > 0 && nargs <= 3) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, \ - "Passing positional arguments to " \ - "test_deprecate_positional_pos0_len3_with_kwdonly() is deprecated. " \ - "Parameters 'a', 'b' and 'c' will become keyword-only parameters in " \ - "Python 3.14.", 1)) - { - goto exit; - } + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'a', 'b' and 'c' in the clinic " \ + "input of 'test_deprecate_positional_pos0_len3_with_kwdonly' to be " \ + "keyword-only." + #elif PY_VERSION_HEX >= 0x030e00A0 + # ifdef _MSC_VER + # pragma message ( \ + "In clinic.test.c, update parameter(s) 'a', 'b' and 'c' in the clinic " \ + "input of 'test_deprecate_positional_pos0_len3_with_kwdonly' to be " \ + "keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'a', 'b' and 'c' in the clinic " \ + "input of 'test_deprecate_positional_pos0_len3_with_kwdonly' to be " \ + "keyword-only." + # endif + #endif + if (nargs > 0 && nargs <= 3) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "Passing positional arguments to " \ + "test_deprecate_positional_pos0_len3_with_kwdonly() is deprecated. " \ + "Parameters 'a', 'b' and 'c' will become keyword-only parameters in " \ + "Python 3.14.", 1)) + { + goto exit; + } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 1, argsbuf); if (!args) { goto exit; @@ -6050,7 +6050,7 @@ test_deprecate_positional_pos0_len3_with_kwdonly_impl(PyObject *module, PyObject *b, PyObject *c, PyObject *e) -/*[clinic end generated code: output=cc96aff202cfcc40 input=1b0121770c0c52e0]*/ +/*[clinic end generated code: output=2504348d9c03f46c input=1b0121770c0c52e0]*/ /*[clinic input] @@ -6107,29 +6107,29 @@ test_deprecate_positional_pos2_len1(PyObject *module, PyObject *const *args, Py_ PyObject *b; PyObject *c; - #if PY_VERSION_HEX >= 0x030e00C0 - # error \ - "In clinic.test.c, update parameter(s) 'c' in the clinic input of " \ - "'test_deprecate_positional_pos2_len1' to be keyword-only." - #elif PY_VERSION_HEX >= 0x030e00A0 - # ifdef _MSC_VER - # pragma message ( \ - "In clinic.test.c, update parameter(s) 'c' in the clinic input of " \ - "'test_deprecate_positional_pos2_len1' to be keyword-only.") - # else - # warning \ - "In clinic.test.c, update parameter(s) 'c' in the clinic input of " \ - "'test_deprecate_positional_pos2_len1' to be keyword-only." - # endif - #endif - if (nargs == 3) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, \ - "Passing 3 positional arguments to " \ - "test_deprecate_positional_pos2_len1() is deprecated. Parameter 'c' " \ - "will become a keyword-only parameter in Python 3.14.", 1)) - { - goto exit; - } + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'c' in the clinic input of " \ + "'test_deprecate_positional_pos2_len1' to be keyword-only." + #elif PY_VERSION_HEX >= 0x030e00A0 + # ifdef _MSC_VER + # pragma message ( \ + "In clinic.test.c, update parameter(s) 'c' in the clinic input of " \ + "'test_deprecate_positional_pos2_len1' to be keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'c' in the clinic input of " \ + "'test_deprecate_positional_pos2_len1' to be keyword-only." + # endif + #endif + if (nargs == 3) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "Passing 3 positional arguments to " \ + "test_deprecate_positional_pos2_len1() is deprecated. Parameter 'c' " \ + "will become a keyword-only parameter in Python 3.14.", 1)) + { + goto exit; + } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); if (!args) { goto exit; @@ -6146,7 +6146,7 @@ test_deprecate_positional_pos2_len1(PyObject *module, PyObject *const *args, Py_ static PyObject * test_deprecate_positional_pos2_len1_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c) -/*[clinic end generated code: output=5ad40341de058b19 input=e1d129689e69ec7c]*/ +/*[clinic end generated code: output=8b90a7f6031698a5 input=e1d129689e69ec7c]*/ /*[clinic input] @@ -6206,29 +6206,29 @@ test_deprecate_positional_pos2_len2(PyObject *module, PyObject *const *args, Py_ PyObject *c; PyObject *d; - #if PY_VERSION_HEX >= 0x030e00C0 - # error \ - "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ - "of 'test_deprecate_positional_pos2_len2' to be keyword-only." - #elif PY_VERSION_HEX >= 0x030e00A0 - # ifdef _MSC_VER - # pragma message ( \ - "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ - "of 'test_deprecate_positional_pos2_len2' to be keyword-only.") - # else - # warning \ - "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ - "of 'test_deprecate_positional_pos2_len2' to be keyword-only." - # endif - #endif - if (nargs > 2 && nargs <= 4) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, \ - "Passing more than 2 positional arguments to " \ - "test_deprecate_positional_pos2_len2() is deprecated. Parameters 'c' " \ - "and 'd' will become keyword-only parameters in Python 3.14.", 1)) - { - goto exit; - } + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ + "of 'test_deprecate_positional_pos2_len2' to be keyword-only." + #elif PY_VERSION_HEX >= 0x030e00A0 + # ifdef _MSC_VER + # pragma message ( \ + "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ + "of 'test_deprecate_positional_pos2_len2' to be keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ + "of 'test_deprecate_positional_pos2_len2' to be keyword-only." + # endif + #endif + if (nargs > 2 && nargs <= 4) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "Passing more than 2 positional arguments to " \ + "test_deprecate_positional_pos2_len2() is deprecated. Parameters 'c' " \ + "and 'd' will become keyword-only parameters in Python 3.14.", 1)) + { + goto exit; + } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 4, 0, argsbuf); if (!args) { goto exit; @@ -6247,7 +6247,7 @@ static PyObject * test_deprecate_positional_pos2_len2_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c, PyObject *d) -/*[clinic end generated code: output=593d77137bd117cb input=0d53533463a12792]*/ +/*[clinic end generated code: output=2e7da298a880b499 input=0d53533463a12792]*/ /*[clinic input] @@ -6314,33 +6314,33 @@ test_deprecate_positional_pos2_len3_with_kwdonly(PyObject *module, PyObject *con PyObject *d; PyObject *e; - #if PY_VERSION_HEX >= 0x030e00C0 - # error \ - "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ - "of 'test_deprecate_positional_pos2_len3_with_kwdonly' to be " \ - "keyword-only." - #elif PY_VERSION_HEX >= 0x030e00A0 - # ifdef _MSC_VER - # pragma message ( \ - "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ - "of 'test_deprecate_positional_pos2_len3_with_kwdonly' to be " \ - "keyword-only.") - # else - # warning \ - "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ - "of 'test_deprecate_positional_pos2_len3_with_kwdonly' to be " \ - "keyword-only." - # endif - #endif - if (nargs > 2 && nargs <= 4) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, \ - "Passing more than 2 positional arguments to " \ - "test_deprecate_positional_pos2_len3_with_kwdonly() is deprecated. " \ - "Parameters 'c' and 'd' will become keyword-only parameters in Python " \ - "3.14.", 1)) - { - goto exit; - } + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ + "of 'test_deprecate_positional_pos2_len3_with_kwdonly' to be " \ + "keyword-only." + #elif PY_VERSION_HEX >= 0x030e00A0 + # ifdef _MSC_VER + # pragma message ( \ + "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ + "of 'test_deprecate_positional_pos2_len3_with_kwdonly' to be " \ + "keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ + "of 'test_deprecate_positional_pos2_len3_with_kwdonly' to be " \ + "keyword-only." + # endif + #endif + if (nargs > 2 && nargs <= 4) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "Passing more than 2 positional arguments to " \ + "test_deprecate_positional_pos2_len3_with_kwdonly() is deprecated. " \ + "Parameters 'c' and 'd' will become keyword-only parameters in Python " \ + "3.14.", 1)) + { + goto exit; + } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 4, 1, argsbuf); if (!args) { goto exit; @@ -6363,4 +6363,4 @@ test_deprecate_positional_pos2_len3_with_kwdonly_impl(PyObject *module, PyObject *c, PyObject *d, PyObject *e) -/*[clinic end generated code: output=2bbf3e16262d2012 input=154fd450448d8935]*/ +/*[clinic end generated code: output=c6962f8980227a21 input=154fd450448d8935]*/ diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index c26dc4cd1b09fd..cbd657d09a4773 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -221,13 +221,23 @@ def c_repr(s: str) -> str: return '"' + s + '"' -def wrapped_c_string_literal(line, width=72): +def wrapped_c_string_literal( + line: str, + width: int = 72, + indent: int = 0, + subsequent_indent: int = 4 +) -> str: add, out = text_accumulator() words = line.split(' ') - add(' \\\n') + first = True while True: + if first: + add(' ' * indent) + first = False + else: + add(' ' * subsequent_indent) add('"') - sz = 1 + sz = indent + 1 while True: try: word = words[0] @@ -862,16 +872,20 @@ class CLanguage(Language): """) DEPRECATED_POSITIONAL_PROTOTYPE: Final[str] = r""" #if PY_VERSION_HEX >= 0x{major:02x}{minor:02x}00C0 - # error {cpp_message} + # error \ + {cpp_message} #elif PY_VERSION_HEX >= 0x{major:02x}{minor:02x}00A0 # ifdef _MSC_VER - # pragma message ({cpp_message}) + # pragma message ( \ + {cpp_message}) # else - # warning {cpp_message} + # warning \ + {cpp_message} # endif #endif if ({condition}) {{{{ - if (PyErr_WarnEx(PyExc_DeprecationWarning, {depr_message}, 1)) + if (PyErr_WarnEx(PyExc_DeprecationWarning, + {depr_message}, 1)) {{{{ goto exit; }}}} @@ -952,8 +966,10 @@ def deprecate_positional_use( condition=condition, major=major, minor=minor, - cpp_message=wrapped_c_string_literal(cpp_message), - depr_message=wrapped_c_string_literal(depr_message), + cpp_message=wrapped_c_string_literal(cpp_message, + subsequent_indent=16), + depr_message=wrapped_c_string_literal(depr_message, + subsequent_indent=29), ) return normalize_snippet(code, indent=4) From 3e24974aa4deae6b7c166584321fde5f95734188 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 7 Aug 2023 13:57:13 +0200 Subject: [PATCH 3/8] Escapes are only needed for preprocessor code --- Lib/test/clinic.test.c | 60 +++++++++++++++++++++--------------------- Tools/clinic/clinic.py | 5 ++-- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c index c6885324cf5914..776411844da89e 100644 --- a/Lib/test/clinic.test.c +++ b/Lib/test/clinic.test.c @@ -5537,8 +5537,8 @@ test_deprecate_positional_pos1_len1_optional(PyObject *module, PyObject *const * #endif if (nargs == 2) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing 2 positional arguments to " \ - "test_deprecate_positional_pos1_len1_optional() is deprecated. " \ + "Passing 2 positional arguments to " + "test_deprecate_positional_pos1_len1_optional() is deprecated. " "Parameter 'b' will become a keyword-only parameter in Python 3.14.", 1)) { goto exit; @@ -5562,7 +5562,7 @@ test_deprecate_positional_pos1_len1_optional(PyObject *module, PyObject *const * static PyObject * test_deprecate_positional_pos1_len1_optional_impl(PyObject *module, PyObject *a, PyObject *b) -/*[clinic end generated code: output=8ff8fda7f3f10aa6 input=89099f3dacd757da]*/ +/*[clinic end generated code: output=862743ccf359e467 input=89099f3dacd757da]*/ /*[clinic input] @@ -5634,8 +5634,8 @@ test_deprecate_positional_pos1_len1(PyObject *module, PyObject *const *args, Py_ #endif if (nargs == 2) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing 2 positional arguments to " \ - "test_deprecate_positional_pos1_len1() is deprecated. Parameter 'b' " \ + "Passing 2 positional arguments to " + "test_deprecate_positional_pos1_len1() is deprecated. Parameter 'b' " "will become a keyword-only parameter in Python 3.14.", 1)) { goto exit; @@ -5655,7 +5655,7 @@ test_deprecate_positional_pos1_len1(PyObject *module, PyObject *const *args, Py_ static PyObject * test_deprecate_positional_pos1_len1_impl(PyObject *module, PyObject *a, PyObject *b) -/*[clinic end generated code: output=170fe98f2d6e2711 input=1702bbab1e9b3b99]*/ +/*[clinic end generated code: output=a2963e60fc291de7 input=1702bbab1e9b3b99]*/ /*[clinic input] @@ -5733,9 +5733,9 @@ test_deprecate_positional_pos1_len2_with_kwd(PyObject *module, PyObject *const * #endif if (nargs > 1 && nargs <= 3) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing more than 1 positional argument to " \ - "test_deprecate_positional_pos1_len2_with_kwd() is deprecated. " \ - "Parameters 'b' and 'c' will become keyword-only parameters in Python " \ + "Passing more than 1 positional argument to " + "test_deprecate_positional_pos1_len2_with_kwd() is deprecated. " + "Parameters 'b' and 'c' will become keyword-only parameters in Python " "3.14.", 1)) { goto exit; @@ -5758,7 +5758,7 @@ static PyObject * test_deprecate_positional_pos1_len2_with_kwd_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c, PyObject *d) -/*[clinic end generated code: output=b4c0595ec15619a3 input=28cdb885f6c34eab]*/ +/*[clinic end generated code: output=277f633ed6d46e75 input=28cdb885f6c34eab]*/ /*[clinic input] @@ -5827,8 +5827,8 @@ test_deprecate_positional_pos0_len1(PyObject *module, PyObject *const *args, Py_ #endif if (nargs == 1) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing positional arguments to test_deprecate_positional_pos0_len1() " \ - "is deprecated. Parameter 'a' will become a keyword-only parameter in " \ + "Passing positional arguments to test_deprecate_positional_pos0_len1() " + "is deprecated. Parameter 'a' will become a keyword-only parameter in " "Python 3.14.", 1)) { goto exit; @@ -5846,7 +5846,7 @@ test_deprecate_positional_pos0_len1(PyObject *module, PyObject *const *args, Py_ static PyObject * test_deprecate_positional_pos0_len1_impl(PyObject *module, PyObject *a) -/*[clinic end generated code: output=e8df4559523e16f4 input=678206db25c0652c]*/ +/*[clinic end generated code: output=05d36044c05396e0 input=678206db25c0652c]*/ /*[clinic input] @@ -5918,8 +5918,8 @@ test_deprecate_positional_pos0_len2(PyObject *module, PyObject *const *args, Py_ #endif if (nargs > 0 && nargs <= 2) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing positional arguments to test_deprecate_positional_pos0_len2() " \ - "is deprecated. Parameters 'a' and 'b' will become keyword-only " \ + "Passing positional arguments to test_deprecate_positional_pos0_len2() " + "is deprecated. Parameters 'a' and 'b' will become keyword-only " "parameters in Python 3.14.", 1)) { goto exit; @@ -5939,7 +5939,7 @@ test_deprecate_positional_pos0_len2(PyObject *module, PyObject *const *args, Py_ static PyObject * test_deprecate_positional_pos0_len2_impl(PyObject *module, PyObject *a, PyObject *b) -/*[clinic end generated code: output=b2c6183a4ba100e3 input=fae0d0b1d480c939]*/ +/*[clinic end generated code: output=a33ee0b9ec8e1d96 input=fae0d0b1d480c939]*/ /*[clinic input] @@ -6023,9 +6023,9 @@ test_deprecate_positional_pos0_len3_with_kwdonly(PyObject *module, PyObject *con #endif if (nargs > 0 && nargs <= 3) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing positional arguments to " \ - "test_deprecate_positional_pos0_len3_with_kwdonly() is deprecated. " \ - "Parameters 'a', 'b' and 'c' will become keyword-only parameters in " \ + "Passing positional arguments to " + "test_deprecate_positional_pos0_len3_with_kwdonly() is deprecated. " + "Parameters 'a', 'b' and 'c' will become keyword-only parameters in " "Python 3.14.", 1)) { goto exit; @@ -6050,7 +6050,7 @@ test_deprecate_positional_pos0_len3_with_kwdonly_impl(PyObject *module, PyObject *b, PyObject *c, PyObject *e) -/*[clinic end generated code: output=2504348d9c03f46c input=1b0121770c0c52e0]*/ +/*[clinic end generated code: output=24d865ef46897afd input=1b0121770c0c52e0]*/ /*[clinic input] @@ -6124,8 +6124,8 @@ test_deprecate_positional_pos2_len1(PyObject *module, PyObject *const *args, Py_ #endif if (nargs == 3) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing 3 positional arguments to " \ - "test_deprecate_positional_pos2_len1() is deprecated. Parameter 'c' " \ + "Passing 3 positional arguments to " + "test_deprecate_positional_pos2_len1() is deprecated. Parameter 'c' " "will become a keyword-only parameter in Python 3.14.", 1)) { goto exit; @@ -6146,7 +6146,7 @@ test_deprecate_positional_pos2_len1(PyObject *module, PyObject *const *args, Py_ static PyObject * test_deprecate_positional_pos2_len1_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c) -/*[clinic end generated code: output=8b90a7f6031698a5 input=e1d129689e69ec7c]*/ +/*[clinic end generated code: output=58e71c08abc28074 input=e1d129689e69ec7c]*/ /*[clinic input] @@ -6223,8 +6223,8 @@ test_deprecate_positional_pos2_len2(PyObject *module, PyObject *const *args, Py_ #endif if (nargs > 2 && nargs <= 4) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing more than 2 positional arguments to " \ - "test_deprecate_positional_pos2_len2() is deprecated. Parameters 'c' " \ + "Passing more than 2 positional arguments to " + "test_deprecate_positional_pos2_len2() is deprecated. Parameters 'c' " "and 'd' will become keyword-only parameters in Python 3.14.", 1)) { goto exit; @@ -6247,7 +6247,7 @@ static PyObject * test_deprecate_positional_pos2_len2_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c, PyObject *d) -/*[clinic end generated code: output=2e7da298a880b499 input=0d53533463a12792]*/ +/*[clinic end generated code: output=0717b6f995cb8eb9 input=0d53533463a12792]*/ /*[clinic input] @@ -6334,9 +6334,9 @@ test_deprecate_positional_pos2_len3_with_kwdonly(PyObject *module, PyObject *con #endif if (nargs > 2 && nargs <= 4) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing more than 2 positional arguments to " \ - "test_deprecate_positional_pos2_len3_with_kwdonly() is deprecated. " \ - "Parameters 'c' and 'd' will become keyword-only parameters in Python " \ + "Passing more than 2 positional arguments to " + "test_deprecate_positional_pos2_len3_with_kwdonly() is deprecated. " + "Parameters 'c' and 'd' will become keyword-only parameters in Python " "3.14.", 1)) { goto exit; @@ -6363,4 +6363,4 @@ test_deprecate_positional_pos2_len3_with_kwdonly_impl(PyObject *module, PyObject *c, PyObject *d, PyObject *e) -/*[clinic end generated code: output=c6962f8980227a21 input=154fd450448d8935]*/ +/*[clinic end generated code: output=2dd67e54b0fb59a2 input=154fd450448d8935]*/ diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index cbd657d09a4773..747645aa3c4057 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -225,6 +225,7 @@ def wrapped_c_string_literal( line: str, width: int = 72, indent: int = 0, + suffix: str = '', subsequent_indent: int = 4 ) -> str: add, out = text_accumulator() @@ -252,7 +253,7 @@ def wrapped_c_string_literal( if words: add(' ') add('"') - add(' \\') + add(suffix) add('\n') @@ -966,7 +967,7 @@ def deprecate_positional_use( condition=condition, major=major, minor=minor, - cpp_message=wrapped_c_string_literal(cpp_message, + cpp_message=wrapped_c_string_literal(cpp_message, suffix=" \\", subsequent_indent=16), depr_message=wrapped_c_string_literal(depr_message, subsequent_indent=29), From 68c1b1ed49deef52a22f900f6beb088567d1d70c Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 7 Aug 2023 13:59:10 +0200 Subject: [PATCH 4/8] width iso. literal --- 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 747645aa3c4057..d53b07e1e53d92 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -246,7 +246,7 @@ def wrapped_c_string_literal( add('"') return out() sz += len(word) + 1 - if sz > 72: + if sz > width: break add(word) del words[0] From 3de23788462dabdaa56af65d159f525fa6586df7 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 7 Aug 2023 14:57:56 +0200 Subject: [PATCH 5/8] Compact version --- Tools/clinic/clinic.py | 39 ++++++++++----------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index d53b07e1e53d92..52a4af309975c4 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -222,39 +222,20 @@ def c_repr(s: str) -> str: def wrapped_c_string_literal( - line: str, + text: str, + *, width: int = 72, - indent: int = 0, suffix: str = '', + initial_indent: int = 0, subsequent_indent: int = 4 ) -> str: - add, out = text_accumulator() - words = line.split(' ') - first = True - while True: - if first: - add(' ' * indent) - first = False - else: - add(' ' * subsequent_indent) - add('"') - sz = indent + 1 - while True: - try: - word = words[0] - except IndexError: - add('"') - return out() - sz += len(word) + 1 - if sz > width: - break - add(word) - del words[0] - if words: - add(' ') - add('"') - add(suffix) - add('\n') + wrapped = textwrap.wrap(text, replace_whitespace=False, + drop_whitespace=False, break_on_hyphens=False) + suffix = f"{suffix}\n" + lines = [f'"{line}"{suffix}' for line in wrapped] + separator = subsequent_indent * ' ' + joined = initial_indent * ' ' + separator.join(lines) + return joined.removesuffix(suffix) is_legal_c_identifier = re.compile('^[A-Za-z_][A-Za-z0-9_]*$').match From b4cebfdbd4f6c21fd1d1631b7902bba5045c0571 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 7 Aug 2023 14:58:58 +0200 Subject: [PATCH 6/8] Slightly nicer --- 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 52a4af309975c4..d9c4ee5b0332b3 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -231,7 +231,7 @@ def wrapped_c_string_literal( ) -> str: wrapped = textwrap.wrap(text, replace_whitespace=False, drop_whitespace=False, break_on_hyphens=False) - suffix = f"{suffix}\n" + suffix += "\n" lines = [f'"{line}"{suffix}' for line in wrapped] separator = subsequent_indent * ' ' joined = initial_indent * ' ' + separator.join(lines) From 4fc27a94e8f363f542c6708436d25e50cfbc9660 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 7 Aug 2023 15:07:24 +0200 Subject: [PATCH 7/8] Slightly nicer --- Lib/test/clinic.test.c | 253 ++++++++++++++++++++++------------------- Tools/clinic/clinic.py | 14 ++- 2 files changed, 147 insertions(+), 120 deletions(-) diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c index 776411844da89e..c5c37b7e9e2168 100644 --- a/Lib/test/clinic.test.c +++ b/Lib/test/clinic.test.c @@ -5522,26 +5522,31 @@ test_deprecate_positional_pos1_len1_optional(PyObject *module, PyObject *const * #if PY_VERSION_HEX >= 0x030e00C0 # error \ - "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ - "'test_deprecate_positional_pos1_len1_optional' to be keyword-only." + "In clinic.test.c, update parameter(s) 'b' in the clinic input of" \ + " 'test_deprecate_positional_pos1_len1_optional' to be " \ + "keyword-only." #elif PY_VERSION_HEX >= 0x030e00A0 # ifdef _MSC_VER # pragma message ( \ - "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ - "'test_deprecate_positional_pos1_len1_optional' to be keyword-only.") + "In clinic.test.c, update parameter(s) 'b' in the clinic input of" \ + " 'test_deprecate_positional_pos1_len1_optional' to be " \ + "keyword-only.") # else # warning \ - "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ - "'test_deprecate_positional_pos1_len1_optional' to be keyword-only." + "In clinic.test.c, update parameter(s) 'b' in the clinic input of" \ + " 'test_deprecate_positional_pos1_len1_optional' to be " \ + "keyword-only." # endif #endif if (nargs == 2) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing 2 positional arguments to " - "test_deprecate_positional_pos1_len1_optional() is deprecated. " - "Parameter 'b' will become a keyword-only parameter in Python 3.14.", 1)) - { - goto exit; + "Passing 2 positional arguments to " + "test_deprecate_positional_pos1_len1_optional() is deprecated. " + "Parameter 'b' will become a keyword-only parameter in Python " + "3.14.", 1)) + { + goto exit; + } } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); if (!args) { @@ -5562,7 +5567,7 @@ test_deprecate_positional_pos1_len1_optional(PyObject *module, PyObject *const * static PyObject * test_deprecate_positional_pos1_len1_optional_impl(PyObject *module, PyObject *a, PyObject *b) -/*[clinic end generated code: output=862743ccf359e467 input=89099f3dacd757da]*/ +/*[clinic end generated code: output=09a6edec1ddcd469 input=89099f3dacd757da]*/ /*[clinic input] @@ -5619,26 +5624,27 @@ test_deprecate_positional_pos1_len1(PyObject *module, PyObject *const *args, Py_ #if PY_VERSION_HEX >= 0x030e00C0 # error \ - "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ - "'test_deprecate_positional_pos1_len1' to be keyword-only." + "In clinic.test.c, update parameter(s) 'b' in the clinic input of" \ + " 'test_deprecate_positional_pos1_len1' to be keyword-only." #elif PY_VERSION_HEX >= 0x030e00A0 # ifdef _MSC_VER # pragma message ( \ - "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ - "'test_deprecate_positional_pos1_len1' to be keyword-only.") + "In clinic.test.c, update parameter(s) 'b' in the clinic input of" \ + " 'test_deprecate_positional_pos1_len1' to be keyword-only.") # else # warning \ - "In clinic.test.c, update parameter(s) 'b' in the clinic input of " \ - "'test_deprecate_positional_pos1_len1' to be keyword-only." + "In clinic.test.c, update parameter(s) 'b' in the clinic input of" \ + " 'test_deprecate_positional_pos1_len1' to be keyword-only." # endif #endif if (nargs == 2) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing 2 positional arguments to " - "test_deprecate_positional_pos1_len1() is deprecated. Parameter 'b' " - "will become a keyword-only parameter in Python 3.14.", 1)) - { - goto exit; + "Passing 2 positional arguments to " + "test_deprecate_positional_pos1_len1() is deprecated. Parameter " + "'b' will become a keyword-only parameter in Python 3.14.", 1)) + { + goto exit; + } } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); if (!args) { @@ -5655,7 +5661,7 @@ test_deprecate_positional_pos1_len1(PyObject *module, PyObject *const *args, Py_ static PyObject * test_deprecate_positional_pos1_len1_impl(PyObject *module, PyObject *a, PyObject *b) -/*[clinic end generated code: output=a2963e60fc291de7 input=1702bbab1e9b3b99]*/ +/*[clinic end generated code: output=52a2618293df747d input=1702bbab1e9b3b99]*/ /*[clinic input] @@ -5718,27 +5724,31 @@ test_deprecate_positional_pos1_len2_with_kwd(PyObject *module, PyObject *const * #if PY_VERSION_HEX >= 0x030e00C0 # error \ - "In clinic.test.c, update parameter(s) 'b' and 'c' in the clinic input " \ - "of 'test_deprecate_positional_pos1_len2_with_kwd' to be keyword-only." + "In clinic.test.c, update parameter(s) 'b' and 'c' in the clinic " \ + "input of 'test_deprecate_positional_pos1_len2_with_kwd' to be " \ + "keyword-only." #elif PY_VERSION_HEX >= 0x030e00A0 # ifdef _MSC_VER # pragma message ( \ - "In clinic.test.c, update parameter(s) 'b' and 'c' in the clinic input " \ - "of 'test_deprecate_positional_pos1_len2_with_kwd' to be keyword-only.") + "In clinic.test.c, update parameter(s) 'b' and 'c' in the clinic " \ + "input of 'test_deprecate_positional_pos1_len2_with_kwd' to be " \ + "keyword-only.") # else # warning \ - "In clinic.test.c, update parameter(s) 'b' and 'c' in the clinic input " \ - "of 'test_deprecate_positional_pos1_len2_with_kwd' to be keyword-only." + "In clinic.test.c, update parameter(s) 'b' and 'c' in the clinic " \ + "input of 'test_deprecate_positional_pos1_len2_with_kwd' to be " \ + "keyword-only." # endif #endif if (nargs > 1 && nargs <= 3) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing more than 1 positional argument to " - "test_deprecate_positional_pos1_len2_with_kwd() is deprecated. " - "Parameters 'b' and 'c' will become keyword-only parameters in Python " - "3.14.", 1)) - { - goto exit; + "Passing more than 1 positional argument to " + "test_deprecate_positional_pos1_len2_with_kwd() is deprecated. " + "Parameters 'b' and 'c' will become keyword-only parameters in " + "Python 3.14.", 1)) + { + goto exit; + } } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 1, argsbuf); if (!args) { @@ -5758,7 +5768,7 @@ static PyObject * test_deprecate_positional_pos1_len2_with_kwd_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c, PyObject *d) -/*[clinic end generated code: output=277f633ed6d46e75 input=28cdb885f6c34eab]*/ +/*[clinic end generated code: output=550aabea548589b4 input=28cdb885f6c34eab]*/ /*[clinic input] @@ -5812,26 +5822,27 @@ test_deprecate_positional_pos0_len1(PyObject *module, PyObject *const *args, Py_ #if PY_VERSION_HEX >= 0x030e00C0 # error \ - "In clinic.test.c, update parameter(s) 'a' in the clinic input of " \ - "'test_deprecate_positional_pos0_len1' to be keyword-only." + "In clinic.test.c, update parameter(s) 'a' in the clinic input of" \ + " 'test_deprecate_positional_pos0_len1' to be keyword-only." #elif PY_VERSION_HEX >= 0x030e00A0 # ifdef _MSC_VER # pragma message ( \ - "In clinic.test.c, update parameter(s) 'a' in the clinic input of " \ - "'test_deprecate_positional_pos0_len1' to be keyword-only.") + "In clinic.test.c, update parameter(s) 'a' in the clinic input of" \ + " 'test_deprecate_positional_pos0_len1' to be keyword-only.") # else # warning \ - "In clinic.test.c, update parameter(s) 'a' in the clinic input of " \ - "'test_deprecate_positional_pos0_len1' to be keyword-only." + "In clinic.test.c, update parameter(s) 'a' in the clinic input of" \ + " 'test_deprecate_positional_pos0_len1' to be keyword-only." # endif #endif if (nargs == 1) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing positional arguments to test_deprecate_positional_pos0_len1() " - "is deprecated. Parameter 'a' will become a keyword-only parameter in " - "Python 3.14.", 1)) - { - goto exit; + "Passing positional arguments to " + "test_deprecate_positional_pos0_len1() is deprecated. Parameter " + "'a' will become a keyword-only parameter in Python 3.14.", 1)) + { + goto exit; + } } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); if (!args) { @@ -5846,7 +5857,7 @@ test_deprecate_positional_pos0_len1(PyObject *module, PyObject *const *args, Py_ static PyObject * test_deprecate_positional_pos0_len1_impl(PyObject *module, PyObject *a) -/*[clinic end generated code: output=05d36044c05396e0 input=678206db25c0652c]*/ +/*[clinic end generated code: output=66c63ec8d6903bde input=678206db25c0652c]*/ /*[clinic input] @@ -5903,26 +5914,30 @@ test_deprecate_positional_pos0_len2(PyObject *module, PyObject *const *args, Py_ #if PY_VERSION_HEX >= 0x030e00C0 # error \ - "In clinic.test.c, update parameter(s) 'a' and 'b' in the clinic input " \ - "of 'test_deprecate_positional_pos0_len2' to be keyword-only." + "In clinic.test.c, update parameter(s) 'a' and 'b' in the clinic " \ + "input of 'test_deprecate_positional_pos0_len2' to be " \ + "keyword-only." #elif PY_VERSION_HEX >= 0x030e00A0 # ifdef _MSC_VER # pragma message ( \ - "In clinic.test.c, update parameter(s) 'a' and 'b' in the clinic input " \ - "of 'test_deprecate_positional_pos0_len2' to be keyword-only.") + "In clinic.test.c, update parameter(s) 'a' and 'b' in the clinic " \ + "input of 'test_deprecate_positional_pos0_len2' to be " \ + "keyword-only.") # else # warning \ - "In clinic.test.c, update parameter(s) 'a' and 'b' in the clinic input " \ - "of 'test_deprecate_positional_pos0_len2' to be keyword-only." + "In clinic.test.c, update parameter(s) 'a' and 'b' in the clinic " \ + "input of 'test_deprecate_positional_pos0_len2' to be " \ + "keyword-only." # endif #endif if (nargs > 0 && nargs <= 2) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing positional arguments to test_deprecate_positional_pos0_len2() " - "is deprecated. Parameters 'a' and 'b' will become keyword-only " - "parameters in Python 3.14.", 1)) - { - goto exit; + "Passing positional arguments to " + "test_deprecate_positional_pos0_len2() is deprecated. Parameters " + "'a' and 'b' will become keyword-only parameters in Python 3.14.", 1)) + { + goto exit; + } } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); if (!args) { @@ -5939,7 +5954,7 @@ test_deprecate_positional_pos0_len2(PyObject *module, PyObject *const *args, Py_ static PyObject * test_deprecate_positional_pos0_len2_impl(PyObject *module, PyObject *a, PyObject *b) -/*[clinic end generated code: output=a33ee0b9ec8e1d96 input=fae0d0b1d480c939]*/ +/*[clinic end generated code: output=6b6df40aaf751b2e input=fae0d0b1d480c939]*/ /*[clinic input] @@ -6005,30 +6020,34 @@ test_deprecate_positional_pos0_len3_with_kwdonly(PyObject *module, PyObject *con #if PY_VERSION_HEX >= 0x030e00C0 # error \ - "In clinic.test.c, update parameter(s) 'a', 'b' and 'c' in the clinic " \ - "input of 'test_deprecate_positional_pos0_len3_with_kwdonly' to be " \ + "In clinic.test.c, update parameter(s) 'a', 'b' and 'c' in the " \ + "clinic input of " \ + "'test_deprecate_positional_pos0_len3_with_kwdonly' to be " \ "keyword-only." #elif PY_VERSION_HEX >= 0x030e00A0 # ifdef _MSC_VER # pragma message ( \ - "In clinic.test.c, update parameter(s) 'a', 'b' and 'c' in the clinic " \ - "input of 'test_deprecate_positional_pos0_len3_with_kwdonly' to be " \ + "In clinic.test.c, update parameter(s) 'a', 'b' and 'c' in the " \ + "clinic input of " \ + "'test_deprecate_positional_pos0_len3_with_kwdonly' to be " \ "keyword-only.") # else # warning \ - "In clinic.test.c, update parameter(s) 'a', 'b' and 'c' in the clinic " \ - "input of 'test_deprecate_positional_pos0_len3_with_kwdonly' to be " \ + "In clinic.test.c, update parameter(s) 'a', 'b' and 'c' in the " \ + "clinic input of " \ + "'test_deprecate_positional_pos0_len3_with_kwdonly' to be " \ "keyword-only." # endif #endif if (nargs > 0 && nargs <= 3) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing positional arguments to " - "test_deprecate_positional_pos0_len3_with_kwdonly() is deprecated. " - "Parameters 'a', 'b' and 'c' will become keyword-only parameters in " - "Python 3.14.", 1)) - { - goto exit; + "Passing positional arguments to " + "test_deprecate_positional_pos0_len3_with_kwdonly() is " + "deprecated. Parameters 'a', 'b' and 'c' will become keyword-only" + " parameters in Python 3.14.", 1)) + { + goto exit; + } } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 1, argsbuf); if (!args) { @@ -6050,7 +6069,7 @@ test_deprecate_positional_pos0_len3_with_kwdonly_impl(PyObject *module, PyObject *b, PyObject *c, PyObject *e) -/*[clinic end generated code: output=24d865ef46897afd input=1b0121770c0c52e0]*/ +/*[clinic end generated code: output=5c936993846d01a3 input=1b0121770c0c52e0]*/ /*[clinic input] @@ -6109,26 +6128,27 @@ test_deprecate_positional_pos2_len1(PyObject *module, PyObject *const *args, Py_ #if PY_VERSION_HEX >= 0x030e00C0 # error \ - "In clinic.test.c, update parameter(s) 'c' in the clinic input of " \ - "'test_deprecate_positional_pos2_len1' to be keyword-only." + "In clinic.test.c, update parameter(s) 'c' in the clinic input of" \ + " 'test_deprecate_positional_pos2_len1' to be keyword-only." #elif PY_VERSION_HEX >= 0x030e00A0 # ifdef _MSC_VER # pragma message ( \ - "In clinic.test.c, update parameter(s) 'c' in the clinic input of " \ - "'test_deprecate_positional_pos2_len1' to be keyword-only.") + "In clinic.test.c, update parameter(s) 'c' in the clinic input of" \ + " 'test_deprecate_positional_pos2_len1' to be keyword-only.") # else # warning \ - "In clinic.test.c, update parameter(s) 'c' in the clinic input of " \ - "'test_deprecate_positional_pos2_len1' to be keyword-only." + "In clinic.test.c, update parameter(s) 'c' in the clinic input of" \ + " 'test_deprecate_positional_pos2_len1' to be keyword-only." # endif #endif if (nargs == 3) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing 3 positional arguments to " - "test_deprecate_positional_pos2_len1() is deprecated. Parameter 'c' " - "will become a keyword-only parameter in Python 3.14.", 1)) - { - goto exit; + "Passing 3 positional arguments to " + "test_deprecate_positional_pos2_len1() is deprecated. Parameter " + "'c' will become a keyword-only parameter in Python 3.14.", 1)) + { + goto exit; + } } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); if (!args) { @@ -6146,7 +6166,7 @@ test_deprecate_positional_pos2_len1(PyObject *module, PyObject *const *args, Py_ static PyObject * test_deprecate_positional_pos2_len1_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c) -/*[clinic end generated code: output=58e71c08abc28074 input=e1d129689e69ec7c]*/ +/*[clinic end generated code: output=2641e037296e3b61 input=e1d129689e69ec7c]*/ /*[clinic input] @@ -6208,26 +6228,30 @@ test_deprecate_positional_pos2_len2(PyObject *module, PyObject *const *args, Py_ #if PY_VERSION_HEX >= 0x030e00C0 # error \ - "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ - "of 'test_deprecate_positional_pos2_len2' to be keyword-only." + "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic " \ + "input of 'test_deprecate_positional_pos2_len2' to be " \ + "keyword-only." #elif PY_VERSION_HEX >= 0x030e00A0 # ifdef _MSC_VER # pragma message ( \ - "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ - "of 'test_deprecate_positional_pos2_len2' to be keyword-only.") + "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic " \ + "input of 'test_deprecate_positional_pos2_len2' to be " \ + "keyword-only.") # else # warning \ - "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ - "of 'test_deprecate_positional_pos2_len2' to be keyword-only." + "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic " \ + "input of 'test_deprecate_positional_pos2_len2' to be " \ + "keyword-only." # endif #endif if (nargs > 2 && nargs <= 4) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing more than 2 positional arguments to " - "test_deprecate_positional_pos2_len2() is deprecated. Parameters 'c' " - "and 'd' will become keyword-only parameters in Python 3.14.", 1)) - { - goto exit; + "Passing more than 2 positional arguments to " + "test_deprecate_positional_pos2_len2() is deprecated. Parameters " + "'c' and 'd' will become keyword-only parameters in Python 3.14.", 1)) + { + goto exit; + } } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 4, 0, argsbuf); if (!args) { @@ -6247,7 +6271,7 @@ static PyObject * test_deprecate_positional_pos2_len2_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c, PyObject *d) -/*[clinic end generated code: output=0717b6f995cb8eb9 input=0d53533463a12792]*/ +/*[clinic end generated code: output=4a9068ef8fee61f6 input=0d53533463a12792]*/ /*[clinic input] @@ -6316,30 +6340,31 @@ test_deprecate_positional_pos2_len3_with_kwdonly(PyObject *module, PyObject *con #if PY_VERSION_HEX >= 0x030e00C0 # error \ - "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ - "of 'test_deprecate_positional_pos2_len3_with_kwdonly' to be " \ - "keyword-only." + "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic " \ + "input of 'test_deprecate_positional_pos2_len3_with_kwdonly' to " \ + "be keyword-only." #elif PY_VERSION_HEX >= 0x030e00A0 # ifdef _MSC_VER # pragma message ( \ - "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ - "of 'test_deprecate_positional_pos2_len3_with_kwdonly' to be " \ - "keyword-only.") + "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic " \ + "input of 'test_deprecate_positional_pos2_len3_with_kwdonly' to " \ + "be keyword-only.") # else # warning \ - "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic input " \ - "of 'test_deprecate_positional_pos2_len3_with_kwdonly' to be " \ - "keyword-only." + "In clinic.test.c, update parameter(s) 'c' and 'd' in the clinic " \ + "input of 'test_deprecate_positional_pos2_len3_with_kwdonly' to " \ + "be keyword-only." # endif #endif if (nargs > 2 && nargs <= 4) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing more than 2 positional arguments to " - "test_deprecate_positional_pos2_len3_with_kwdonly() is deprecated. " - "Parameters 'c' and 'd' will become keyword-only parameters in Python " - "3.14.", 1)) - { - goto exit; + "Passing more than 2 positional arguments to " + "test_deprecate_positional_pos2_len3_with_kwdonly() is " + "deprecated. Parameters 'c' and 'd' will become keyword-only " + "parameters in Python 3.14.", 1)) + { + goto exit; + } } args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 4, 1, argsbuf); if (!args) { @@ -6363,4 +6388,4 @@ test_deprecate_positional_pos2_len3_with_kwdonly_impl(PyObject *module, PyObject *c, PyObject *d, PyObject *e) -/*[clinic end generated code: output=2dd67e54b0fb59a2 input=154fd450448d8935]*/ +/*[clinic end generated code: output=1154c2e3e798948c input=154fd450448d8935]*/ diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index d9c4ee5b0332b3..7b22a10e7c265e 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -229,7 +229,7 @@ def wrapped_c_string_literal( initial_indent: int = 0, subsequent_indent: int = 4 ) -> str: - wrapped = textwrap.wrap(text, replace_whitespace=False, + wrapped = textwrap.wrap(text, width=width, replace_whitespace=False, drop_whitespace=False, break_on_hyphens=False) suffix += "\n" lines = [f'"{line}"{suffix}' for line in wrapped] @@ -867,9 +867,10 @@ class CLanguage(Language): #endif if ({condition}) {{{{ if (PyErr_WarnEx(PyExc_DeprecationWarning, - {depr_message}, 1)) - {{{{ - goto exit; + {depr_message}, 1)) + {{{{ + goto exit; + }}}} }}}} """ @@ -949,9 +950,10 @@ def deprecate_positional_use( major=major, minor=minor, cpp_message=wrapped_c_string_literal(cpp_message, suffix=" \\", + width=64, subsequent_indent=16), - depr_message=wrapped_c_string_literal(depr_message, - subsequent_indent=29), + depr_message=wrapped_c_string_literal(depr_message, width=64, + subsequent_indent=20), ) return normalize_snippet(code, indent=4) From 0c8bbf19fc508adaa0a1da5525fce690f537ee18 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 7 Aug 2023 16:00:11 +0200 Subject: [PATCH 8/8] Even more compact code Co-authored-by: Serhiy Storchaka --- Tools/clinic/clinic.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 7b22a10e7c265e..4437b0f2485f3a 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -231,11 +231,8 @@ def wrapped_c_string_literal( ) -> str: wrapped = textwrap.wrap(text, width=width, replace_whitespace=False, drop_whitespace=False, break_on_hyphens=False) - suffix += "\n" - lines = [f'"{line}"{suffix}' for line in wrapped] - separator = subsequent_indent * ' ' - joined = initial_indent * ' ' + separator.join(lines) - return joined.removesuffix(suffix) + separator = '"' + suffix + '\n' + subsequent_indent * ' ' + '"' + return initial_indent * ' ' + '"' + separator.join(wrapped) + '"' is_legal_c_identifier = re.compile('^[A-Za-z_][A-Za-z0-9_]*$').match