Skip to content

Commit 20a6a43

Browse files
committed
Begin enforcing docstring length in Argument Clinic
1 parent b36d23f commit 20a6a43

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
OVERLONG_DOCSTRINGS = frozenset((
2+
'_abc._abc_instancecheck',
3+
'_abc._abc_register',
4+
'_abc._abc_subclasscheck',
5+
'_codecs.lookup',
6+
'_functools.reduce',
7+
'_hashlib.pbkdf2_hmac',
8+
'_io._BufferedIOBase.read1',
9+
'_jit.is_active',
10+
'_jit.is_available',
11+
'_jit.is_enabled',
12+
'_lzma._decode_filter_properties',
13+
'_remote_debugging.RemoteUnwinder.get_async_stack_trace',
14+
'_socket.inet_aton',
15+
'_sre.SRE_Match.expand',
16+
'_sre.SRE_Match.groupdict',
17+
'_sre.SRE_Pattern.finditer',
18+
'_sre.SRE_Pattern.search',
19+
'_sre.SRE_Pattern.sub',
20+
'_sre.SRE_Pattern.subn',
21+
'_ssl._SSLContext.sni_callback',
22+
'_ssl._SSLSocket.pending',
23+
'_ssl.get_default_verify_paths',
24+
'_ssl.RAND_status',
25+
'_sysconfig.config_vars',
26+
'_testcapi.make_exception_with_doc',
27+
'_tkinter.getbusywaitinterval',
28+
'_tkinter.setbusywaitinterval',
29+
'array.array.buffer_info',
30+
'array.array.frombytes',
31+
'array.array.tobytes',
32+
'bytearray.count',
33+
'bytearray.find',
34+
'bytearray.index',
35+
'bytearray.rfind',
36+
'bytearray.rindex',
37+
'bytes.count',
38+
'bytes.find',
39+
'bytes.index',
40+
'bytes.rfind',
41+
'bytes.rindex',
42+
'itertools.chain.from_iterable',
43+
'itertools.combinations_with_replacement.__new__',
44+
'itertools.cycle.__new__',
45+
'itertools.starmap.__new__',
46+
'itertools.takewhile.__new__',
47+
'math.comb',
48+
'msvcrt.kbhit',
49+
'OrderedDict.pop',
50+
'os.pwritev',
51+
'os.sched_getaffinity',
52+
'os.timerfd_gettime',
53+
'os.timerfd_gettime_ns',
54+
'pyexpat.xmlparser.ExternalEntityParserCreate',
55+
'pyexpat.xmlparser.GetReparseDeferralEnabled',
56+
'pyexpat.xmlparser.UseForeignDTD',
57+
'str.count',
58+
'str.find',
59+
'str.index',
60+
'str.rfind',
61+
'str.rindex',
62+
'str.rsplit',
63+
'str.split',
64+
'sys._setprofileallthreads',
65+
'sys._settraceallthreads',
66+
'unicodedata.UCD.decomposition',
67+
'zoneinfo.ZoneInfo.dst',
68+
'zoneinfo.ZoneInfo.tzname',
69+
'zoneinfo.ZoneInfo.utcoffset',
70+
))

Tools/clinic/libclinic/dsl_parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from libclinic import (
1515
ClinicError, VersionTuple,
1616
fail, warn, unspecified, unknown, NULL)
17+
from libclinic._overlong_docstrings import OVERLONG_DOCSTRINGS
1718
from libclinic.function import (
1819
Module, Class, Function, Parameter,
1920
FunctionKind,
@@ -1509,6 +1510,9 @@ def format_docstring(self) -> str:
15091510
fail(f"Docstring for {f.full_name!r} does not have a summary line!\n"
15101511
"Every non-blank function docstring must start with "
15111512
"a single line summary followed by an empty line.")
1513+
if len(lines[0]) > 80 and f.full_name not in OVERLONG_DOCSTRINGS:
1514+
fail(f"Summary line {f.full_name!r} is too long!\n"
1515+
"The summary line must be no longer than 80 characters.")
15121516
elif len(lines) == 1:
15131517
# the docstring is only one line right now--the summary line.
15141518
# add an empty line after the summary line so we have space

Tools/clinic/libclinic/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __post_init__(self) -> None:
1515
def report(self, *, warn_only: bool = False) -> str:
1616
msg = "Warning" if warn_only else "Error"
1717
if self.filename is not None:
18-
msg += f" in file {self.filename!r}"
18+
msg += f" in file '{self.filename}'"
1919
if self.lineno is not None:
2020
msg += f" on line {self.lineno}"
2121
msg += ":\n"

0 commit comments

Comments
 (0)