[Python-checkins] bpo-42238: Check Misc/NEWS.d/next/ for reStructuredText issues. (GH-23802)

JulienPalard webhook-mailer at python.org
Fri Dec 18 04:48:15 EST 2020


https://github.com/python/cpython/commit/b9735420aa8ecd2555fe3dc000863bc50487334b
commit: b9735420aa8ecd2555fe3dc000863bc50487334b
branch: master
author: Julien Palard <julien at palard.fr>
committer: JulienPalard <julien at palard.fr>
date: 2020-12-18T10:48:08+01:00
summary:

bpo-42238: Check Misc/NEWS.d/next/ for reStructuredText issues. (GH-23802)

files:
M Doc/Makefile
M Doc/tools/rstlint.py
M Misc/NEWS.d/next/Core and Builtins/2020-11-20-00-57-47.bpo-42195.HeqcpS.rst
M Misc/NEWS.d/next/Library/2020-10-02-10-19-49.bpo-41907.wiIEsz.rst
M Misc/NEWS.d/next/Library/2020-12-08-22-43-35.bpo-42678.ba9ktU.rst
M Misc/NEWS.d/next/Library/2020-12-10-18-36-52.bpo-39717.sK2u0w.rst
M Misc/NEWS.d/next/Library/2020-12-15-10-00-04.bpo-42644.XgLCNx.rst

diff --git a/Doc/Makefile b/Doc/Makefile
index c24c70c699a06..f113dd0653986 100644
--- a/Doc/Makefile
+++ b/Doc/Makefile
@@ -202,6 +202,7 @@ dist:
 
 check:
 	$(PYTHON) tools/rstlint.py -i tools -i $(VENVDIR) -i README.rst
+	$(PYTHON) tools/rstlint.py ../Misc/NEWS.d/next/
 
 serve:
 	$(PYTHON) ../Tools/scripts/serve.py build/html
diff --git a/Doc/tools/rstlint.py b/Doc/tools/rstlint.py
index a3024d6734d25..cbcb8eb801b13 100755
--- a/Doc/tools/rstlint.py
+++ b/Doc/tools/rstlint.py
@@ -13,6 +13,7 @@
 import re
 import sys
 import getopt
+from string import ascii_letters
 from os.path import join, splitext, abspath, exists
 from collections import defaultdict
 
@@ -128,6 +129,81 @@ def check_leaked_markup(fn, lines):
             yield lno+1, 'possibly leaked markup: %r' % line
 
 
+def hide_literal_blocks(lines):
+    """Tool to remove literal blocks from given lines.
+
+    It yields empty lines in place of blocks, so line numbers are
+    still meaningful.
+    """
+    in_block = False
+    for line in lines:
+        if line.endswith("::\n"):
+            in_block = True
+        elif in_block:
+            if line == "\n" or line.startswith(" "):
+                line = "\n"
+            else:
+                in_block = False
+        yield line
+
+
+def type_of_explicit_markup(line):
+    if re.match(fr'\.\. {all_directives}::', line):
+        return 'directive'
+    if re.match(r'\.\. \[[0-9]+\] ', line):
+        return 'footnote'
+    if re.match(r'\.\. \[[^\]]+\] ', line):
+        return 'citation'
+    if re.match(r'\.\. _.*[^_]: ', line):
+        return 'target'
+    if re.match(r'\.\. \|[^\|]*\| ', line):
+        return 'substitution_definition'
+    return 'comment'
+
+
+def hide_comments(lines):
+    """Tool to remove comments from given lines.
+
+    It yields empty lines in place of comments, so line numbers are
+    still meaningfull.
+    """
+    in_multiline_comment = False
+    for line in lines:
+        if line == "..\n":
+            in_multiline_comment = True
+        elif in_multiline_comment:
+            if line == "\n" or line.startswith(" "):
+                line = "\n"
+            else:
+                in_multiline_comment = False
+        if line.startswith(".. ") and type_of_explicit_markup(line) == 'comment':
+            line = "\n"
+        yield line
+
+
+
+ at checker(".rst", severity=2)
+def check_missing_surrogate_space_on_plural(fn, lines):
+    r"""Check for missing 'backslash-space' between a code sample a letter.
+
+    Good: ``Point``\ s
+    Bad: ``Point``s
+    """
+    in_code_sample = False
+    check_next_one = False
+    for lno, line in enumerate(hide_comments(hide_literal_blocks(lines))):
+        tokens = line.split("``")
+        for token_no, token in enumerate(tokens):
+            if check_next_one:
+                if token[0] in ascii_letters:
+                    yield lno + 1, f"Missing backslash-space between code sample and {token!r}."
+                check_next_one = False
+            if token_no == len(tokens) - 1:
+                continue
+            if in_code_sample:
+                check_next_one = True
+            in_code_sample = not in_code_sample
+
 def main(argv):
     usage = '''\
 Usage: %s [-v] [-f] [-s sev] [-i path]* [path]
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-11-20-00-57-47.bpo-42195.HeqcpS.rst b/Misc/NEWS.d/next/Core and Builtins/2020-11-20-00-57-47.bpo-42195.HeqcpS.rst
index fec4b7f81cb45..87e8c0e89b3b8 100644
--- a/Misc/NEWS.d/next/Core and Builtins/2020-11-20-00-57-47.bpo-42195.HeqcpS.rst	
+++ b/Misc/NEWS.d/next/Core and Builtins/2020-11-20-00-57-47.bpo-42195.HeqcpS.rst	
@@ -1,11 +1,10 @@
 The ``__args__`` of the parameterized generics for :data:`typing.Callable`
-and :class:`collections.abc.Callable` are now consistent.  The ``__args__`` 
-for :class:`collections.abc.Callable` are now flattened while 
-:data:`typing.Callable`'s have not changed.  To allow this change, 
-:class:`types.GenericAlias` can now be subclassed and 
+and :class:`collections.abc.Callable` are now consistent.  The ``__args__``
+for :class:`collections.abc.Callable` are now flattened while
+:data:`typing.Callable`'s have not changed.  To allow this change,
+:class:`types.GenericAlias` can now be subclassed and
 ``collections.abc.Callable``'s ``__class_getitem__`` will now return a subclass
-of ``types.GenericAlias``.  Tests for typing were also updated to not subclass 
+of ``types.GenericAlias``.  Tests for typing were also updated to not subclass
 things like ``Callable[..., T]`` as that is not a valid base class.  Finally,
-both ``Callable``\ s no longer validate their ``argtypes``, in 
-``Callable[[argtypes], resulttype]`` to prepare for :pep:`612`.  Patch by Ken Jin.  
-
+both ``Callable``\ s no longer validate their ``argtypes``, in
+``Callable[[argtypes], resulttype]`` to prepare for :pep:`612`.  Patch by Ken Jin.
diff --git a/Misc/NEWS.d/next/Library/2020-10-02-10-19-49.bpo-41907.wiIEsz.rst b/Misc/NEWS.d/next/Library/2020-10-02-10-19-49.bpo-41907.wiIEsz.rst
index aa337b38046e6..2c7b70d589d83 100644
--- a/Misc/NEWS.d/next/Library/2020-10-02-10-19-49.bpo-41907.wiIEsz.rst
+++ b/Misc/NEWS.d/next/Library/2020-10-02-10-19-49.bpo-41907.wiIEsz.rst
@@ -1 +1 @@
-fix `format()` behavior for `IntFlag`
+fix ``format()`` behavior for ``IntFlag``
diff --git a/Misc/NEWS.d/next/Library/2020-12-08-22-43-35.bpo-42678.ba9ktU.rst b/Misc/NEWS.d/next/Library/2020-12-08-22-43-35.bpo-42678.ba9ktU.rst
index 7c94cdf40dd4c..4b2ced5c148af 100644
--- a/Misc/NEWS.d/next/Library/2020-12-08-22-43-35.bpo-42678.ba9ktU.rst
+++ b/Misc/NEWS.d/next/Library/2020-12-08-22-43-35.bpo-42678.ba9ktU.rst
@@ -1 +1 @@
-`Enum`: call `__init_subclass__` after members have been added
+``Enum``: call ``__init_subclass__`` after members have been added
diff --git a/Misc/NEWS.d/next/Library/2020-12-10-18-36-52.bpo-39717.sK2u0w.rst b/Misc/NEWS.d/next/Library/2020-12-10-18-36-52.bpo-39717.sK2u0w.rst
index fcbf99925208b..6f3691f591f2b 100644
--- a/Misc/NEWS.d/next/Library/2020-12-10-18-36-52.bpo-39717.sK2u0w.rst
+++ b/Misc/NEWS.d/next/Library/2020-12-10-18-36-52.bpo-39717.sK2u0w.rst
@@ -1 +1 @@
-[tarfile] update nested exception raising to use `from None` or `from e`
+[tarfile] update nested exception raising to use ``from None`` or ``from e``
diff --git a/Misc/NEWS.d/next/Library/2020-12-15-10-00-04.bpo-42644.XgLCNx.rst b/Misc/NEWS.d/next/Library/2020-12-15-10-00-04.bpo-42644.XgLCNx.rst
index f58b58e4002ad..ee4d111dc349a 100644
--- a/Misc/NEWS.d/next/Library/2020-12-15-10-00-04.bpo-42644.XgLCNx.rst
+++ b/Misc/NEWS.d/next/Library/2020-12-15-10-00-04.bpo-42644.XgLCNx.rst
@@ -1,3 +1,3 @@
-`logging.disable` will now validate the types and value of its parameter. It
-also now accepts strings representing the levels (as does `loging.setLevel`)
+``logging.disable`` will now validate the types and value of its parameter. It
+also now accepts strings representing the levels (as does ``loging.setLevel``)
 instead of only the numerical values.



More information about the Python-checkins mailing list