Skip to content

Commit 0db043d

Browse files
gh-95065: Make Argument Clinic append deprecation warnings to docstrings (#107745)
1 parent 328d925 commit 0db043d

File tree

2 files changed

+63
-18
lines changed

2 files changed

+63
-18
lines changed

Lib/test/clinic.test.c

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5477,7 +5477,11 @@ test_deprecate_positional_pos1_len1_optional
54775477
PyDoc_STRVAR(test_deprecate_positional_pos1_len1_optional__doc__,
54785478
"test_deprecate_positional_pos1_len1_optional($module, /, a, b=None)\n"
54795479
"--\n"
5480-
"\n");
5480+
"\n"
5481+
"Note: Passing 2 positional arguments to\n"
5482+
"test_deprecate_positional_pos1_len1_optional() is deprecated.\n"
5483+
"Parameter \'b\' will become a keyword-only parameter in Python 3.14.\n"
5484+
"");
54815485

54825486
#define TEST_DEPRECATE_POSITIONAL_POS1_LEN1_OPTIONAL_METHODDEF \
54835487
{"test_deprecate_positional_pos1_len1_optional", _PyCFunction_CAST(test_deprecate_positional_pos1_len1_optional), METH_FASTCALL|METH_KEYWORDS, test_deprecate_positional_pos1_len1_optional__doc__},
@@ -5567,7 +5571,7 @@ test_deprecate_positional_pos1_len1_optional(PyObject *module, PyObject *const *
55675571
static PyObject *
55685572
test_deprecate_positional_pos1_len1_optional_impl(PyObject *module,
55695573
PyObject *a, PyObject *b)
5570-
/*[clinic end generated code: output=09a6edec1ddcd469 input=89099f3dacd757da]*/
5574+
/*[clinic end generated code: output=6c0fd9d94fa1e765 input=89099f3dacd757da]*/
55715575

55725576

55735577
/*[clinic input]
@@ -5580,7 +5584,11 @@ test_deprecate_positional_pos1_len1
55805584
PyDoc_STRVAR(test_deprecate_positional_pos1_len1__doc__,
55815585
"test_deprecate_positional_pos1_len1($module, /, a, b)\n"
55825586
"--\n"
5583-
"\n");
5587+
"\n"
5588+
"Note: Passing 2 positional arguments to\n"
5589+
"test_deprecate_positional_pos1_len1() is deprecated. Parameter \'b\'\n"
5590+
"will become a keyword-only parameter in Python 3.14.\n"
5591+
"");
55845592

55855593
#define TEST_DEPRECATE_POSITIONAL_POS1_LEN1_METHODDEF \
55865594
{"test_deprecate_positional_pos1_len1", _PyCFunction_CAST(test_deprecate_positional_pos1_len1), METH_FASTCALL|METH_KEYWORDS, test_deprecate_positional_pos1_len1__doc__},
@@ -5661,7 +5669,7 @@ test_deprecate_positional_pos1_len1(PyObject *module, PyObject *const *args, Py_
56615669
static PyObject *
56625670
test_deprecate_positional_pos1_len1_impl(PyObject *module, PyObject *a,
56635671
PyObject *b)
5664-
/*[clinic end generated code: output=52a2618293df747d input=1702bbab1e9b3b99]*/
5672+
/*[clinic end generated code: output=22821a0fa9945d0c input=1702bbab1e9b3b99]*/
56655673

56665674

56675675
/*[clinic input]
@@ -5677,7 +5685,12 @@ test_deprecate_positional_pos1_len2_with_kwd
56775685
PyDoc_STRVAR(test_deprecate_positional_pos1_len2_with_kwd__doc__,
56785686
"test_deprecate_positional_pos1_len2_with_kwd($module, /, a, b, c, *, d)\n"
56795687
"--\n"
5680-
"\n");
5688+
"\n"
5689+
"Note: Passing more than 1 positional argument to\n"
5690+
"test_deprecate_positional_pos1_len2_with_kwd() is deprecated.\n"
5691+
"Parameters \'b\' and \'c\' will become keyword-only parameters in Python\n"
5692+
"3.14.\n"
5693+
"");
56815694

56825695
#define TEST_DEPRECATE_POSITIONAL_POS1_LEN2_WITH_KWD_METHODDEF \
56835696
{"test_deprecate_positional_pos1_len2_with_kwd", _PyCFunction_CAST(test_deprecate_positional_pos1_len2_with_kwd), METH_FASTCALL|METH_KEYWORDS, test_deprecate_positional_pos1_len2_with_kwd__doc__},
@@ -5768,7 +5781,7 @@ static PyObject *
57685781
test_deprecate_positional_pos1_len2_with_kwd_impl(PyObject *module,
57695782
PyObject *a, PyObject *b,
57705783
PyObject *c, PyObject *d)
5771-
/*[clinic end generated code: output=550aabea548589b4 input=28cdb885f6c34eab]*/
5784+
/*[clinic end generated code: output=061d554ccc6b8f51 input=28cdb885f6c34eab]*/
57725785

57735786

57745787
/*[clinic input]
@@ -5780,7 +5793,11 @@ test_deprecate_positional_pos0_len1
57805793
PyDoc_STRVAR(test_deprecate_positional_pos0_len1__doc__,
57815794
"test_deprecate_positional_pos0_len1($module, /, a)\n"
57825795
"--\n"
5783-
"\n");
5796+
"\n"
5797+
"Note: Passing positional arguments to\n"
5798+
"test_deprecate_positional_pos0_len1() is deprecated. Parameter \'a\'\n"
5799+
"will become a keyword-only parameter in Python 3.14.\n"
5800+
"");
57845801

57855802
#define TEST_DEPRECATE_POSITIONAL_POS0_LEN1_METHODDEF \
57865803
{"test_deprecate_positional_pos0_len1", _PyCFunction_CAST(test_deprecate_positional_pos0_len1), METH_FASTCALL|METH_KEYWORDS, test_deprecate_positional_pos0_len1__doc__},
@@ -5857,7 +5874,7 @@ test_deprecate_positional_pos0_len1(PyObject *module, PyObject *const *args, Py_
58575874

58585875
static PyObject *
58595876
test_deprecate_positional_pos0_len1_impl(PyObject *module, PyObject *a)
5860-
/*[clinic end generated code: output=66c63ec8d6903bde input=678206db25c0652c]*/
5877+
/*[clinic end generated code: output=3e512117a5eda970 input=678206db25c0652c]*/
58615878

58625879

58635880
/*[clinic input]
@@ -5870,7 +5887,11 @@ test_deprecate_positional_pos0_len2
58705887
PyDoc_STRVAR(test_deprecate_positional_pos0_len2__doc__,
58715888
"test_deprecate_positional_pos0_len2($module, /, a, b)\n"
58725889
"--\n"
5873-
"\n");
5890+
"\n"
5891+
"Note: Passing positional arguments to\n"
5892+
"test_deprecate_positional_pos0_len2() is deprecated. Parameters \'a\'\n"
5893+
"and \'b\' will become keyword-only parameters in Python 3.14.\n"
5894+
"");
58745895

58755896
#define TEST_DEPRECATE_POSITIONAL_POS0_LEN2_METHODDEF \
58765897
{"test_deprecate_positional_pos0_len2", _PyCFunction_CAST(test_deprecate_positional_pos0_len2), METH_FASTCALL|METH_KEYWORDS, test_deprecate_positional_pos0_len2__doc__},
@@ -5954,7 +5975,7 @@ test_deprecate_positional_pos0_len2(PyObject *module, PyObject *const *args, Py_
59545975
static PyObject *
59555976
test_deprecate_positional_pos0_len2_impl(PyObject *module, PyObject *a,
59565977
PyObject *b)
5957-
/*[clinic end generated code: output=6b6df40aaf751b2e input=fae0d0b1d480c939]*/
5978+
/*[clinic end generated code: output=d41da050a5b82dd0 input=fae0d0b1d480c939]*/
59585979

59595980

59605981
/*[clinic input]
@@ -5971,7 +5992,12 @@ PyDoc_STRVAR(test_deprecate_positional_pos0_len3_with_kwdonly__doc__,
59715992
"test_deprecate_positional_pos0_len3_with_kwdonly($module, /, a, b, c,\n"
59725993
" *, e)\n"
59735994
"--\n"
5974-
"\n");
5995+
"\n"
5996+
"Note: Passing positional arguments to\n"
5997+
"test_deprecate_positional_pos0_len3_with_kwdonly() is deprecated.\n"
5998+
"Parameters \'a\', \'b\' and \'c\' will become keyword-only parameters in\n"
5999+
"Python 3.14.\n"
6000+
"");
59756001

59766002
#define TEST_DEPRECATE_POSITIONAL_POS0_LEN3_WITH_KWDONLY_METHODDEF \
59776003
{"test_deprecate_positional_pos0_len3_with_kwdonly", _PyCFunction_CAST(test_deprecate_positional_pos0_len3_with_kwdonly), METH_FASTCALL|METH_KEYWORDS, test_deprecate_positional_pos0_len3_with_kwdonly__doc__},
@@ -6069,7 +6095,7 @@ test_deprecate_positional_pos0_len3_with_kwdonly_impl(PyObject *module,
60696095
PyObject *b,
60706096
PyObject *c,
60716097
PyObject *e)
6072-
/*[clinic end generated code: output=5c936993846d01a3 input=1b0121770c0c52e0]*/
6098+
/*[clinic end generated code: output=c5d7ddfc139ddf31 input=1b0121770c0c52e0]*/
60736099

60746100

60756101
/*[clinic input]
@@ -6083,7 +6109,11 @@ test_deprecate_positional_pos2_len1
60836109
PyDoc_STRVAR(test_deprecate_positional_pos2_len1__doc__,
60846110
"test_deprecate_positional_pos2_len1($module, /, a, b, c)\n"
60856111
"--\n"
6086-
"\n");
6112+
"\n"
6113+
"Note: Passing 3 positional arguments to\n"
6114+
"test_deprecate_positional_pos2_len1() is deprecated. Parameter \'c\'\n"
6115+
"will become a keyword-only parameter in Python 3.14.\n"
6116+
"");
60876117

60886118
#define TEST_DEPRECATE_POSITIONAL_POS2_LEN1_METHODDEF \
60896119
{"test_deprecate_positional_pos2_len1", _PyCFunction_CAST(test_deprecate_positional_pos2_len1), METH_FASTCALL|METH_KEYWORDS, test_deprecate_positional_pos2_len1__doc__},
@@ -6166,7 +6196,7 @@ test_deprecate_positional_pos2_len1(PyObject *module, PyObject *const *args, Py_
61666196
static PyObject *
61676197
test_deprecate_positional_pos2_len1_impl(PyObject *module, PyObject *a,
61686198
PyObject *b, PyObject *c)
6169-
/*[clinic end generated code: output=2641e037296e3b61 input=e1d129689e69ec7c]*/
6199+
/*[clinic end generated code: output=d80609e6b37ffb8a input=e1d129689e69ec7c]*/
61706200

61716201

61726202
/*[clinic input]
@@ -6181,7 +6211,11 @@ test_deprecate_positional_pos2_len2
61816211
PyDoc_STRVAR(test_deprecate_positional_pos2_len2__doc__,
61826212
"test_deprecate_positional_pos2_len2($module, /, a, b, c, d)\n"
61836213
"--\n"
6184-
"\n");
6214+
"\n"
6215+
"Note: Passing more than 2 positional arguments to\n"
6216+
"test_deprecate_positional_pos2_len2() is deprecated. Parameters \'c\'\n"
6217+
"and \'d\' will become keyword-only parameters in Python 3.14.\n"
6218+
"");
61856219

61866220
#define TEST_DEPRECATE_POSITIONAL_POS2_LEN2_METHODDEF \
61876221
{"test_deprecate_positional_pos2_len2", _PyCFunction_CAST(test_deprecate_positional_pos2_len2), METH_FASTCALL|METH_KEYWORDS, test_deprecate_positional_pos2_len2__doc__},
@@ -6271,7 +6305,7 @@ static PyObject *
62716305
test_deprecate_positional_pos2_len2_impl(PyObject *module, PyObject *a,
62726306
PyObject *b, PyObject *c,
62736307
PyObject *d)
6274-
/*[clinic end generated code: output=4a9068ef8fee61f6 input=0d53533463a12792]*/
6308+
/*[clinic end generated code: output=1c10d6197562319f input=0d53533463a12792]*/
62756309

62766310

62776311
/*[clinic input]
@@ -6289,7 +6323,12 @@ PyDoc_STRVAR(test_deprecate_positional_pos2_len3_with_kwdonly__doc__,
62896323
"test_deprecate_positional_pos2_len3_with_kwdonly($module, /, a, b, c,\n"
62906324
" d, *, e)\n"
62916325
"--\n"
6292-
"\n");
6326+
"\n"
6327+
"Note: Passing more than 2 positional arguments to\n"
6328+
"test_deprecate_positional_pos2_len3_with_kwdonly() is deprecated.\n"
6329+
"Parameters \'c\' and \'d\' will become keyword-only parameters in Python\n"
6330+
"3.14.\n"
6331+
"");
62936332

62946333
#define TEST_DEPRECATE_POSITIONAL_POS2_LEN3_WITH_KWDONLY_METHODDEF \
62956334
{"test_deprecate_positional_pos2_len3_with_kwdonly", _PyCFunction_CAST(test_deprecate_positional_pos2_len3_with_kwdonly), METH_FASTCALL|METH_KEYWORDS, test_deprecate_positional_pos2_len3_with_kwdonly__doc__},
@@ -6388,4 +6427,4 @@ test_deprecate_positional_pos2_len3_with_kwdonly_impl(PyObject *module,
63886427
PyObject *c,
63896428
PyObject *d,
63906429
PyObject *e)
6391-
/*[clinic end generated code: output=1154c2e3e798948c input=154fd450448d8935]*/
6430+
/*[clinic end generated code: output=d32375ffce63d3db input=154fd450448d8935]*/

Tools/clinic/clinic.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,12 @@ def deprecate_positional_use(
941941
f"{func.full_name}() is deprecated. Parameters {pstr} will "
942942
f"become keyword-only parameters in Python {major}.{minor}."
943943
)
944+
945+
# Append deprecation warning to docstring.
946+
lines = textwrap.wrap(f"Note: {depr_message}")
947+
docstring = "\n".join(lines)
948+
func.docstring += f"\n\n{docstring}\n"
949+
944950
# Format and return the code block.
945951
code = self.DEPRECATED_POSITIONAL_PROTOTYPE.format(
946952
condition=condition,

0 commit comments

Comments
 (0)