From a40315da6df09a5e503c23d06fc7c1fa2e247617 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 9 Aug 2023 13:01:38 +0200 Subject: [PATCH 1/3] gh-95065: Produce nicer deprecation messages in Argument Clinic --- Lib/test/clinic.test.c | 261 +++++++++++++++++++++++++++++++++++------ Tools/clinic/clinic.py | 38 +++--- 2 files changed, 245 insertions(+), 54 deletions(-) diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c index 9fcee0dad7118b..9b9dd088c575e7 100644 --- a/Lib/test/clinic.test.c +++ b/Lib/test/clinic.test.c @@ -5528,18 +5528,18 @@ 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 " \ + " 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 " \ + " 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 " \ + " test_deprecate_positional_pos1_len1_optional() to be " \ "keyword-only." # endif #endif @@ -5572,7 +5572,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=144cbf1adc574dd9 input=89099f3dacd757da]*/ +/*[clinic end generated code: output=38192d2818f21bc9 input=89099f3dacd757da]*/ /*[clinic input] @@ -5635,16 +5635,16 @@ 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." + " 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.") + " 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." + " test_deprecate_positional_pos1_len1() to be keyword-only." # endif #endif if (nargs == 2) { @@ -5671,7 +5671,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=994bd57c1c634709 input=1702bbab1e9b3b99]*/ +/*[clinic end generated code: output=8a798ba78564b5be input=1702bbab1e9b3b99]*/ /*[clinic input] @@ -5741,18 +5741,18 @@ 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 " \ + "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 " \ + "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 " \ + "input of test_deprecate_positional_pos1_len2_with_kwd() to be " \ "keyword-only." # endif #endif @@ -5784,7 +5784,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=146c60ecbcdbf4b8 input=28cdb885f6c34eab]*/ +/*[clinic end generated code: output=262458b0b1bc2bc6 input=28cdb885f6c34eab]*/ /*[clinic input] @@ -5844,16 +5844,16 @@ 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." + " 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.") + " 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." + " test_deprecate_positional_pos0_len1() to be keyword-only." # endif #endif if (nargs == 1) { @@ -5878,7 +5878,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=dce99971a2494f9f input=678206db25c0652c]*/ +/*[clinic end generated code: output=8eab04dfe43d7c95 input=678206db25c0652c]*/ /*[clinic input] @@ -5941,18 +5941,18 @@ 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 " \ + "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 " \ + "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 " \ + "input of test_deprecate_positional_pos0_len2() to be " \ "keyword-only." # endif #endif @@ -5980,7 +5980,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=06999692e0c8dac4 input=fae0d0b1d480c939]*/ +/*[clinic end generated code: output=fe3b0d05e6a52a25 input=fae0d0b1d480c939]*/ /*[clinic input] @@ -6054,20 +6054,20 @@ test_deprecate_positional_pos0_len3_with_kwdonly(PyObject *module, PyObject *con # 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 " \ + "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 " \ + "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 " \ + "test_deprecate_positional_pos0_len3_with_kwdonly() to be " \ "keyword-only." # endif #endif @@ -6101,7 +6101,7 @@ test_deprecate_positional_pos0_len3_with_kwdonly_impl(PyObject *module, PyObject *b, PyObject *c, PyObject *e) -/*[clinic end generated code: output=a553e33101dc42b2 input=1b0121770c0c52e0]*/ +/*[clinic end generated code: output=03633f700d5af5fa input=1b0121770c0c52e0]*/ /*[clinic input] @@ -6166,16 +6166,16 @@ 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." + " 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.") + " 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." + " test_deprecate_positional_pos2_len1() to be keyword-only." # endif #endif if (nargs == 3) { @@ -6203,7 +6203,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=f96454a4970b443c input=e1d129689e69ec7c]*/ +/*[clinic end generated code: output=7630d8014eee60a4 input=e1d129689e69ec7c]*/ /*[clinic input] @@ -6271,18 +6271,18 @@ 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 " \ + "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 " \ + "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 " \ + "input of test_deprecate_positional_pos2_len2() to be " \ "keyword-only." # endif #endif @@ -6313,7 +6313,7 @@ static PyObject * test_deprecate_positional_pos2_len2_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c, PyObject *d) -/*[clinic end generated code: output=5e648e887da0a804 input=0d53533463a12792]*/ +/*[clinic end generated code: output=affce099ff43591d input=0d53533463a12792]*/ /*[clinic input] @@ -6389,18 +6389,18 @@ 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 " \ + "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 " \ + "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 " \ + "input of test_deprecate_positional_pos2_len3_with_kwdonly() to " \ "be keyword-only." # endif #endif @@ -6436,4 +6436,193 @@ test_deprecate_positional_pos2_len3_with_kwdonly_impl(PyObject *module, PyObject *c, PyObject *d, PyObject *e) -/*[clinic end generated code: output=383d56b03f7c2dcb input=154fd450448d8935]*/ +/*[clinic end generated code: output=0c7e90700b1ab0dd input=154fd450448d8935]*/ + + +/*[clinic input] +@classmethod +Test.__new__ + * [from 3.14] + a: object +The deprecation message should use the class name instead of __new__. +[clinic start generated code]*/ + +PyDoc_STRVAR(Test__doc__, +"Test(a)\n" +"--\n" +"\n" +"The deprecation message should use the class name instead of __new__.\n" +"\n" +"Note: Passing positional arguments to Test() is deprecated. Parameter\n" +"\'a\' will become a keyword-only parameter in Python 3.14.\n" +""); + +static PyObject * +Test_impl(PyTypeObject *type, PyObject *a); + +static PyObject * +Test(PyTypeObject *type, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 1 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { &_Py_ID(a), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"a", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "Test", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject * const *fastargs; + Py_ssize_t nargs = PyTuple_GET_SIZE(args); + PyObject *a; + + // Emit compiler warnings when we get to Python 3.14. + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'a' in the clinic input of" \ + " Test() 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() to be keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'a' in the clinic input of" \ + " Test() to be keyword-only." + # endif + #endif + if (nargs == 1) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "Passing positional arguments to Test() is deprecated. Parameter " + "'a' will become a keyword-only parameter in Python 3.14.", 1)) + { + goto exit; + } + } + fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf); + if (!fastargs) { + goto exit; + } + a = fastargs[0]; + return_value = Test_impl(type, a); + +exit: + return return_value; +} + +static PyObject * +Test_impl(PyTypeObject *type, PyObject *a) +/*[clinic end generated code: output=39b4c0aeee267af7 input=f133dc077aef49ec]*/ + + +/*[clinic input] +Test.__init__ + * [from 3.14] + a: object +The deprecation message should use the class name instead of __init__. +[clinic start generated code]*/ + +PyDoc_STRVAR(Test___init____doc__, +"Test(a)\n" +"--\n" +"\n" +"The deprecation message should use the class name instead of __init__.\n" +"\n" +"Note: Passing positional arguments to Test() is deprecated. Parameter\n" +"\'a\' will become a keyword-only parameter in Python 3.14.\n" +""); + +static int +Test___init___impl(TestObj *self, PyObject *a); + +static int +Test___init__(PyObject *self, PyObject *args, PyObject *kwargs) +{ + int return_value = -1; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 1 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { &_Py_ID(a), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"a", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "Test", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject * const *fastargs; + Py_ssize_t nargs = PyTuple_GET_SIZE(args); + PyObject *a; + + // Emit compiler warnings when we get to Python 3.14. + #if PY_VERSION_HEX >= 0x030e00C0 + # error \ + "In clinic.test.c, update parameter(s) 'a' in the clinic input of" \ + " Test() 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() to be keyword-only.") + # else + # warning \ + "In clinic.test.c, update parameter(s) 'a' in the clinic input of" \ + " Test() to be keyword-only." + # endif + #endif + if (nargs == 1) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "Passing positional arguments to Test() is deprecated. Parameter " + "'a' will become a keyword-only parameter in Python 3.14.", 1)) + { + goto exit; + } + } + fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf); + if (!fastargs) { + goto exit; + } + a = fastargs[0]; + return_value = Test___init___impl((TestObj *)self, a); + +exit: + return return_value; +} + +static int +Test___init___impl(TestObj *self, PyObject *a) +/*[clinic end generated code: output=4bd39f6cf9e13372 input=bcc7995baf256b11]*/ diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 059c2db27288db..d1a0ad9c0a466f 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -917,7 +917,7 @@ def deprecate_positional_use( major, minor = thenceforth cpp_message = ( f"In {source}, update parameter(s) {pstr} in the clinic " - f"input of {func.full_name!r} to be keyword-only." + f"input of {func.fulldisplayname}() to be keyword-only." ) # Format the deprecation message. @@ -928,7 +928,7 @@ def deprecate_positional_use( if first_pos: preamble = f"Passing {first_pos+1} positional arguments to " depr_message = preamble + ( - f"{func.full_name}() is deprecated. Parameter {pstr} will " + f"{func.fulldisplayname}() is deprecated. Parameter {pstr} will " f"become a keyword-only parameter in Python {major}.{minor}." ) else: @@ -939,7 +939,7 @@ def deprecate_positional_use( f"argument{'s' if first_pos != 1 else ''} to " ) depr_message = preamble + ( - f"{func.full_name}() is deprecated. Parameters {pstr} will " + f"{func.fulldisplayname}() is deprecated. Parameters {pstr} will " f"become keyword-only parameters in Python {major}.{minor}." ) @@ -1673,14 +1673,7 @@ def render_function( full_name = f.full_name template_dict = {'full_name': full_name} - - if new_or_init: - assert isinstance(f.cls, Class) - name = f.cls.name - else: - name = f.name - - template_dict['name'] = name + template_dict['name'] = f.displayname if f.c_basename: c_basename = f.c_basename @@ -2678,6 +2671,21 @@ def __post_init__(self) -> None: self.self_converter: self_converter | None = None self.__render_parameters__: list[Parameter] | None = None + @functools.cached_property + def displayname(self) -> str: + """Pretty-printable name.""" + if self.kind.new_or_init: + assert isinstance(self.cls, Class) + return self.cls.name + else: + return self.name + + @functools.cached_property + def fulldisplayname(self) -> str: + if isinstance(self.module, Module): + return f"{self.module.name}.{self.displayname}" + return self.displayname + @property def render_parameters(self) -> list[Parameter]: if not self.__render_parameters__: @@ -5515,13 +5523,7 @@ def format_docstring_signature( self, f: Function, parameters: list[Parameter] ) -> str: text, add, output = _text_accumulator() - if f.kind.new_or_init: - # classes get *just* the name of the class - # not __new__, not __init__, and not module.classname - assert f.cls - add(f.cls.name) - else: - add(f.name) + add(f.displayname) if self.forced_text_signature: add(self.forced_text_signature) else: From ffc901433a09c85a60af18ee5b81d6528c684ef0 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 9 Aug 2023 13:11:46 +0200 Subject: [PATCH 2/3] Adjust one of the tests to include module path --- Lib/test/clinic.test.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c index 9b9dd088c575e7..0a01490bbd6942 100644 --- a/Lib/test/clinic.test.c +++ b/Lib/test/clinic.test.c @@ -4,9 +4,11 @@ output preset block /*[clinic end generated code: output=da39a3ee5e6b4b0d input=3c81ac2402d06a8b]*/ /*[clinic input] +module m +class m.T "TestObj *" "TestType" class Test "TestObj *" "TestType" [clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=fc7e50384d12b83f]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=f761b4d55cb179cf]*/ /*[clinic input] test_object_converter @@ -6535,27 +6537,27 @@ Test_impl(PyTypeObject *type, PyObject *a) /*[clinic input] -Test.__init__ +m.T.__init__ * [from 3.14] a: object The deprecation message should use the class name instead of __init__. [clinic start generated code]*/ -PyDoc_STRVAR(Test___init____doc__, -"Test(a)\n" +PyDoc_STRVAR(m_T___init____doc__, +"T(a)\n" "--\n" "\n" "The deprecation message should use the class name instead of __init__.\n" "\n" -"Note: Passing positional arguments to Test() is deprecated. Parameter\n" +"Note: Passing positional arguments to m.T() is deprecated. Parameter\n" "\'a\' will become a keyword-only parameter in Python 3.14.\n" ""); static int -Test___init___impl(TestObj *self, PyObject *a); +m_T___init___impl(TestObj *self, PyObject *a); static int -Test___init__(PyObject *self, PyObject *args, PyObject *kwargs) +m_T___init__(PyObject *self, PyObject *args, PyObject *kwargs) { int return_value = -1; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -6579,7 +6581,7 @@ Test___init__(PyObject *self, PyObject *args, PyObject *kwargs) static const char * const _keywords[] = {"a", NULL}; static _PyArg_Parser _parser = { .keywords = _keywords, - .fname = "Test", + .fname = "T", .kwtuple = KWTUPLE, }; #undef KWTUPLE @@ -6592,21 +6594,21 @@ Test___init__(PyObject *self, PyObject *args, PyObject *kwargs) #if PY_VERSION_HEX >= 0x030e00C0 # error \ "In clinic.test.c, update parameter(s) 'a' in the clinic input of" \ - " Test() to be keyword-only." + " m.T() 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() to be keyword-only.") + " m.T() to be keyword-only.") # else # warning \ "In clinic.test.c, update parameter(s) 'a' in the clinic input of" \ - " Test() to be keyword-only." + " m.T() to be keyword-only." # endif #endif if (nargs == 1) { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Passing positional arguments to Test() is deprecated. Parameter " + "Passing positional arguments to m.T() is deprecated. Parameter " "'a' will become a keyword-only parameter in Python 3.14.", 1)) { goto exit; @@ -6617,12 +6619,12 @@ Test___init__(PyObject *self, PyObject *args, PyObject *kwargs) goto exit; } a = fastargs[0]; - return_value = Test___init___impl((TestObj *)self, a); + return_value = m_T___init___impl((TestObj *)self, a); exit: return return_value; } static int -Test___init___impl(TestObj *self, PyObject *a) -/*[clinic end generated code: output=4bd39f6cf9e13372 input=bcc7995baf256b11]*/ +m_T___init___impl(TestObj *self, PyObject *a) +/*[clinic end generated code: output=14ffb1aea3bc94d9 input=f71b51dbe19fa657]*/ From 6f2eb6fd6217d9d1e11d5087b4ad3637a394aa6d Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 9 Aug 2023 14:53:02 +0200 Subject: [PATCH 3/3] Don't change the preprocessor warning --- Lib/test/clinic.test.c | 88 +++++++++++++++++++++--------------------- Tools/clinic/clinic.py | 2 +- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c index 0a01490bbd6942..c7063e1139b0a9 100644 --- a/Lib/test/clinic.test.c +++ b/Lib/test/clinic.test.c @@ -5530,18 +5530,18 @@ 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 " \ + " '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 " \ + " '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 " \ + " 'test_deprecate_positional_pos1_len1_optional' to be " \ "keyword-only." # endif #endif @@ -5574,7 +5574,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=38192d2818f21bc9 input=89099f3dacd757da]*/ +/*[clinic end generated code: output=144cbf1adc574dd9 input=89099f3dacd757da]*/ /*[clinic input] @@ -5637,16 +5637,16 @@ 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." + " '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.") + " '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." + " 'test_deprecate_positional_pos1_len1' to be keyword-only." # endif #endif if (nargs == 2) { @@ -5673,7 +5673,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=8a798ba78564b5be input=1702bbab1e9b3b99]*/ +/*[clinic end generated code: output=994bd57c1c634709 input=1702bbab1e9b3b99]*/ /*[clinic input] @@ -5743,18 +5743,18 @@ 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 " \ + "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 " \ + "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 " \ + "input of 'test_deprecate_positional_pos1_len2_with_kwd' to be " \ "keyword-only." # endif #endif @@ -5786,7 +5786,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=262458b0b1bc2bc6 input=28cdb885f6c34eab]*/ +/*[clinic end generated code: output=146c60ecbcdbf4b8 input=28cdb885f6c34eab]*/ /*[clinic input] @@ -5846,16 +5846,16 @@ 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." + " '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.") + " '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." + " 'test_deprecate_positional_pos0_len1' to be keyword-only." # endif #endif if (nargs == 1) { @@ -5880,7 +5880,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=8eab04dfe43d7c95 input=678206db25c0652c]*/ +/*[clinic end generated code: output=dce99971a2494f9f input=678206db25c0652c]*/ /*[clinic input] @@ -5943,18 +5943,18 @@ 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 " \ + "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 " \ + "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 " \ + "input of 'test_deprecate_positional_pos0_len2' to be " \ "keyword-only." # endif #endif @@ -5982,7 +5982,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=fe3b0d05e6a52a25 input=fae0d0b1d480c939]*/ +/*[clinic end generated code: output=06999692e0c8dac4 input=fae0d0b1d480c939]*/ /*[clinic input] @@ -6056,20 +6056,20 @@ test_deprecate_positional_pos0_len3_with_kwdonly(PyObject *module, PyObject *con # 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 " \ + "'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 " \ + "'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 " \ + "'test_deprecate_positional_pos0_len3_with_kwdonly' to be " \ "keyword-only." # endif #endif @@ -6103,7 +6103,7 @@ test_deprecate_positional_pos0_len3_with_kwdonly_impl(PyObject *module, PyObject *b, PyObject *c, PyObject *e) -/*[clinic end generated code: output=03633f700d5af5fa input=1b0121770c0c52e0]*/ +/*[clinic end generated code: output=a553e33101dc42b2 input=1b0121770c0c52e0]*/ /*[clinic input] @@ -6168,16 +6168,16 @@ 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." + " '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.") + " '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." + " 'test_deprecate_positional_pos2_len1' to be keyword-only." # endif #endif if (nargs == 3) { @@ -6205,7 +6205,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=7630d8014eee60a4 input=e1d129689e69ec7c]*/ +/*[clinic end generated code: output=f96454a4970b443c input=e1d129689e69ec7c]*/ /*[clinic input] @@ -6273,18 +6273,18 @@ 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 " \ + "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 " \ + "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 " \ + "input of 'test_deprecate_positional_pos2_len2' to be " \ "keyword-only." # endif #endif @@ -6315,7 +6315,7 @@ static PyObject * test_deprecate_positional_pos2_len2_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c, PyObject *d) -/*[clinic end generated code: output=affce099ff43591d input=0d53533463a12792]*/ +/*[clinic end generated code: output=5e648e887da0a804 input=0d53533463a12792]*/ /*[clinic input] @@ -6391,18 +6391,18 @@ 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 " \ + "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 " \ + "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 " \ + "input of 'test_deprecate_positional_pos2_len3_with_kwdonly' to " \ "be keyword-only." # endif #endif @@ -6438,7 +6438,7 @@ test_deprecate_positional_pos2_len3_with_kwdonly_impl(PyObject *module, PyObject *c, PyObject *d, PyObject *e) -/*[clinic end generated code: output=0c7e90700b1ab0dd input=154fd450448d8935]*/ +/*[clinic end generated code: output=383d56b03f7c2dcb input=154fd450448d8935]*/ /*[clinic input] @@ -6500,16 +6500,16 @@ Test(PyTypeObject *type, PyObject *args, PyObject *kwargs) #if PY_VERSION_HEX >= 0x030e00C0 # error \ "In clinic.test.c, update parameter(s) 'a' in the clinic input of" \ - " Test() to be keyword-only." + " 'Test.__new__' 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() to be keyword-only.") + " 'Test.__new__' to be keyword-only.") # else # warning \ "In clinic.test.c, update parameter(s) 'a' in the clinic input of" \ - " Test() to be keyword-only." + " 'Test.__new__' to be keyword-only." # endif #endif if (nargs == 1) { @@ -6533,7 +6533,7 @@ Test(PyTypeObject *type, PyObject *args, PyObject *kwargs) static PyObject * Test_impl(PyTypeObject *type, PyObject *a) -/*[clinic end generated code: output=39b4c0aeee267af7 input=f133dc077aef49ec]*/ +/*[clinic end generated code: output=d15a69ea37ec6502 input=f133dc077aef49ec]*/ /*[clinic input] @@ -6594,16 +6594,16 @@ m_T___init__(PyObject *self, PyObject *args, PyObject *kwargs) #if PY_VERSION_HEX >= 0x030e00C0 # error \ "In clinic.test.c, update parameter(s) 'a' in the clinic input of" \ - " m.T() to be keyword-only." + " 'm.T.__init__' 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" \ - " m.T() to be keyword-only.") + " 'm.T.__init__' to be keyword-only.") # else # warning \ "In clinic.test.c, update parameter(s) 'a' in the clinic input of" \ - " m.T() to be keyword-only." + " 'm.T.__init__' to be keyword-only." # endif #endif if (nargs == 1) { @@ -6627,4 +6627,4 @@ m_T___init__(PyObject *self, PyObject *args, PyObject *kwargs) static int m_T___init___impl(TestObj *self, PyObject *a) -/*[clinic end generated code: output=14ffb1aea3bc94d9 input=f71b51dbe19fa657]*/ +/*[clinic end generated code: output=ef43c425816a549f input=f71b51dbe19fa657]*/ diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index c8c05f19f18181..70b066cce82fae 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -917,7 +917,7 @@ def deprecate_positional_use( major, minor = thenceforth cpp_message = ( f"In {source}, update parameter(s) {pstr} in the clinic " - f"input of {func.fulldisplayname}() to be keyword-only." + f"input of {func.full_name!r} to be keyword-only." ) # Format the deprecation message.