diff --git a/Makefile b/Makefile index 9d28459fc..d14e6a3ae 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ DONT_CHECK = -i build -i dist -i sphinx/style/jquery.js \ all: clean-pyc clean-backupfiles style-check type-check test style-check: - @$(PYTHON) utils/check_sources.py $(DONT_CHECK) . + @PYTHONWARNINGS=all $(PYTHON) utils/check_sources.py $(DONT_CHECK) . type-check: mypy sphinx/ diff --git a/sphinx/config.py b/sphinx/config.py index 12f206f96..3207b829b 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -171,7 +171,8 @@ class Config(object): if getenv('SOURCE_DATE_EPOCH') is not None: for k in ('copyright', 'epub_copyright'): if k in config: - config[k] = copyright_year_re.sub('\g<1>%s' % format_date('%Y'), config[k]) + config[k] = copyright_year_re.sub(r'\g<1>%s' % format_date('%Y'), + config[k]) def check_types(self): # type: () -> None diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index 2467e85ef..25ce4c648 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -116,7 +116,7 @@ class PyXrefMixin(object): def make_xrefs(self, rolename, domain, target, innernode=nodes.emphasis, contnode=None): # type: (unicode, unicode, unicode, nodes.Node, nodes.Node) -> List[nodes.Node] - delims = '(\s*[\[\]\(\),](?:\s*or\s)?\s*|\s+or\s+)' + delims = r'(\s*[\[\]\(\),](?:\s*or\s)?\s*|\s+or\s+)' delims_re = re.compile(delims) sub_targets = re.split(delims, target) diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index abd02877c..cd518f713 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -47,7 +47,7 @@ logger = logging.getLogger(__name__) # RE for option descriptions option_desc_re = re.compile(r'((?:/|--|-|\+)?[^\s=]+)(=?\s*.*)') # RE for grammar tokens -token_re = re.compile('`(\w+)`', re.U) +token_re = re.compile(r'`(\w+)`', re.U) class GenericObject(ObjectDescription): diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index 8d521a74d..7bf5ad5b8 100644 --- a/sphinx/ext/autosummary/__init__.py +++ b/sphinx/ext/autosummary/__init__.py @@ -357,7 +357,7 @@ class Autosummary(Directive): *items* is a list produced by :meth:`get_items`. """ table_spec = addnodes.tabular_col_spec() - table_spec['spec'] = 'p{0.5\linewidth}p{0.5\linewidth}' + table_spec['spec'] = r'p{0.5\linewidth}p{0.5\linewidth}' table = autosummary_table('') real_table = nodes.table('', classes=['longtable']) @@ -388,7 +388,7 @@ class Autosummary(Directive): for name, sig, summary, real_name in items: qualifier = 'obj' if 'nosignatures' not in self.options: - col1 = ':%s:`%s <%s>`\ %s' % (qualifier, name, real_name, rst.escape(sig)) # type: unicode # NOQA + col1 = ':%s:`%s <%s>`\\ %s' % (qualifier, name, real_name, rst.escape(sig)) # type: unicode # NOQA else: col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name) col2 = summary diff --git a/sphinx/pycode/__init__.py b/sphinx/pycode/__init__.py index bf8848305..d7c81e6f0 100644 --- a/sphinx/pycode/__init__.py +++ b/sphinx/pycode/__init__.py @@ -52,7 +52,7 @@ number2name.update(token.tok_name) _eq = nodes.Leaf(token.EQUAL, '=') -emptyline_re = re.compile('^\s*(#.*)?$') +emptyline_re = re.compile(r'^\s*(#.*)?$') class AttrDocVisitor(nodes.NodeVisitor): diff --git a/sphinx/roles.py b/sphinx/roles.py index 5dd815547..eb37b7ac7 100644 --- a/sphinx/roles.py +++ b/sphinx/roles.py @@ -293,7 +293,7 @@ def emph_literal_role(typ, rawtext, text, lineno, inliner, return [retnode], [] -_abbr_re = re.compile('\((.*)\)$', re.S) +_abbr_re = re.compile(r'\((.*)\)$', re.S) def abbr_role(typ, rawtext, text, lineno, inliner, options={}, content=[]): diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index cd34139eb..997983f28 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -556,7 +556,7 @@ def encode_uri(uri): def split_docinfo(text): # type: (unicode) -> Sequence[unicode] - docinfo_re = re.compile('\A((?:\s*:\w+:.*?\n(?:[ \t]+.*?\n)*)+)', re.M) + docinfo_re = re.compile('\\A((?:\\s*:\\w+:.*?\n(?:[ \\t]+.*?\n)*)+)', re.M) result = docinfo_re.split(text, 1) # type: ignore if len(result) == 1: return '', result[0] diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py index 38fdcde28..c50364fd9 100644 --- a/sphinx/util/docutils.py +++ b/sphinx/util/docutils.py @@ -21,7 +21,8 @@ from docutils.parsers.rst import directives, roles from sphinx.util import logging logger = logging.getLogger(__name__) -report_re = re.compile('^(.+?:\d+): \((DEBUG|INFO|WARNING|ERROR|SEVERE)/(\d+)?\) (.+?)\n?$') +report_re = re.compile('^(.+?:\\d+): \\((DEBUG|INFO|WARNING|ERROR|SEVERE)/(\\d+)?\\) ' + '(.+?)\n?$') if False: diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py index f5ddd036c..6bf47da1f 100644 --- a/sphinx/util/nodes.py +++ b/sphinx/util/nodes.py @@ -65,8 +65,8 @@ def apply_source_workaround(node): if isinstance(node, nodes.term): # strip classifier from rawsource of term for classifier in reversed(node.parent.traverse(nodes.classifier)): - node.rawsource = re.sub( - '\s*:\s*%s' % re.escape(classifier.astext()), '', node.rawsource) + node.rawsource = re.sub(r'\s*:\s*%s' % re.escape(classifier.astext()), + '', node.rawsource) # workaround: recommonmark-0.2.0 doesn't set rawsource attribute if not node.rawsource: diff --git a/sphinx/util/rst.py b/sphinx/util/rst.py index afb452f45..f49cb0c1d 100644 --- a/sphinx/util/rst.py +++ b/sphinx/util/rst.py @@ -11,7 +11,7 @@ import re -symbols_re = re.compile('([!-/:-@\[-`{-~])') +symbols_re = re.compile(r'([!-/:-@\[-`{-~])') def escape(text): diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 72b6e527a..9d919713d 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -371,7 +371,7 @@ class Table(object): This is what LaTeX calls the 'preamble argument' of the used table environment. - .. note:: the ``\X`` column type specifier is defined in ``sphinx.sty``. + .. note:: the ``\\X`` column type specifier is defined in ``sphinx.sty``. """ if self.colspec: return self.colspec @@ -456,13 +456,13 @@ class TableCell(object): def escape_abbr(text): # type: (unicode) -> unicode """Adjust spacing after abbreviations.""" - return re.sub('\.(?=\s|$)', '.\\@', text) + return re.sub(r'\.(?=\s|$)', r'.\@', text) def rstdim_to_latexdim(width_str): # type: (unicode) -> unicode """Convert `width_str` with rst length to LaTeX length.""" - match = re.match('^(\d*\.?\d*)\s*(\S*)$', width_str) + match = re.match(r'^(\d*\.?\d*)\s*(\S*)$', width_str) if not match: raise ValueError res = width_str @@ -2244,7 +2244,7 @@ class LaTeXTranslator(nodes.NodeVisitor): def visit_line(self, node): # type: (nodes.Node) -> None - self.body.append('\item[] ') + self.body.append(r'\item[] ') def depart_line(self, node): # type: (nodes.Node) -> None diff --git a/sphinx/writers/manpage.py b/sphinx/writers/manpage.py index c0ba28bbf..b7ed95f48 100644 --- a/sphinx/writers/manpage.py +++ b/sphinx/writers/manpage.py @@ -129,7 +129,7 @@ class ManualPageTranslator(BaseTranslator): tmpl = (".TH \"%(title_upper)s\" \"%(manual_section)s\"" " \"%(date)s\" \"%(version)s\" \"%(manual_group)s\"\n" ".SH NAME\n" - "%(title)s \- %(subtitle)s\n") + "%(title)s \\- %(subtitle)s\n") return tmpl % self._docinfo def visit_start_of_file(self, node): diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py index a6908d113..c3cacd3e2 100644 --- a/sphinx/writers/texinfo.py +++ b/sphinx/writers/texinfo.py @@ -469,7 +469,7 @@ class TexinfoTranslator(nodes.NodeVisitor): def tex_image_length(self, width_str): # type: (unicode) -> unicode - match = re.match('(\d*\.?\d*)\s*(\S*)', width_str) + match = re.match(r'(\d*\.?\d*)\s*(\S*)', width_str) if not match: # fallback return width_str diff --git a/tests/etree13/ElementPath.py b/tests/etree13/ElementPath.py index d26a0d7a0..8cf1ab578 100644 --- a/tests/etree13/ElementPath.py +++ b/tests/etree13/ElementPath.py @@ -52,15 +52,15 @@ import re xpath_tokenizer = re.compile( - "(" - "'[^']*'|\"[^\"]*\"|" - "::|" - "//?|" - "\.\.|" - "\(\)|" - "[/.*:\[\]\(\)@=])|" - "((?:\{[^}]+\})?[^/:\[\]\(\)@=\s]+)|" - "\s+" + r"(" + r"'[^']*'|\"[^\"]*\"|" + r"::|" + r"//?|" + r"\.\.|" + r"\(\)|" + r"[/.*:\[\]\(\)@=])|" + r"((?:\{[^}]+\})?[^/:\[\]\(\)@=\s]+)|" + r"\s+" ).findall def prepare_tag(next, token): diff --git a/tests/etree13/ElementTree.py b/tests/etree13/ElementTree.py index 0dd12ddb6..134abf313 100644 --- a/tests/etree13/ElementTree.py +++ b/tests/etree13/ElementTree.py @@ -976,7 +976,7 @@ def _serialize_text(write, elem, encoding): # invalid. def register_namespace(prefix, uri): - if re.match("ns\d+$", prefix): + if re.match(r"ns\d+$", prefix): raise ValueError("Prefix format reserved for internal use") for k, v in _namespace_map.items(): if k == uri or v == prefix: diff --git a/tests/run.py b/tests/run.py index 8c6298ad9..71ddcc363 100755 --- a/tests/run.py +++ b/tests/run.py @@ -24,6 +24,7 @@ sys.path.insert(0, os.path.abspath(os.path.join(testroot, os.path.pardir))) # filter warnings of test dependencies warnings.filterwarnings('ignore', category=DeprecationWarning, module='site') # virtualenv warnings.filterwarnings('ignore', category=ImportWarning, module='backports') +warnings.filterwarnings('ignore', category=ImportWarning, module='pytest_cov') warnings.filterwarnings('ignore', category=PendingDeprecationWarning, module=r'_pytest\..*') # check dependencies before testing diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 2750ae29a..068390471 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -346,7 +346,7 @@ def test_static_output(app): (".//a[@class='reference internal'][@href='#cmdoption-perl-arg-p']/code/span", 'perl'), (".//a[@class='reference internal'][@href='#cmdoption-perl-arg-p']/code/span", - '\+p'), + '\\+p'), (".//a[@class='reference internal'][@href='#cmdoption-perl-objc']/code/span", '--ObjC\\+\\+'), (".//a[@class='reference internal'][@href='#cmdoption-perl-plugin-option']/code/span", diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 9a91bf0b5..cd040eb1b 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -482,9 +482,9 @@ def test_footnote(app, status, warning): assert '\\caption{Table caption \\sphinxfootnotemark[4]' in result assert 'name \\sphinxfootnotemark[5]' in result assert ('\\end{threeparttable}\n\\par\n\\endgroup\n%\n' - '\\begin{footnotetext}[4]\sphinxAtStartFootnote\n' + '\\begin{footnotetext}[4]\\sphinxAtStartFootnote\n' 'footnotes in table caption\n%\n\\end{footnotetext}%\n' - '\\begin{footnotetext}[5]\sphinxAtStartFootnote\n' + '\\begin{footnotetext}[5]\\sphinxAtStartFootnote\n' 'footnotes in table\n%\n\\end{footnotetext}') in result @@ -507,18 +507,18 @@ def test_reference_in_caption_and_codeblock_in_footnote(app, status, warning): '%\n\\begin{footnotetext}[4]\\sphinxAtStartFootnote\n' 'Footnote in section\n%\n\\end{footnotetext}') in result assert ('\\caption{This is the figure caption with a footnote to ' - '\\sphinxfootnotemark[6].}\label{\\detokenize{index:id27}}\end{figure}\n' + '\\sphinxfootnotemark[6].}\\label{\\detokenize{index:id27}}\\end{figure}\n' '%\n\\begin{footnotetext}[6]\\sphinxAtStartFootnote\n' 'Footnote in caption\n%\n\\end{footnotetext}')in result assert ('\\caption{footnote \\sphinxfootnotemark[7] ' 'in caption of normal table}\\label{\\detokenize{index:id28}}') in result assert ('\\caption{footnote \\sphinxfootnotemark[8] ' - 'in caption \sphinxfootnotemark[9] of longtable}') in result - assert ('\end{longtable}\n%\n\\begin{footnotetext}[8]' - '\sphinxAtStartFootnote\n' + 'in caption \\sphinxfootnotemark[9] of longtable}') in result + assert ('\\end{longtable}\n%\n\\begin{footnotetext}[8]' + '\\sphinxAtStartFootnote\n' 'Foot note in longtable\n%\n\\end{footnotetext}' in result) assert ('This is a reference to the code-block in the footnote:\n' - '{\hyperref[\\detokenize{index:codeblockinfootnote}]' + '{\\hyperref[\\detokenize{index:codeblockinfootnote}]' '{\\sphinxcrossref{\\DUrole{std,std-ref}{I am in a footnote}}}}') in result assert ('&\nThis is one more footnote with some code in it ' '\\sphinxfootnotemark[10].\n\\\\') in result @@ -855,7 +855,7 @@ def test_latex_table_tabulars(app, status, warning): # table having :align: option (tabular) table = tables['table having :align: option (tabular)'] assert ('\\begingroup\n\\raggedright\n' - '\\begin{tabular}{|\X{30}{100}|\X{70}{100}|}\n' in table) + '\\begin{tabular}{|\\X{30}{100}|\\X{70}{100}|}\n' in table) assert ('\\hline\n\\end{tabular}\n\\par\n\\endgroup' in table) # table with tabularcolumn diff --git a/tests/test_directive_code.py b/tests/test_directive_code.py index 4ebe937d8..5c1bacfa8 100644 --- a/tests/test_directive_code.py +++ b/tests/test_directive_code.py @@ -67,7 +67,7 @@ def test_code_block_caption_latex(app, status, warning): latex = (app.outdir / 'Python.tex').text(encoding='utf-8') caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstyleemphasis{test} rb}' label = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:id1}}}' - link = '\hyperref[\\detokenize{caption:name-test-rb}]' \ + link = '\\hyperref[\\detokenize{caption:name-test-rb}]' \ '{Listing \\ref{\\detokenize{caption:name-test-rb}}}' assert caption in latex assert label in latex @@ -263,7 +263,7 @@ def test_literalinclude_caption_latex(app, status, warning): latex = (app.outdir / 'Python.tex').text(encoding='utf-8') caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstylestrong{test} py}' label = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:id2}}}' - link = '\hyperref[\\detokenize{caption:name-test-py}]' \ + link = '\\hyperref[\\detokenize{caption:name-test-py}]' \ '{Listing \\ref{\\detokenize{caption:name-test-py}}}' assert caption in latex assert label in latex diff --git a/tests/test_domain_cpp.py b/tests/test_domain_cpp.py index 00ffd484e..4ff8a11f0 100644 --- a/tests/test_domain_cpp.py +++ b/tests/test_domain_cpp.py @@ -520,12 +520,12 @@ def test_build_domain_cpp_with_add_function_parentheses_is_True(app, status, war ('', 'MyEnum') ] parenPatterns = [ - ('ref function without parens ', 'paren_1\(\)'), - ('ref function with parens ', 'paren_2\(\)'), + ('ref function without parens ', r'paren_1\(\)'), + ('ref function with parens ', r'paren_2\(\)'), ('ref function without parens, explicit title ', 'paren_3_title'), ('ref function with parens, explicit title ', 'paren_4_title'), - ('ref op call without parens ', 'paren_5::operator\(\)\(\)'), - ('ref op call with parens ', 'paren_6::operator\(\)\(\)'), + ('ref op call without parens ', r'paren_5::operator\(\)\(\)'), + ('ref op call with parens ', r'paren_6::operator\(\)\(\)'), ('ref op call without parens, explicit title ', 'paren_7_title'), ('ref op call with parens, explicit title ', 'paren_8_title') ] @@ -566,8 +566,8 @@ def test_build_domain_cpp_with_add_function_parentheses_is_False(app, status, wa ('ref function with parens ', 'paren_2'), ('ref function without parens, explicit title ', 'paren_3_title'), ('ref function with parens, explicit title ', 'paren_4_title'), - ('ref op call without parens ', 'paren_5::operator\(\)'), - ('ref op call with parens ', 'paren_6::operator\(\)'), + ('ref op call without parens ', r'paren_5::operator\(\)'), + ('ref op call with parens ', r'paren_6::operator\(\)'), ('ref op call without parens, explicit title ', 'paren_7_title'), ('ref op call with parens, explicit title ', 'paren_8_title') ] diff --git a/tests/test_ext_graphviz.py b/tests/test_ext_graphviz.py index 45850f3ce..1c31e8eaf 100644 --- a/tests/test_ext_graphviz.py +++ b/tests/test_ext_graphviz.py @@ -20,8 +20,8 @@ def test_graphviz_html(app, status, warning): app.builder.build_all() content = (app.outdir / 'index.html').text() - html = ('
' - 'caption of graph.*
\s*' + r'caption of graph.*
\s*' - 'on right.*
\s*' + r'on right.*
\s*' 'Test Foo!\xb6
') diff --git a/tests/test_ext_math.py b/tests/test_ext_math.py index 3a2c4df45..3cbb534e9 100644 --- a/tests/test_ext_math.py +++ b/tests/test_ext_math.py @@ -45,8 +45,8 @@ def test_imgmath_png(app, status, warning): raise SkipTest('dvipng command "dvipng" is not available') content = (app.outdir / 'index.html').text() - html = ('\s*\s*
\s*\s*
\s*\s*
\s*\s*