10000 gh-106970: Fix Argument Clinic 'destination <name> clear' command (#1… · python/cpython@3372bcb · GitHub
[go: up one dir, main page]

Skip to content

Commit 3372bcb

Browse files
gh-106970: Fix Argument Clinic 'destination <name> clear' command (#106972)
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().
1 parent cdeb1a6 commit 3372bcb
< 10000 span class="CopyToClipboardButton-module__tooltip--Dq1IB prc-TooltipV2-Tooltip-cYMVY" data-direction="sw" aria-label="Copy full SHA for 3372bcb" aria-hidden="true" id=":R4lebab:">Copy full SHA for 3372bcb

File tree

4 files changed

+77
-8
lines changed

4 files changed

+77
-8
lines changed

Lib/test/clinic.test.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4948,3 +4948,59 @@ Test_meth_coexist(TestObj *self, PyObject *Py_UNUSED(ignored))
49484948
static PyObject *
49494949
Test_meth_coexist_impl(TestObj *self)
49504950
/*[clinic end generated code: output=808a293d0cd27439 input=2a1d75b5e6fec6dd]*/
4951+
4952+
4953+
/*[clinic input]
4954+
output push
4955+
output preset buffer
4956+
[clinic start generated code]*/
4957+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=5bff3376ee0df0b5]*/
4958+
4959+
/*[clinic input]
4960+
buffer_clear
4961+
a: int
4962+
We'll call 'destination buffer clear' after this.
4963+
4964+
Argument Clinic's buffer preset puts most generated code into the
4965+
'buffer' destination, except from 'impl_definition', which is put into
4966+
the 'block' destination, so we should expect everything but
4967+
'impl_definition' to be cleared.
4968+
[clinic start generated code]*/
4969+
4970+
static PyObject *
4971+
buffer_clear_impl(PyObject *module, int a)
4972+
/*[clinic end generated code: output=f14bba74677e1846 input=a4c308a6fdab043c]*/
4973+
4974+
/*[clinic input]
4975+
destination buffer clear
4976+
output pop
4977+
[clinic start generated code]*/
4978+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=f20d06adb8252084]*/
4979+
4980+
4981+
/*[clinic input]
4982+
output push
4983+
destination test1 new buffer
4984+
output everything suppress
4985+
output docstring_definition test1
4986+
[clinic start generated code]*/
4987+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=5a77c454970992fc]*/
4988+
4989+
/*[clinic input]
4990+
new_dest
4991+
a: int
4992+
Only this docstring should be outputted to test1.
4993+
[clinic start generated code]*/
4994+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=da5af421ed8996ed]*/
4995+
4996+
/*[clinic input]
4997+
dump test1
4998+
output pop
4999+
[clinic start generated code]*/
5000+
5001+
PyDoc_STRVAR(new_dest__doc__,
5002+
"new_dest($module, /, a)\n"
5003+
"--\n"
5004+
"\n"
5005+
"Only this docstring should be outputted to test1.");
5006+
/*[clinic end generated code: output=9cac703f51d90e84 input=090db8df4945576d]*/

Lib/test/test_clinic.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,15 @@ def test_cpp_monitor_fail_no_matching_if(self):
249249
out = self.expect_failure(raw)
250250
self.assertEqual(out, msg)
251251

252+
def test_unknown_destination_command(self):
253+
out = self.expect_failure("""
254+
/*[clinic input]
255+
destination buffer nosuchcommand
256+
[clinic start generated code]*/
257+
""")
258+
msg = "unknown destination command 'nosuchcommand'"
259+
self.assertIn(msg, out)
260+
252261

253262
class ClinicGroupPermuterTest(TestCase):
254263
def _test(self, l, m, r, output):
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: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,7 +1983,7 @@ def __getitem__(self, i):
19831983

19841984
def clear(self):
19851985
for ta in self._array:
1986-
ta._text.clear()
1986+
ta.text.clear()
19871987

19881988
def dump(self):
19891989
texts = [ta.output() for ta in self._array]
@@ -4487,13 +4487,13 @@ def directive_destination(
44874487
command: str,
44884488
*args
44894489
) -> None:
4490-
if command == 'new':
4491-
self.clinic.add_destination(name, *args)
4492-
return
4493-
4494-
if command == 'clear':
4495-
self.clinic.get_destination(name).clear()
4496-
fail("unknown destination command", repr(command))
4490+
match command:
4491+
case "new":
4492+
self.clinic.add_destination(name, *args)
4493+
case "clear":
4494+
self.clinic.get_destination(name).clear()
4495+
case _:
4496+
fail("unknown destination command", repr(command))
44974497

44984498

44994499
def directive_output(

0 commit comments

Comments
 (0)
0