Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-95065: Add Argument Clinic support for deprecating positional use of parameters #95151

Merged
merged 95 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 91 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
9196162
PoC
erlend-aasland Jun 24, 2022
6a8c14f
Add tests
erlend-aasland Jul 22, 2022
457d38a
Improve warning wording
erlend-aasland Jul 22, 2022
3687748
Add NEWS
erlend-aasland Jul 22, 2022
9c81ae1
Pull in main
erlend-aasland Feb 21, 2023
a5734d6
Pull in main
erlend-aasland Apr 29, 2023
1e9fd55
Pull in main
erlend-aasland Jul 2, 2023
93e0745
Merge branch 'main' into ac-deprecate
erlend-aasland Jul 3, 2023
6bde63d
Add annotation
erlend-aasland Jul 3, 2023
bb619a5
Pull in main
erlend-aasland Jul 3, 2023
d85475e
Amend tests
erlend-aasland Jul 3, 2023
68f8ed9
Pull in main
erlend-aasland Jul 3, 2023
ca496b4
Amend test
erlend-aasland Jul 3, 2023
fe77d5f
Annotate
erlend-aasland Jul 3, 2023
de9e661
Pull in main
erlend-aasland Jul 12, 2023
3701b41
Fix merge
erlend-aasland Jul 14, 2023
a149a7b
Fix tests and repr
erlend-aasland Jul 14, 2023
e9ad211
Get ready for '* [from ...]' syntax
erlend-aasland Jul 14, 2023
0fcad58
Add 'whence' to deprecation warning message
erlend-aasland Jul 14, 2023
efb1fba
PoC
erlend-aasland Jul 14, 2023
3d8164f
Pull in main
erlend-aasland Jul 15, 2023
43cec6c
Improve preprocessor warning message, and fix it on windows
erlend-aasland Jul 15, 2023
075cf67
Nits
erlend-aasland Jul 15, 2023
13104e8
Assert format
erlend-aasland Jul 15, 2023
dc22c91
Pull in main
erlend-aasland Jul 15, 2023
7864dcb
Improve accuracy of variable name
erlend-aasland Jul 15, 2023
fbed52f
Add docs
erlend-aasland Jul 15, 2023
222c3bb
Pull in main
erlend-aasland Jul 15, 2023
2abe7a3
Adjust CPP barking
erlend-aasland Jul 15, 2023
4c0ec79
Fix CPP
erlend-aasland Jul 15, 2023
35fbe80
Fix CPP for error case also
erlend-aasland Jul 15, 2023
ccf8df8
Update clinic.test.c
erlend-aasland Jul 15, 2023
4db3c8d
Fix and test multiple deprecation directives error message
erlend-aasland Jul 15, 2023
43af475
Extend the docs
erlend-aasland Jul 15, 2023
5074495
Add note about compiler error
erlend-aasland Jul 15, 2023
ce5cd92
Fixup docs and fixup cpp error string
erlend-aasland Jul 15, 2023
c2cfc80
Pull in main
erlend-aasland Jul 19, 2023
4dc8241
Fix mypy complain
erlend-aasland Jul 19, 2023
b2c8f34
Pull in main
erlend-aasland Jul 20, 2023
5f181c7
Pull in main
erlend-aasland Jul 20, 2023
9eab8f7
Address review: annotate deprecated_positional as str | None
AlexWaygood Jul 20, 2023
25aa23c
Address review: add return annotation to parse_deprecated_positional()
erlend-aasland Jul 20, 2023
6624e8f
Merge branch 'main' into ac-deprecate
erlend-aasland Jul 20, 2023
46924a7
Pull in main
erlend-aasland Jul 22, 2023
2e72b66
WIP
erlend-aasland Jul 22, 2023
cbbcf1a
Pull in main
erlend-aasland Aug 2, 2023
f82be40
Pull in main
erlend-aasland Aug 4, 2023
a76d63c
Move prototype to class level
erlend-aasland Aug 4, 2023
e5bbd7b
Address review: start warning from alpha stage
erlend-aasland Aug 4, 2023
c981efa
Add more test cases
erlend-aasland Aug 4, 2023
821124e
Add TODO comment
erlend-aasland Aug 4, 2023
aa1b85d
Test case 2 already covers this test case
erlend-aasland Aug 5, 2023
44af850
Handle more cases
erlend-aasland Aug 5, 2023
01f17f9
Add one more test case as requested by Nikita
erlend-aasland Aug 5, 2023
e6860bc
Fix mypy whining
erlend-aasland Aug 5, 2023
71a8750
Address Alex's review: solve mypy complaint more elegantly
erlend-aasland Aug 5, 2023
e6886f0
Address some of Serhiy's remarks:
erlend-aasland Aug 5, 2023
480a29f
Address review: use stack level 1
erlend-aasland Aug 5, 2023
a3cf43a
Merge branch 'main' into ac-deprecate
erlend-aasland Aug 5, 2023
5151e62
Pull in main
erlend-aasland Aug 5, 2023
b98aab3
Address Serhiy's second round of remarks:
erlend-aasland Aug 5, 2023
eeb8187
Fix merge: revert accidental removal of a clinic.test.c test method
erlend-aasland Aug 5, 2023
6c6dd10
Address Alex and Serhiy's doc remarks
erlend-aasland Aug 5, 2023
ddd319b
Pull in main
erlend-aasland Aug 6, 2023
47a8979
Further improvements:
erlend-aasland Aug 6, 2023
02eba96
Make mypy happy (quickfix)
erlend-aasland Aug 6, 2023
fa77489
Revert sqlite3 test
erlend-aasland Aug 6, 2023
87a7f20
Use try...except ValueError trick for neater code
erlend-aasland Aug 6, 2023
f36bc05
Move VersionTuple to above Parameter class
erlend-aasland Aug 6, 2023
5e65020
Add more tests for illegal formats
erlend-aasland Aug 6, 2023
f1f311a
Don't link to keyword-only param glossary section
erlend-aasland Aug 6, 2023
83de0b8
No need for iter
erlend-aasland Aug 6, 2023
b10dc9c
For now, only use the basename of the source file
erlend-aasland Aug 6, 2023
c4ba025
Apply suggestions from code review
erlend-aasland Aug 6, 2023
c875d60
Fix mypy error
erlend-aasland Aug 6, 2023
cdd927c
Fix deprecation condition
erlend-aasland Aug 6, 2023
f0847bc
Further improve warning messages
erlend-aasland Aug 6, 2023
ce8db9a
Simplify condition
erlend-aasland Aug 6, 2023
0dff20c
Merge remote-tracking branch 'origin/ac-deprecate' into ac-deprecate
erlend-aasland Aug 6, 2023
b45d845
Refactor: extract pprinter
erlend-aasland Aug 6, 2023
d2330c6
Reintroduce condition and fixup deprecation message
erlend-aasland Aug 6, 2023
622b556
Remove unused variable, and reorder some lines for readability
erlend-aasland Aug 6, 2023
e71fbe1
Simplify pprint_words
erlend-aasland Aug 6, 2023
c4141f0
Fix function name formatting
erlend-aasland Aug 6, 2023
87e50c7
Use fully qualified function/meth name in fail() messages
erlend-aasland Aug 6, 2023
6e9e7b4
Add more test cases and normalise the their naming
erlend-aasland Aug 6, 2023
bde0f90
Improve deprecation messages
erlend-aasland Aug 6, 2023
8e9ea05
Pull in main
erlend-aasland Aug 7, 2023
8324510
ValueError will catch if '.' not in thenceforth for us
erlend-aasland Aug 7, 2023
2e4d64f
Improve NEWS entry
erlend-aasland Aug 7, 2023
52e7078
Update Misc/NEWS.d/next/Tools-Demos/2022-07-23-00-33-28.gh-issue-9506…
erlend-aasland Aug 7, 2023
8a39ffb
Fix grammar in depr sentence
erlend-aasland Aug 7, 2023
dc8f10d
Merge remote-tracking branch 'origin/ac-deprecate' into ac-deprecate
erlend-aasland Aug 7, 2023
d2130ab
Fix fixup code and add test
erlend-aasland Aug 7, 2023
b21bc32
Revert "Fix fixup code and add test"
erlend-aasland Aug 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions Doc/howto/clinic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1898,3 +1898,91 @@ blocks embedded in Python files look slightly different. They look like this:
#[python start generated code]*/
def foo(): pass
#/*[python checksum:...]*/


.. _clinic-howto-deprecate-positional:

How to deprecate passing parameters positionally
------------------------------------------------

Argument Clinic provides syntax that makes it possible to generate code that
deprecates passing :term:`arguments <argument>` positionally.
For example, say we've got a module-level function :py:func:`!foo.myfunc`
that has three :term:`parameters <parameter>`:
positional-or-keyword parameters *a* and *b*, and a keyword-only parameter *c*::

/*[clinic input]
module foo
myfunc
a: int
b: int
*
c: int
[clinic start generated output]*/

We now want to make the *b* parameter keyword-only;
however, we'll have to wait two releases before making this change,
as mandated by Python's backwards-compatibility policy (see :pep:`387`).
For this example, imagine we're in the development phase for Python 3.12:
that means we'll be allowed to introduce deprecation warnings in Python 3.12
whenever the *b* parameter is passed positionally,
and we'll be allowed to make it keyword-only in Python 3.14 at the earliest.

We can use Argument Clinic to emit the desired deprecation warnings
using the ``* [from ...]``` syntax,
by adding the line ``* [from 3.14]`` right above the *b* parameter::

/*[clinic input]
module foo
myfunc
a: int
* [from 3.14]
b: int
*
c: int
[clinic start generated output]*/

Next, regenerate Argument Clinic code (``make clinic``),
and add unit tests for the new behaviour.

The generated code will now emit a :exc:`DeprecationWarning`
when an :term:`argument` for the :term:`parameter` *b* is passed positionally.
C preprocessor directives are also generated for emitting
compiler warnings if the ``* [from ...]`` line has not been removed
from the Argument Clinic input when the deprecation period is over,
which means when the alpha phase of the specified Python version kicks in.

Let's return to our example and skip ahead two years:
Python 3.14 development has now entered the alpha phase,
but we forgot all about updating the Argument Clinic code
for :py:func:`!myfunc`!
Luckily for us, compiler warnings are now generated:

.. code-block:: none

In file included from Modules/foomodule.c:139:
Modules/clinic/foomodule.c.h:83:8: warning: Update 'b' in 'myfunc' in 'foomodule.c' to be keyword-only. [-W#warnings]
# warning "Update 'b' in 'myfunc' in 'foomodule.c' to be keyword-only."
^

We now close the deprecation phase by making *b* keyword-only;
replace the ``* [from ...]``` line above *b*
with the ``*`` from the line above *c*::

/*[clinic input]
module foo
myfunc
a: int
*
b: int
c: int
[clinic start generated output]*/

Finally, run ``make clinic`` to regenerate the Argument Clinic code,
and update your unit tests to reflect the new behaviour.
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved

.. note::

If you forget to update your input block during the alpha and beta phases,
the compiler warning will turn into a compiler error when the
release candidate phase begins.
Loading
Loading