Skip to content

Commit 63c945a

Browse files
[3.11] gh-106970: Fix Argument Clinic 'destination <name> clear' command (#106972) (#107059)
Add test for the 'destination <name> clear' command, and the 'destination' directive in general. Fix two bugs in 'destination <name> clear' command: 1. The text attribute of the allocator is called 'text', not '_text' 2. Return after processing the 'clear' command, instead of proceeding directly to the fail(). (cherry picked from commit 3372bcb)
1 parent b711441 commit 63c945a

File tree

3 files changed

+74
-9
lines changed

3 files changed

+74
-9
lines changed

Lib/test/clinic.test.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4192,3 +4192,59 @@ Test_meth_coexist(TestObj *self, PyObject *Py_UNUSED(ignored))
41924192
static PyObject *
41934193
Test_meth_coexist_impl(TestObj *self)
41944194
/*[clinic end generated code: output=808a293d0cd27439 input=2a1d75b5e6fec6dd]*/
4195+
4196+
4197+
/*[clinic input]
4198+
output push
4199+
output preset buffer
4200+
[clinic start generated code]*/
4201+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=5bff3376ee0df0b5]*/
4202+
4203+
/*[clinic input]
4204+
buffer_clear
4205+
a: int
4206+
We'll call 'destination buffer clear' after this.
4207+
4208+
Argument Clinic's buffer preset puts most generated code into the
4209+
'buffer' destination, except from 'impl_definition', which is put into
4210+
the 'block' destination, so we should expect everything but
4211+
'impl_definition' to be cleared.
4212+
[clinic start generated code]*/
4213+
4214+
static PyObject *
4215+
buffer_clear_impl(PyObject *module, int a)
4216+
/*[clinic end generated code: output=f14bba74677e1846 input=a4c308a6fdab043c]*/
4217+
4218+
/*[clinic input]
4219+
destination buffer clear
4220+
output pop
4221+
[clinic start generated code]*/
4222+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=f20d06adb8252084]*/
4223+
4224+
4225+
/*[clinic input]
4226+
output push
4227+
destination test1 new buffer
4228+
output everything suppress
4229+
output docstring_definition test1
4230+
[clinic start generated code]*/
4231+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=5a77c454970992fc]*/
4232+
4233+
/*[clinic input]
4234+
new_dest
4235+
a: int
4236+
Only this docstring should be outputted to test1.
4237+
[clinic start generated code]*/
4238+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=da5af421ed8996ed]*/
4239+
4240+
/*[clinic input]
4241+
dump test1
4242+
output pop
4243+
[clinic start generated code]*/
4244+
4245+
PyDoc_STRVAR(new_dest__doc__,
4246+
"new_dest($module, /, a)\n"
4247+
"--\n"
4248+
"\n"
4249+
"Only this docstring should be outputted to test1.");
4250+
/*[clinic end generated code: output=9cac703f51d90e84 input=090db8df4945576d]*/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix bugs in the Argument Clinic ``destination <name> clear`` command; the
2+
destination buffers would never be cleared, and the ``destination``
3+
directive parser would simply continue to the fault handler after processing
4+
the command. Patch by Erlend E. Aasland.

Tools/clinic/clinic.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,7 @@ def __getitem__(self, i):
17981798

17991799
def clear(self):
18001800
for ta in self._array:
1801-
ta._text.clear()
1801+
ta.text.clear()
18021802

18031803
def dump(self):
18041804
texts = [ta.output() for ta in self._array]
@@ -4121,14 +4121,19 @@ def directive_set(self, name, value):
41214121

41224122
self.clinic.__dict__[name] = value
41234123

4124-
def directive_destination(self, name, command, *args):
4125-
if command == 'new':
4126-
self.clinic.add_destination(name, *args)
4127-
return
4128-
4129-
if command == 'clear':
4130-
self.clinic.get_destination(name).clear()
4131-
fail("unknown destination command", repr(command))
4124+
def directive_destination(
4125+
self,
4126+
name: str,
4127+
command: str,
4128+
*args
4129+
) -> None:
4130+
match command:
4131+
case "new":
4132+
self.clinic.add_destination(name, *args)
4133+
case "clear":
4134+
self.clinic.get_destination(name).clear()
4135+
case _:
4136+
fail("unknown destination command", repr(command))
41324137

41334138

41344139
def directive_output(self, command_or_name, destination=''):

0 commit comments

Comments
 (0)