Skip to content

Commit c3f92f6

Browse files
gh-113317: Clean up Argument Clinic global namespace (#113414)
Split up clinic.py by establishing libclinic as a support package for Argument Clinic. Get rid of clinic.py globals by either making them class members, or by putting them into libclinic. - Move INCLUDE_COMMENT_COLUMN to BlockPrinter - Move NO_VARARG to CLanguage - Move formatting helpers to libclinic - Move some constants to libclinic (and annotate them as Final)
1 parent 9c3ddf3 commit c3f92f6

File tree

4 files changed

+185
-135
lines changed

4 files changed

+185
-135
lines changed

Lib/test/test_clinic.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
test_tools.skip_if_missing('clinic')
1818
with test_tools.imports_under_tool('clinic'):
19+
import libclinic
1920
import clinic
2021
from clinic import DSLParser
2122

@@ -3761,19 +3762,19 @@ def test_normalize_snippet(self):
37613762
actual = clinic.normalize_snippet(snippet, indent=indent)
37623763
self.assertEqual(actual, expected)
37633764

3764-
def test_quoted_for_c_string(self):
3765+
def test_escaped_docstring(self):
37653766
dataset = (
37663767
# input, expected
3767-
(r"abc", r"abc"),
3768-
(r"\abc", r"\\abc"),
3769-
(r"\a\bc", r"\\a\\bc"),
3770-
(r"\a\\bc", r"\\a\\\\bc"),
3771-
(r'"abc"', r'\"abc\"'),
3772-
(r"'a'", r"\'a\'"),
3768+
(r"abc", r'"abc"'),
3769+
(r"\abc", r'"\\abc"'),
3770+
(r"\a\bc", r'"\\a\\bc"'),
3771+
(r"\a\\bc", r'"\\a\\\\bc"'),
3772+
(r'"abc"', r'"\"abc\""'),
3773+
(r"'a'", r'"\'a\'"'),
37733774
)
37743775
for line, expected in dataset:
37753776
with self.subTest(line=line, expected=expected):
3776-
out = clinic.quoted_for_c_string(line)
3777+
out = libclinic.docstring_for_c_string(line)
37773778
self.assertEqual(out, expected)
37783779

37793780
def test_format_escape(self):
@@ -3784,7 +3785,7 @@ def test_format_escape(self):
37843785

37853786
def test_indent_all_lines(self):
37863787
# Blank lines are expected to be unchanged.
3787-
self.assertEqual(clinic.indent_all_lines("", prefix="bar"), "")
3788+
self.assertEqual(libclinic.indent_all_lines("", prefix="bar"), "")
37883789

37893790
lines = (
37903791
"one\n"
@@ -3794,7 +3795,7 @@ def test_indent_all_lines(self):
37943795
"barone\n"
37953796
"bartwo"
37963797
)
3797-
out = clinic.indent_all_lines(lines, prefix="bar")
3798+
out = libclinic.indent_all_lines(lines, prefix="bar")
37983799
self.assertEqual(out, expected)
37993800

38003801
# If last line is empty, expect it to be unchanged.
@@ -3810,12 +3811,12 @@ def test_indent_all_lines(self):
38103811
"bartwo\n"
38113812
""
38123813
)
3813-
out = clinic.indent_all_lines(lines, prefix="bar")
3814+
out = libclinic.indent_all_lines(lines, prefix="bar")
38143815
self.assertEqual(out, expected)
38153816

38163817
def test_suffix_all_lines(self):
38173818
# Blank lines are expected to be unchanged.
3818-
self.assertEqual(clinic.suffix_all_lines("", suffix="foo"), "")
3819+
self.assertEqual(libclinic.suffix_all_lines("", suffix="foo"), "")
38193820

38203821
lines = (
38213822
"one\n"
@@ -3825,7 +3826,7 @@ def test_suffix_all_lines(self):
38253826
"onefoo\n"
38263827
"twofoo"
38273828
)
3828-
out = clinic.suffix_all_lines(lines, suffix="foo")
3829+
out = libclinic.suffix_all_lines(lines, suffix="foo")
38293830
self.assertEqual(out, expected)
38303831

38313832
# If last line is empty, expect it to be unchanged.
@@ -3841,7 +3842,7 @@ def test_suffix_all_lines(self):
38413842
"twofoo\n"
38423843
""
38433844
)
3844-
out = clinic.suffix_all_lines(lines, suffix="foo")
3845+
out = libclinic.suffix_all_lines(lines, suffix="foo")
38453846
self.assertEqual(out, expected)
38463847

38473848

0 commit comments

Comments
 (0)