mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Shrink mypy exclude list (#12669)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
This commit is contained in:
parent
68eaf08fc1
commit
f09bc62969
@ -136,26 +136,19 @@ exclude = [
|
|||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
files = ["sphinx", "utils", "tests"]
|
files = ["sphinx", "utils", "tests"]
|
||||||
exclude = [
|
exclude = [
|
||||||
"tests/certs",
|
|
||||||
"tests/js",
|
|
||||||
"tests/roots",
|
"tests/roots",
|
||||||
# tests/
|
# tests/
|
||||||
"^tests/test_events\\.py$",
|
"^tests/test_events\\.py$",
|
||||||
"^tests/test_quickstart\\.py$",
|
"^tests/test_quickstart\\.py$",
|
||||||
"^tests/test_search\\.py$",
|
"^tests/test_search\\.py$",
|
||||||
"^tests/test_versioning\\.py$",
|
|
||||||
# tests/test_builders
|
# tests/test_builders
|
||||||
"^tests/test_builders/test_build_dirhtml\\.py$",
|
|
||||||
"^tests/test_builders/test_build_epub\\.py$",
|
"^tests/test_builders/test_build_epub\\.py$",
|
||||||
"^tests/test_builders/test_builder\\.py$",
|
|
||||||
"^tests/test_builders/test_build_gettext\\.py$",
|
"^tests/test_builders/test_build_gettext\\.py$",
|
||||||
"^tests/test_builders/test_build_html\\.py$",
|
|
||||||
"^tests/test_builders/test_build_latex\\.py$",
|
"^tests/test_builders/test_build_latex\\.py$",
|
||||||
"^tests/test_builders/test_build_texinfo\\.py$",
|
"^tests/test_builders/test_build_texinfo\\.py$",
|
||||||
# tests/test_config
|
# tests/test_config
|
||||||
"^tests/test_config/test_config\\.py$",
|
"^tests/test_config/test_config\\.py$",
|
||||||
# tests/test_directives
|
# tests/test_directives
|
||||||
"^tests/test_directives/test_directive_object_description\\.py$",
|
|
||||||
"^tests/test_directives/test_directive_only\\.py$",
|
"^tests/test_directives/test_directive_only\\.py$",
|
||||||
"^tests/test_directives/test_directive_other\\.py$",
|
"^tests/test_directives/test_directive_other\\.py$",
|
||||||
"^tests/test_directives/test_directive_patch\\.py$",
|
"^tests/test_directives/test_directive_patch\\.py$",
|
||||||
@ -185,14 +178,10 @@ exclude = [
|
|||||||
"^tests/test_extensions/test_ext_napoleon_docstring\\.py$",
|
"^tests/test_extensions/test_ext_napoleon_docstring\\.py$",
|
||||||
# tests/test_intl
|
# tests/test_intl
|
||||||
"^tests/test_intl/test_intl\\.py$",
|
"^tests/test_intl/test_intl\\.py$",
|
||||||
# tests/test_markup
|
|
||||||
"^tests/test_markup/test_markup\\.py$",
|
|
||||||
# tests/test_pycode
|
# tests/test_pycode
|
||||||
"^tests/test_pycode/test_pycode\\.py$",
|
"^tests/test_pycode/test_pycode\\.py$",
|
||||||
"^tests/test_pycode/test_pycode_ast\\.py$",
|
"^tests/test_pycode/test_pycode_ast\\.py$",
|
||||||
# tests/test_theming
|
|
||||||
# tests/test_transforms
|
# tests/test_transforms
|
||||||
"^tests/test_transforms/test_transforms_move_module_targets\\.py$",
|
|
||||||
"^tests/test_transforms/test_transforms_post_transforms\\.py$",
|
"^tests/test_transforms/test_transforms_post_transforms\\.py$",
|
||||||
# tests/test_util
|
# tests/test_util
|
||||||
"^tests/test_util/test_util_fileutil\\.py$",
|
"^tests/test_util/test_util_fileutil\\.py$",
|
||||||
|
@ -27,14 +27,14 @@ def test_dirhtml(app):
|
|||||||
with (app.outdir / 'objects.inv').open('rb') as f:
|
with (app.outdir / 'objects.inv').open('rb') as f:
|
||||||
invdata = InventoryFile.load(f, 'path/to', posixpath.join)
|
invdata = InventoryFile.load(f, 'path/to', posixpath.join)
|
||||||
|
|
||||||
assert 'index' in invdata.get('std:doc')
|
assert 'index' in invdata.get('std:doc', {})
|
||||||
assert invdata['std:doc']['index'] == ('Project name not set', '', 'path/to/', '-')
|
assert invdata['std:doc']['index'] == ('Project name not set', '', 'path/to/', '-')
|
||||||
|
|
||||||
assert 'foo/index' in invdata.get('std:doc')
|
assert 'foo/index' in invdata.get('std:doc', {})
|
||||||
assert invdata['std:doc']['foo/index'] == ('Project name not set', '', 'path/to/foo/', '-')
|
assert invdata['std:doc']['foo/index'] == ('Project name not set', '', 'path/to/foo/', '-')
|
||||||
|
|
||||||
assert 'index' in invdata.get('std:label')
|
assert 'index' in invdata.get('std:label', {})
|
||||||
assert invdata['std:label']['index'] == ('Project name not set', '', 'path/to/#index', '-')
|
assert invdata['std:label']['index'] == ('Project name not set', '', 'path/to/#index', '-')
|
||||||
|
|
||||||
assert 'foo' in invdata.get('std:label')
|
assert 'foo' in invdata.get('std:label', {})
|
||||||
assert invdata['std:label']['foo'] == ('Project name not set', '', 'path/to/foo/#foo', 'foo/index')
|
assert invdata['std:label']['foo'] == ('Project name not set', '', 'path/to/foo/#foo', 'foo/index')
|
||||||
|
@ -174,7 +174,7 @@ def test_nested_toc(app):
|
|||||||
assert toc.find("./ncx:docTitle/ncx:text").text == 'Project name not set'
|
assert toc.find("./ncx:docTitle/ncx:text").text == 'Project name not set'
|
||||||
|
|
||||||
# toc.ncx / navPoint
|
# toc.ncx / navPoint
|
||||||
def navinfo(elem):
|
def navinfo(elem: EPUBElementTree):
|
||||||
label = elem.find("./ncx:navLabel/ncx:text")
|
label = elem.find("./ncx:navLabel/ncx:text")
|
||||||
content = elem.find("./ncx:content")
|
content = elem.find("./ncx:content")
|
||||||
return (elem.get('id'), elem.get('playOrder'),
|
return (elem.get('id'), elem.get('playOrder'),
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
"""Test the HTML builder and check output against XPath."""
|
"""Test the HTML builder and check output against XPath."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import posixpath
|
import posixpath
|
||||||
import re
|
import re
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -14,6 +17,9 @@ from sphinx.util.inventory import InventoryFile
|
|||||||
from tests.test_builders.xpath_data import FIGURE_CAPTION
|
from tests.test_builders.xpath_data import FIGURE_CAPTION
|
||||||
from tests.test_builders.xpath_util import check_xpath
|
from tests.test_builders.xpath_util import check_xpath
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
def test_html_sidebars_error(make_app, tmp_path):
|
def test_html_sidebars_error(make_app, tmp_path):
|
||||||
(tmp_path / 'conf.py').touch()
|
(tmp_path / 'conf.py').touch()
|
||||||
@ -230,7 +236,7 @@ def test_html_style(app):
|
|||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='basic')
|
@pytest.mark.sphinx('html', testroot='basic')
|
||||||
def test_html_sidebar(app):
|
def test_html_sidebar(app):
|
||||||
ctx = {}
|
ctx: dict[str, Any] = {}
|
||||||
|
|
||||||
# default for alabaster
|
# default for alabaster
|
||||||
app.build(force_all=True)
|
app.build(force_all=True)
|
||||||
@ -398,7 +404,7 @@ def test_html_pep_695_one_type_per_line(app, cached_etree_parse):
|
|||||||
etree = cached_etree_parse(fname)
|
etree = cached_etree_parse(fname)
|
||||||
|
|
||||||
class chk:
|
class chk:
|
||||||
def __init__(self, expect):
|
def __init__(self, expect: str) -> None:
|
||||||
self.expect = expect
|
self.expect = expect
|
||||||
|
|
||||||
def __call__(self, nodes):
|
def __call__(self, nodes):
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
"""Test object description directives."""
|
"""Test object description directives."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import docutils.utils
|
import docutils.utils
|
||||||
import pytest
|
import pytest
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
@ -9,8 +13,11 @@ from sphinx.io import create_publisher
|
|||||||
from sphinx.testing import restructuredtext
|
from sphinx.testing import restructuredtext
|
||||||
from sphinx.util.docutils import sphinx_domains
|
from sphinx.util.docutils import sphinx_domains
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from sphinx.builders import Builder
|
||||||
|
|
||||||
def _doctree_for_test(builder, docname: str) -> nodes.document:
|
|
||||||
|
def _doctree_for_test(builder: Builder, docname: str) -> nodes.document:
|
||||||
builder.env.prepare_settings(docname)
|
builder.env.prepare_settings(docname)
|
||||||
publisher = create_publisher(builder.app, 'restructuredtext')
|
publisher = create_publisher(builder.app, 'restructuredtext')
|
||||||
with sphinx_domains(builder.env):
|
with sphinx_domains(builder.env):
|
||||||
|
@ -17,7 +17,8 @@ from sphinx.testing.util import assert_node
|
|||||||
from sphinx.transforms import SphinxSmartQuotes
|
from sphinx.transforms import SphinxSmartQuotes
|
||||||
from sphinx.util import texescape
|
from sphinx.util import texescape
|
||||||
from sphinx.util.docutils import sphinx_domains
|
from sphinx.util.docutils import sphinx_domains
|
||||||
from sphinx.writers.html import HTML5Translator, HTMLWriter
|
from sphinx.writers.html import HTMLWriter
|
||||||
|
from sphinx.writers.html5 import HTML5Translator
|
||||||
from sphinx.writers.latex import LaTeXTranslator, LaTeXWriter
|
from sphinx.writers.latex import LaTeXTranslator, LaTeXWriter
|
||||||
|
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ def parse(new_document):
|
|||||||
document = new_document()
|
document = new_document()
|
||||||
parser = RstParser()
|
parser = RstParser()
|
||||||
parser.parse(rst, document)
|
parser.parse(rst, document)
|
||||||
SphinxSmartQuotes(document, startnode=None).apply()
|
SphinxSmartQuotes(document, startnode=None).apply() # type: ignore[no-untyped-call]
|
||||||
for msg in list(document.findall(nodes.system_message)):
|
for msg in list(document.findall(nodes.system_message)):
|
||||||
if msg['level'] == 1:
|
if msg['level'] == 1:
|
||||||
msg.replace_self([])
|
msg.replace_self([])
|
||||||
|
@ -32,7 +32,7 @@ def test_move_module_targets(tmp_path, content):
|
|||||||
app = SphinxTestApp('dummy', srcdir=tmp_path)
|
app = SphinxTestApp('dummy', srcdir=tmp_path)
|
||||||
app.build(force_all=True)
|
app.build(force_all=True)
|
||||||
document = app.env.get_doctree('index')
|
document = app.env.get_doctree('index')
|
||||||
section = document[0]
|
section: nodes.section = document[0] # type: ignore[assignment]
|
||||||
|
|
||||||
# target ID has been lifted into the section node
|
# target ID has been lifted into the section node
|
||||||
assert section["ids"] == ['module-fish_licence.halibut', 'move-module-targets']
|
assert section["ids"] == ['module-fish_licence.halibut', 'move-module-targets']
|
||||||
@ -65,11 +65,11 @@ def test_move_module_targets_disabled(tmp_path):
|
|||||||
app.registry.transforms.remove(MoveModuleTargets) # disable the transform
|
app.registry.transforms.remove(MoveModuleTargets) # disable the transform
|
||||||
app.build(force_all=True)
|
app.build(force_all=True)
|
||||||
document = app.env.get_doctree('index')
|
document = app.env.get_doctree('index')
|
||||||
section = document[0]
|
section: nodes.section = document[0] # type: ignore[assignment]
|
||||||
|
|
||||||
# target ID is not lifted into the section node
|
# target ID is not lifted into the section node
|
||||||
assert section["ids"] == ['move-module-targets']
|
assert section["ids"] == ['move-module-targets']
|
||||||
assert section[2]["ids"] == ['module-fish_licence.halibut']
|
assert section[2]["ids"] == ['module-fish_licence.halibut'] # type: ignore[index]
|
||||||
# nodes.target remains in 'section'
|
# nodes.target remains in 'section'
|
||||||
assert isinstance(section[0], nodes.title)
|
assert isinstance(section[0], nodes.title)
|
||||||
assert isinstance(section[1], addnodes.index)
|
assert isinstance(section[1], addnodes.index)
|
||||||
|
@ -22,7 +22,7 @@ def _setup_module(rootdir, sphinx_test_tempdir):
|
|||||||
app.connect('doctree-resolved', on_doctree_resolved)
|
app.connect('doctree-resolved', on_doctree_resolved)
|
||||||
app.build()
|
app.build()
|
||||||
original = doctrees['original']
|
original = doctrees['original']
|
||||||
original_uids = [n.uid for n in add_uids(original, is_paragraph)]
|
original_uids = [n.uid for n in add_uids(original, is_paragraph)] # type: ignore[attr-defined]
|
||||||
yield
|
yield
|
||||||
app.cleanup()
|
app.cleanup()
|
||||||
|
|
||||||
@ -115,6 +115,6 @@ def test_insert_similar():
|
|||||||
new_nodes = list(merge_doctrees(original, insert_similar, is_paragraph))
|
new_nodes = list(merge_doctrees(original, insert_similar, is_paragraph))
|
||||||
uids = [n.uid for n in insert_similar.findall(is_paragraph)]
|
uids = [n.uid for n in insert_similar.findall(is_paragraph)]
|
||||||
assert len(new_nodes) == 1
|
assert len(new_nodes) == 1
|
||||||
assert new_nodes[0].rawsource == 'Anyway I need more'
|
assert new_nodes[0].rawsource == 'Anyway I need more' # type: ignore[attr-defined]
|
||||||
assert original_uids[0] == uids[0]
|
assert original_uids[0] == uids[0]
|
||||||
assert original_uids[1:] == uids[2:]
|
assert original_uids[1:] == uids[2:]
|
||||||
|
Loading…
Reference in New Issue
Block a user