Skip to content

Commit e01ba76

Browse files
committed
Use a decorator for docstring line length
1 parent 6baf552 commit e01ba76

File tree

2 files changed

+22
-306
lines changed

2 files changed

+22
-306
lines changed

Tools/clinic/libclinic/_overlong_docstrings.py

Lines changed: 0 additions & 299 deletions
This file was deleted.

Tools/clinic/libclinic/dsl_parser.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from libclinic import (
1515
ClinicError, VersionTuple,
1616
fail, warn, unspecified, unknown, NULL)
17-
from libclinic._overlong_docstrings import OVERLONG_SUMMARY, OVERLONG_BODY
1817
from libclinic.function import (
1918
Module, Class, Function, Parameter,
2019
FunctionKind,
@@ -263,6 +262,8 @@ class DSLParser:
263262
target_critical_section: list[str]
264263
disable_fastcall: bool
265264
from_version_re = re.compile(r'([*/]) +\[from +(.+)\]')
265+
permit_long_summary = False
266+
permit_long_docstring_body = False
266267

267268
def __init__(self, clinic: Clinic) -> None:
268269
self.clinic = clinic
@@ -299,6 +300,8 @@ def reset(self) -> None:
299300
self.critical_section = False
300301
self.target_critical_section = []
301302
self.disable_fastcall = False
303+
self.permit_long_summary = False
304+
self.permit_long_docstring_body = False
302305

303306
def directive_module(self, name: str) -> None:
304307
fields = name.split('.')[:-1]
@@ -471,6 +474,16 @@ def at_text_signature(self, text_signature: str) -> None:
471474
fail("Called @text_signature twice!")
472475
self.forced_text_signature = text_signature
473476

477+
def at_permit_long_summary(self) -> None:
478+
if self.permit_long_summary:
479+
fail("Called @permit_long_summary twice!")
480+
self.permit_long_summary = True
481+
482+
def at_permit_long_docstring_body(self) -> None:
483+
if self.permit_long_docstring_body:
484+
fail("Called @permit_long_docstring_body twice!")
485+
self.permit_long_docstring_body = True
486+
474487
def parse(self, block: Block) -> None:
475488
self.reset()
476489
self.block = block
@@ -1523,20 +1536,22 @@ def format_docstring(self) -> str:
15231536
summary_len = len(lines[0])
15241537
max_body = max(map(len, lines[1:]))
15251538
if summary_len > max_width:
1526-
if f.full_name not in OVERLONG_SUMMARY:
1539+
if not self.permit_long_summary:
15271540
fail(f"Summary line for {f.full_name!r} is too long!\n"
15281541
f"The summary line must be no longer than {max_width} characters.")
15291542
else:
1530-
if f.full_name in OVERLONG_SUMMARY:
1531-
warn(f"Remove {f.full_name!r} from OVERLONG_SUMMARY!\n")
1543+
if self.permit_long_summary:
1544+
warn("Remove the @permit_long_summary decorator from "
1545+
f"{f.full_name!r}!\n")
15321546

15331547
if max_body > max_width:
1534-
if f.full_name not in OVERLONG_BODY:
1548+
if not self.permit_long_docstring_body:
15351549
warn(f"Docstring lines for {f.full_name!r} are too long!\n"
15361550
f"Lines should be no longer than {max_width} characters.")
15371551
else:
1538-
if f.full_name in OVERLONG_BODY:
1539-
warn(f"Remove {f.full_name!r} from OVERLONG_BODY!\n")
1552+
if self.permit_long_docstring_body:
1553+
warn("Remove the @permit_long_docstring_body decorator from "
1554+
f"{f.full_name!r}!\n")
15401555

15411556
parameters_marker_count = len(f.docstring.split('{parameters}')) - 1
15421557
if parameters_marker_count > 1:

0 commit comments

Comments
 (0)