Skip to content

Commit bc2a7d7

Browse files
committed
Check Misc/NEWS.d/next/ for reStructuredText issues.
1 parent fc3dca3 commit bc2a7d7

7 files changed

+74
-13
lines changed

Doc/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ dist:
202202

203203
check:
204204
$(PYTHON) tools/rstlint.py -i tools -i $(VENVDIR) -i README.rst
205+
$(PYTHON) tools/rstlint.py ../Misc/NEWS.d/next/
205206

206207
serve:
207208
$(PYTHON) ../Tools/scripts/serve.py build/html

Doc/tools/rstlint.py

+61
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import re
1414
import sys
1515
import getopt
16+
from string import ascii_letters
1617
from os.path import join, splitext, abspath, exists
1718
from collections import defaultdict
1819

@@ -128,6 +129,66 @@ def check_leaked_markup(fn, lines):
128129
yield lno+1, 'possibly leaked markup: %r' % line
129130

130131

132+
def hide_literal_blocks(lines):
133+
"""Tool to remove literal blocks from given lines.
134+
135+
It yields empty lines in place of blocks, so line numbers are
136+
still meaningfull.
137+
"""
138+
in_block = False
139+
for line in lines:
140+
if line.endswith("::\n"):
141+
in_block = True
142+
elif in_block:
143+
if line == "\n" or line.startswith(" "):
144+
line = "\n"
145+
else:
146+
in_block = False
147+
yield line
148+
149+
def hide_comments(lines):
150+
"""Tool to remove comments from given lines.
151+
152+
It yields empty lines in place of comments, so line numbers are
153+
still meaningfull.
154+
"""
155+
in_multiline_comment = False
156+
for line in lines:
157+
if line == "..\n":
158+
in_multiline_comment = True
159+
elif in_multiline_comment:
160+
if line == "\n" or line.startswith(" "):
161+
line = "\n"
162+
else:
163+
in_multiline_comment = False
164+
if line.startswith(".. "):
165+
line = "\n"
166+
yield line
167+
168+
169+
170+
@checker(".rst", severity=2)
171+
def check_missing_surrogate_space_on_plural(fn, lines):
172+
r"""Check for missing 'backslash-space' between a code sample a letter.
173+
174+
Good: ``Point``\ s
175+
Bad: ``Point``s
176+
"""
177+
in_code_sample = False
178+
check_next_one = False
179+
for lno, line in enumerate(hide_comments(hide_literal_blocks(lines))):
180+
tokens = line.split("``")
181+
for token_no, token in enumerate(tokens):
182+
if check_next_one:
183+
if token[0] in ascii_letters:
184+
yield lno + 1, f"Missing backslash-space between code sample and {token!r}."
185+
check_next_one = False
186+
if token_no == len(tokens) - 1:
187+
continue
188+
if in_code_sample:
189+
check_next_one = True
190+
in_code_sample = not in_code_sample
191+
131192
def main(argv):
132193
usage = '''\
133194
Usage: %s [-v] [-f] [-s sev] [-i path]* [path]
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
The ``__args__`` of the parameterized generics for :data:`typing.Callable`
2-
and :class:`collections.abc.Callable` are now consistent. The ``__args__``
3-
for :class:`collections.abc.Callable` are now flattened while
4-
:data:`typing.Callable`'s have not changed. To allow this change,
5-
:class:`types.GenericAlias` can now be subclassed and
2+
and :class:`collections.abc.Callable` are now consistent. The ``__args__``
3+
for :class:`collections.abc.Callable` are now flattened while
4+
:data:`typing.Callable`'s have not changed. To allow this change,
5+
:class:`types.GenericAlias` can now be subclassed and
66
``collections.abc.Callable``'s ``__class_getitem__`` will now return a subclass
7-
of ``types.GenericAlias``. Tests for typing were also updated to not subclass
7+
of ``types.GenericAlias``. Tests for typing were also updated to not subclass
88
things like ``Callable[..., T]`` as that is not a valid base class. Finally,
9-
both ``Callable``\ s no longer validate their ``argtypes``, in
10-
``Callable[[argtypes], resulttype]`` to prepare for :pep:`612`. Patch by Ken Jin.
11-
9+
both ``Callable``\ s no longer validate their ``argtypes``, in
10+
``Callable[[argtypes], resulttype]`` to prepare for :pep:`612`. Patch by Ken Jin.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
fix `format()` behavior for `IntFlag`
1+
fix ``format()`` behavior for ``IntFlag``
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
`Enum`: call `__init_subclass__` after members have been added
1+
``Enum``: call ``__init_subclass__`` after members have been added
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[tarfile] update nested exception raising to use `from None` or `from e`
1+
[tarfile] update nested exception raising to use ``from None`` or ``from e``
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
`logging.disable` will now validate the types and value of its parameter. It
2-
also now accepts strings representing the levels (as does `loging.setLevel`)
1+
``logging.disable`` will now validate the types and value of its parameter. It
2+
also now accepts strings representing the levels (as does ``loging.setLevel``)
33
instead of only the numerical values.

0 commit comments

Comments
 (0)