|
14 | 14 | from libclinic import (
|
15 | 15 | ClinicError, VersionTuple,
|
16 | 16 | fail, warn, unspecified, unknown, NULL)
|
17 |
| -from libclinic._overlong_docstrings import OVERLONG_SUMMARY, OVERLONG_BODY |
18 | 17 | from libclinic.function import (
|
19 | 18 | Module, Class, Function, Parameter,
|
20 | 19 | FunctionKind,
|
@@ -263,6 +262,8 @@ class DSLParser:
|
263 | 262 | target_critical_section: list[str]
|
264 | 263 | disable_fastcall: bool
|
265 | 264 | from_version_re = re.compile(r'([*/]) +\[from +(.+)\]')
|
| 265 | + permit_long_summary = False |
| 266 | + permit_long_docstring_body = False |
266 | 267 |
|
267 | 268 | def __init__(self, clinic: Clinic) -> None:
|
268 | 269 | self.clinic = clinic
|
@@ -299,6 +300,8 @@ def reset(self) -> None:
|
299 | 300 | self.critical_section = False
|
300 | 301 | self.target_critical_section = []
|
301 | 302 | self.disable_fastcall = False
|
| 303 | + self.permit_long_summary = False |
| 304 | + self.permit_long_docstring_body = False |
302 | 305 |
|
303 | 306 | def directive_module(self, name: str) -> None:
|
304 | 307 | fields = name.split('.')[:-1]
|
@@ -471,6 +474,16 @@ def at_text_signature(self, text_signature: str) -> None:
|
471 | 474 | fail("Called @text_signature twice!")
|
472 | 475 | self.forced_text_signature = text_signature
|
473 | 476 |
|
| 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 | + |
474 | 487 | def parse(self, block: Block) -> None:
|
475 | 488 | self.reset()
|
476 | 489 | self.block = block
|
@@ -1523,20 +1536,22 @@ def format_docstring(self) -> str:
|
1523 | 1536 | summary_len = len(lines[0])
|
1524 | 1537 | max_body = max(map(len, lines[1:]))
|
1525 | 1538 | if summary_len > max_width:
|
1526 |
| - if f.full_name not in OVERLONG_SUMMARY: |
| 1539 | + if not self.permit_long_summary: |
1527 | 1540 | fail(f"Summary line for {f.full_name!r} is too long!\n"
|
1528 | 1541 | f"The summary line must be no longer than {max_width} characters.")
|
1529 | 1542 | 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") |
1532 | 1546 |
|
1533 | 1547 | if max_body > max_width:
|
1534 |
| - if f.full_name not in OVERLONG_BODY: |
| 1548 | + if not self.permit_long_docstring_body: |
1535 | 1549 | warn(f"Docstring lines for {f.full_name!r} are too long!\n"
|
1536 | 1550 | f"Lines should be no longer than {max_width} characters.")
|
1537 | 1551 | 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") |
1540 | 1555 |
|
1541 | 1556 | parameters_marker_count = len(f.docstring.split('{parameters}')) - 1
|
1542 | 1557 | if parameters_marker_count > 1:
|
|
0 commit comments