Description
Feature or enhancement
Suggesting to add syntax for producing deprecation warnings for positional use of optional parameters.
I made a proof-of-concept patch for this where I introduced a new special symbol x
. Example use:
/*[clinic input]
mod.func
stuff: object
/
x
optarg: int = 128
This will then generate code that emits a DeprecationWarning if optarg
is passed as a positional argument, but not if it is passed as a keyword.
We can use this feature to introduce deprecation warnings for parameters that will become keyword-only in future releases. When the deprecation period is done, we can simply replace the x
with *
, to really make the optional params keyword-only.
Pitch
Quoting @serhiy-storchaka, in issue #93057:
It is recommended to make optional rarely used arguments keyword-only. I do not think it will break much code, but we need a deprecation period for this.
The problem is that sqlite3.connect() was converted to Argument Clinic, and it was much easier to add deprecation warning in the old code.
Previous discussion
Linked PRs
- gh-95065: Add Argument Clinic support for deprecating positional use of parameters #95151
- gh-95065: Argument Clinic: Pretty-print long C strings in generated code #107712
- gh-95065: PoC: Argument Clinic: Support multiple '* [from ...]' deprecations #107742
- gh-95065: Make Argument Clinic append deprecation warnings to docstrings #107745
- gh-95065: Argument Clinic: Add comment to preprocessor warning code #107766
- gh-95065: Argument Clinic: Add functional tests of deprecated positionals #107768
- gh-95065: Produce nicer deprecation messages in Argument Clinic #107808
- gh-95065, gh-107704: Argument Clinic: support multiple '/ [from ...]' and '* [from ...]' markers #108132