You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gh-107704: Argument Clinic: add support for deprecating keyword use of parameters (GH-107984)
It is now possible to deprecate passing keyword arguments for
keyword-or-positional parameters with Argument Clinic, using the new
'/ [from X.Y]' syntax.
(To be read as "positional-only from Python version X.Y")
Co-authored-by: Erlend E. Aasland <erlend@python.org>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
The generated code will now emit a :exc:`DeprecationWarning`
1989
-
when an :term:`argument` for the :term:`parameter` *b* is passed positionally.
2003
+
when an :term:`argument` for the :term:`parameter` *d* is passed positionally
2004
+
(e.g ``myfunc(1, 2, 3, 4, e=5)``) or an argument for the parameter *b* is
2005
+
passed by keyword (e.g ``myfunc(1, b=2, c=3, d=4, e=5)``).
1990
2006
C preprocessor directives are also generated for emitting
1991
-
compiler warnings if the ``* [from ...]`` line has not been removed
2007
+
compiler warnings if the ``[from ...]`` lines have not been removed
1992
2008
from the Argument Clinic input when the deprecation period is over,
1993
2009
which means when the alpha phase of the specified Python version kicks in.
1994
2010
@@ -2001,21 +2017,26 @@ Luckily for us, compiler warnings are now generated:
2001
2017
.. code-block:: none
2002
2018
2003
2019
In file included from Modules/foomodule.c:139:
2004
-
Modules/clinic/foomodule.c.h:139:8: warning: In 'foomodule.c', update parameter(s) 'a' and 'b' in the clinic input of 'mymod.myfunc' to be keyword-only. [-W#warnings]
2005
-
# warning "In 'foomodule.c', update parameter(s) 'a' and 'b' in the clinic input of 'mymod.myfunc' to be keyword-only. [-W#warnings]"
2020
+
Modules/clinic/foomodule.c.h:139:8: warning: In 'foomodule.c', update the clinic input of 'mymod.myfunc'. [-W#warnings]
2021
+
# warning "In 'foomodule.c', update the clinic input of 'mymod.myfunc'. [-W#warnings]"
2006
2022
^
2007
2023
2008
-
We now close the deprecation phase by making *b* keyword-only;
2009
-
replace the ``* [from ...]`` line above *b*
2010
-
with the ``*`` from the line above *c*::
2024
+
We now close the deprecation phase by making *a* positional-only and *c*
2025
+
keyword-only;
2026
+
replace the ``/ [from ...]`` line below *b* with the ``/`` from the line
2027
+
below *a* and the ``* [from ...]`` line above *d* with the ``*`` from
2028
+
the line above *e*::
2011
2029
2012
2030
/*[clinic input]
2013
2031
module foo
2014
2032
myfunc
2015
2033
a: int
2016
-
*
2017
2034
b: int
2035
+
/
2018
2036
c: int
2037
+
*
2038
+
d: int
2039
+
e: int
2019
2040
[clinic start generated output]*/
2020
2041
2021
2042
Finally, run ``make clinic`` to regenerate the Argument Clinic code,
0 commit comments