mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix mypy violations
This commit is contained in:
@@ -13,7 +13,7 @@ import re
|
||||
from os import path, getenv
|
||||
|
||||
from six import PY2, PY3, iteritems, string_types, binary_type, text_type, integer_types
|
||||
from typing import Any, NamedTuple
|
||||
from typing import Any, NamedTuple, Union
|
||||
|
||||
from sphinx.errors import ConfigError
|
||||
from sphinx.locale import l_
|
||||
@@ -24,7 +24,7 @@ from sphinx.util.pycompat import execfile_, NoneType
|
||||
|
||||
if False:
|
||||
# For type annotation
|
||||
from typing import Any, Callable, Generator, Iterator, Tuple # NOQA
|
||||
from typing import Any, Callable, Iterable, Iterator, Tuple # NOQA
|
||||
from sphinx.util.tags import Tags # NOQA
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -46,7 +46,7 @@ CONFIG_TYPE_WARNING = "The config value `{name}' has type `{current.__name__}',
|
||||
|
||||
ConfigValue = NamedTuple('ConfigValue', [('name', str),
|
||||
('value', Any),
|
||||
('rebuild', str)])
|
||||
('rebuild', Union[bool, unicode])])
|
||||
|
||||
|
||||
class ENUM(object):
|
||||
@@ -314,12 +314,12 @@ class Config(object):
|
||||
return name in self.values
|
||||
|
||||
def __iter__(self):
|
||||
# type: () -> Iterator[ConfigValue]
|
||||
# type: () -> Iterable[ConfigValue]
|
||||
for name, value in iteritems(self.values):
|
||||
yield ConfigValue(name, getattr(self, name), value[1]) # type: ignore
|
||||
|
||||
def add(self, name, default, rebuild, types):
|
||||
# type: (str, Any, str, Any) -> None
|
||||
# type: (unicode, Any, Union[bool, unicode], Any) -> None
|
||||
self.values[name] = (default, rebuild, types)
|
||||
|
||||
def filter(self, rebuild):
|
||||
|
||||
@@ -916,7 +916,7 @@ class ASTTemplateParams(ASTBase):
|
||||
return ''.join(res)
|
||||
|
||||
def describe_signature(self, parentNode, mode, env, symbol, lineSpec=None):
|
||||
# type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None
|
||||
# type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol, bool) -> None
|
||||
# 'lineSpec' is defaulted becuase of template template parameters
|
||||
def makeLine(parentNode=parentNode):
|
||||
signode = addnodes.desc_signature_line()
|
||||
@@ -1024,7 +1024,7 @@ class ASTTemplateIntroduction(ASTBase):
|
||||
return ''.join(res)
|
||||
|
||||
def describe_signature(self, parentNode, mode, env, symbol, lineSpec):
|
||||
# type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None
|
||||
# type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol, bool) -> None
|
||||
# Note: 'lineSpec' has no effect on template introductions.
|
||||
signode = addnodes.desc_signature_line()
|
||||
parentNode += signode
|
||||
@@ -1065,7 +1065,7 @@ class ASTTemplateDeclarationPrefix(ASTBase):
|
||||
return u''.join(res)
|
||||
|
||||
def describe_signature(self, signode, mode, env, symbol, lineSpec):
|
||||
# type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None
|
||||
# type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol, bool) -> None
|
||||
_verify_description_mode(mode)
|
||||
for t in self.templates:
|
||||
t.describe_signature(signode, 'lastIsName', env, symbol, lineSpec)
|
||||
@@ -2742,7 +2742,7 @@ class ASTDeclaration(ASTBase):
|
||||
return u''.join(res)
|
||||
|
||||
def describe_signature(self, signode, mode, env, options):
|
||||
# type: (addnodes.desc_signature, unicode, BuildEnvironment) -> None
|
||||
# type: (addnodes.desc_signature, unicode, BuildEnvironment, Dict) -> None
|
||||
_verify_description_mode(mode)
|
||||
# The caller of the domain added a desc_signature node.
|
||||
# Always enable multiline:
|
||||
@@ -4545,7 +4545,7 @@ class CPPObject(ObjectDescription):
|
||||
raise NotImplementedError()
|
||||
|
||||
def describe_signature(self, signode, ast, options): # type: ignore
|
||||
# type: (addnodes.desc_signature, Any) -> None
|
||||
# type: (addnodes.desc_signature, Any, Dict) -> None
|
||||
ast.describe_signature(signode, 'lastIsName', self.env, options)
|
||||
|
||||
def handle_signature(self, sig, signode):
|
||||
|
||||
@@ -57,7 +57,7 @@ class IfConfig(Directive):
|
||||
|
||||
def process_ifconfig_nodes(app, doctree, docname):
|
||||
# type: (Sphinx, nodes.Node, unicode) -> None
|
||||
ns = dict((confval.name, confval.value) for confval in app.config)
|
||||
ns = dict((confval.name, confval.value) for confval in app.config) # type: ignore
|
||||
ns.update(app.config.__dict__.copy())
|
||||
ns['builder'] = app.builder.name
|
||||
for node in doctree.traverse(ifconfig):
|
||||
|
||||
@@ -45,7 +45,7 @@ from sphinx.util.matching import patfilter # noqa
|
||||
|
||||
if False:
|
||||
# For type annotation
|
||||
from typing import Any, Callable, Iterable, Iterator, Pattern, Sequence, Tuple # NOQA
|
||||
from typing import Any, Callable, Iterable, Iterator, Pattern, Sequence, Tuple, Union # NOQA
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -565,7 +565,7 @@ def old_status_iterator(iterable, summary, color="darkgreen", stringify_func=dis
|
||||
# new version with progress info
|
||||
def status_iterator(iterable, summary, color="darkgreen", length=0, verbosity=0,
|
||||
stringify_func=display_chunk):
|
||||
# type: (Iterable, unicode, str, int, int, Callable[[Any], unicode]) -> Iterable
|
||||
# type: (Iterable, unicode, str, int, int, Callable[[Any], unicode]) -> Iterable # NOQA
|
||||
if length == 0:
|
||||
for item in old_status_iterator(iterable, summary, color, stringify_func):
|
||||
yield item
|
||||
|
||||
@@ -1575,8 +1575,9 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
def visit_image(self, node):
|
||||
# type: (nodes.Node) -> None
|
||||
attrs = node.attributes
|
||||
pre = [] # in reverse order
|
||||
post = []
|
||||
pre = [] # type: List[unicode]
|
||||
# in reverse order
|
||||
post = [] # type: List[unicode]
|
||||
if self.in_parsed_literal:
|
||||
pre = ['\\begingroup\\sphinxunactivateextrasandspace\\relax ']
|
||||
post = ['\\endgroup ']
|
||||
|
||||
Reference in New Issue
Block a user