Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/sphinx
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx')
-rw-r--r--sphinx/application.py2
-rw-r--r--sphinx/config.py2
-rw-r--r--sphinx/domains/c.py4
-rw-r--r--sphinx/domains/cpp.py144
-rw-r--r--sphinx/domains/std.py2
-rw-r--r--sphinx/ext/autosummary/generate.py4
-rw-r--r--sphinx/jinja2glue.py2
-rw-r--r--sphinx/search/__init__.py10
-rw-r--r--sphinx/util/console.py3
-rw-r--r--sphinx/util/images.py2
-rw-r--r--sphinx/util/nodes.py3
-rw-r--r--sphinx/util/pycompat.py2
-rw-r--r--sphinx/util/template.py2
-rw-r--r--sphinx/util/typing.py8
14 files changed, 150 insertions, 40 deletions
diff --git a/sphinx/application.py b/sphinx/application.py
index bd23c86e7..d84a2c975 100644
--- a/sphinx/application.py
+++ b/sphinx/application.py
@@ -165,7 +165,7 @@ class Sphinx:
if path.exists(self.outdir) and not path.isdir(self.outdir):
raise ApplicationError(__('Output directory (%s) is not a directory') %
- self.srcdir)
+ self.outdir)
if self.srcdir == self.outdir:
raise ApplicationError(__('Source directory and destination '
diff --git a/sphinx/config.py b/sphinx/config.py
index 6e6c256c5..92c203dfd 100644
--- a/sphinx/config.py
+++ b/sphinx/config.py
@@ -131,7 +131,7 @@ class Config:
'rst_epilog': (None, 'env', [str]),
'rst_prolog': (None, 'env', [str]),
'trim_doctest_flags': (True, 'env', []),
- 'primary_domain': ('py', 'env', [NoneType]), # type: ignore
+ 'primary_domain': ('py', 'env', [NoneType]),
'needs_sphinx': (None, None, [str]),
'needs_extensions': ({}, None, []),
'manpages_url': (None, 'env', []),
diff --git a/sphinx/domains/c.py b/sphinx/domains/c.py
index 164a87254..36a8f1f65 100644
--- a/sphinx/domains/c.py
+++ b/sphinx/domains/c.py
@@ -432,9 +432,9 @@ class ASTUnaryOpExpr(ASTExpression):
def _stringify(self, transform: StringifyTransform) -> str:
if self.op[0] in 'cn':
- return transform(self.op) + " " + transform(self.expr)
+ return self.op + " " + transform(self.expr)
else:
- return transform(self.op) + transform(self.expr)
+ return self.op + transform(self.expr)
def describe_signature(self, signode: TextElement, mode: str,
env: "BuildEnvironment", symbol: "Symbol") -> None:
diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py
index b801f4030..1783db491 100644
--- a/sphinx/domains/cpp.py
+++ b/sphinx/domains/cpp.py
@@ -951,12 +951,12 @@ class ASTFoldExpr(ASTExpression):
if self.leftExpr:
res.append(transform(self.leftExpr))
res.append(' ')
- res.append(transform(self.op))
+ res.append(self.op)
res.append(' ')
res.append('...')
if self.rightExpr:
res.append(' ')
- res.append(transform(self.op))
+ res.append(self.op)
res.append(' ')
res.append(transform(self.rightExpr))
res.append(')')
@@ -1223,9 +1223,9 @@ class ASTUnaryOpExpr(ASTExpression):
def _stringify(self, transform: StringifyTransform) -> str:
if self.op[0] in 'cn':
- return transform(self.op) + " " + transform(self.expr)
+ return self.op + " " + transform(self.expr)
else:
- return transform(self.op) + transform(self.expr)
+ return self.op + transform(self.expr)
def get_id(self, version: int) -> str:
return _id_operator_unary_v2[self.op] + self.expr.get_id(version)
@@ -3538,6 +3538,8 @@ class ASTTemplateIntroduction(ASTBase):
signode += nodes.Text('}')
+################################################################################
+
class ASTTemplateDeclarationPrefix(ASTBase):
def __init__(self,
templates: List[Union[ASTTemplateParams,
@@ -3566,18 +3568,35 @@ class ASTTemplateDeclarationPrefix(ASTBase):
t.describe_signature_as_introducer(signode, 'lastIsName', env, symbol, lineSpec)
+class ASTRequiresClause(ASTBase):
+ def __init__(self, expr: ASTExpression) -> None:
+ self.expr = expr
+
+ def _stringify(self, transform: StringifyTransform) -> str:
+ return 'requires ' + transform(self.expr)
+
+ def describe_signature(self, signode: addnodes.desc_signature_line, mode: str,
+ env: "BuildEnvironment", symbol: "Symbol") -> None:
+ signode += nodes.Text('requires ', 'requires ')
+ self.expr.describe_signature(signode, mode, env, symbol)
+
+
################################################################################
################################################################################
class ASTDeclaration(ASTBase):
def __init__(self, objectType: str, directiveType: str, visibility: str,
- templatePrefix: ASTTemplateDeclarationPrefix, declaration: Any,
+ templatePrefix: ASTTemplateDeclarationPrefix,
+ requiresClause: ASTRequiresClause, declaration: Any,
+ trailingRequiresClause: ASTRequiresClause,
semicolon: bool = False) -> None:
self.objectType = objectType
self.directiveType = directiveType
self.visibility = visibility
self.templatePrefix = templatePrefix
+ self.requiresClause = requiresClause
self.declaration = declaration
+ self.trailingRequiresClause = trailingRequiresClause
self.semicolon = semicolon
self.symbol = None # type: Symbol
@@ -3585,13 +3604,14 @@ class ASTDeclaration(ASTBase):
self.enumeratorScopedSymbol = None # type: Symbol
def clone(self) -> "ASTDeclaration":
- if self.templatePrefix:
- templatePrefixClone = self.templatePrefix.clone()
- else:
- templatePrefixClone = None
- return ASTDeclaration(self.objectType, self.directiveType,
- self.visibility, templatePrefixClone,
- self.declaration.clone(), self.semicolon)
+ templatePrefixClone = self.templatePrefix.clone() if self.templatePrefix else None
+ requiresClasueClone = self.requiresClause.clone() if self.requiresClause else None
+ trailingRequiresClasueClone = self.trailingRequiresClause.clone() \
+ if self.trailingRequiresClause else None
+ return ASTDeclaration(self.objectType, self.directiveType, self.visibility,
+ templatePrefixClone, requiresClasueClone,
+ self.declaration.clone(), trailingRequiresClasueClone,
+ self.semicolon)
@property
def name(self) -> ASTNestedName:
@@ -3619,6 +3639,17 @@ class ASTDeclaration(ASTBase):
res = []
if self.templatePrefix:
res.append(self.templatePrefix.get_id(version))
+ if self.requiresClause or self.trailingRequiresClause:
+ if version < 4:
+ raise NoOldIdError()
+ res.append('IQ')
+ if self.requiresClause and self.trailingRequiresClause:
+ res.append('aa')
+ if self.requiresClause:
+ res.append(self.requiresClause.expr.get_id(version))
+ if self.trailingRequiresClause:
+ res.append(self.trailingRequiresClause.expr.get_id(version))
+ res.append('E')
res.append(self.declaration.get_id(version, self.objectType, self.symbol))
return ''.join(res)
@@ -3632,7 +3663,13 @@ class ASTDeclaration(ASTBase):
res.append(' ')
if self.templatePrefix:
res.append(transform(self.templatePrefix))
+ if self.requiresClause:
+ res.append(transform(self.requiresClause))
+ res.append(' ')
res.append(transform(self.declaration))
+ if self.trailingRequiresClause:
+ res.append(' ')
+ res.append(transform(self.trailingRequiresClause))
if self.semicolon:
res.append(';')
return ''.join(res)
@@ -3653,6 +3690,11 @@ class ASTDeclaration(ASTBase):
self.templatePrefix.describe_signature(signode, mode, env,
symbol=self.symbol,
lineSpec=options.get('tparam-line-spec'))
+ if self.requiresClause:
+ reqNode = addnodes.desc_signature_line()
+ reqNode.sphinx_line_type = 'requiresClause'
+ signode.append(reqNode)
+ self.requiresClause.describe_signature(reqNode, 'markType', env, self.symbol)
signode += mainDeclNode
if self.visibility and self.visibility != "public":
mainDeclNode += addnodes.desc_annotation(self.visibility + " ",
@@ -3688,8 +3730,16 @@ class ASTDeclaration(ASTBase):
else:
assert False
self.declaration.describe_signature(mainDeclNode, mode, env, self.symbol)
+ lastDeclNode = mainDeclNode
+ if self.trailingRequiresClause:
+ trailingReqNode = addnodes.desc_signature_line()
+ trailingReqNode.sphinx_line_type = 'trailingRequiresClause'
+ signode.append(trailingReqNode)
+ lastDeclNode = trailingReqNode
+ self.trailingRequiresClause.describe_signature(
+ trailingReqNode, 'markType', env, self.symbol)
if self.semicolon:
- mainDeclNode += nodes.Text(';')
+ lastDeclNode += nodes.Text(';')
class ASTNamespace(ASTBase):
@@ -3808,7 +3858,7 @@ class Symbol:
continue
# only add a declaration if we our self are from a declaration
if self.declaration:
- decl = ASTDeclaration('templateParam', None, None, None, tp)
+ decl = ASTDeclaration('templateParam', None, None, None, None, tp, None)
else:
decl = None
nne = ASTNestedNameElement(tp.get_identifier(), None)
@@ -3823,7 +3873,7 @@ class Symbol:
if nn is None:
continue
# (comparing to the template params: we have checked that we are a declaration)
- decl = ASTDeclaration('functionParam', None, None, None, fp)
+ decl = ASTDeclaration('functionParam', None, None, None, None, fp, None)
assert not nn.rooted
assert len(nn.names) == 1
self._add_symbols(nn, [], decl, self.docname)
@@ -6297,8 +6347,61 @@ class DefinitionParser(BaseParser):
'Expected ",", or "}".')
return ASTTemplateIntroduction(concept, params)
+ def _parse_requires_clause(self) -> Optional[ASTRequiresClause]:
+ # requires-clause -> 'requires' constraint-logical-or-expression
+ # constraint-logical-or-expression
+ # -> constraint-logical-and-expression
+ # | constraint-logical-or-expression '||' constraint-logical-and-expression
+ # constraint-logical-and-expression
+ # -> primary-expression
+ # | constraint-logical-and-expression '&&' primary-expression
+ self.skip_ws()
+ if not self.skip_word('requires'):
+ return None
+
+ def parse_and_expr(self: DefinitionParser) -> ASTExpression:
+ andExprs = []
+ ops = []
+ andExprs.append(self._parse_primary_expression())
+ while True:
+ self.skip_ws()
+ oneMore = False
+ if self.skip_string('&&'):
+ oneMore = True
+ ops.append('&&')
+ elif self.skip_word('and'):
+ oneMore = True
+ ops.append('and')
+ if not oneMore:
+ break
+ andExprs.append(self._parse_primary_expression())
+ if len(andExprs) == 1:
+ return andExprs[0]
+ else:
+ return ASTBinOpExpr(andExprs, ops)
+
+ orExprs = []
+ ops = []
+ orExprs.append(parse_and_expr(self))
+ while True:
+ self.skip_ws()
+ oneMore = False
+ if self.skip_string('||'):
+ oneMore = True
+ ops.append('||')
+ elif self.skip_word('or'):
+ oneMore = True
+ ops.append('or')
+ if not oneMore:
+ break
+ orExprs.append(parse_and_expr(self))
+ if len(orExprs) == 1:
+ return ASTRequiresClause(orExprs[0])
+ else:
+ return ASTRequiresClause(ASTBinOpExpr(orExprs, ops))
+
def _parse_template_declaration_prefix(self, objectType: str
- ) -> ASTTemplateDeclarationPrefix:
+ ) -> Optional[ASTTemplateDeclarationPrefix]:
templates = [] # type: List[Union[ASTTemplateParams, ASTTemplateIntroduction]]
while 1:
self.skip_ws()
@@ -6377,6 +6480,8 @@ class DefinitionParser(BaseParser):
raise Exception('Internal error, unknown directiveType "%s".' % directiveType)
visibility = None
templatePrefix = None
+ requiresClause = None
+ trailingRequiresClause = None
declaration = None # type: Any
self.skip_ws()
@@ -6385,6 +6490,8 @@ class DefinitionParser(BaseParser):
if objectType in ('type', 'concept', 'member', 'function', 'class'):
templatePrefix = self._parse_template_declaration_prefix(objectType)
+ if objectType == 'function' and templatePrefix is not None:
+ requiresClause = self._parse_requires_clause()
if objectType == 'type':
prevErrors = []
@@ -6410,6 +6517,8 @@ class DefinitionParser(BaseParser):
declaration = self._parse_type_with_init(named=True, outer='member')
elif objectType == 'function':
declaration = self._parse_type(named=True, outer='function')
+ if templatePrefix is not None:
+ trailingRequiresClause = self._parse_requires_clause()
elif objectType == 'class':
declaration = self._parse_class()
elif objectType == 'union':
@@ -6427,7 +6536,8 @@ class DefinitionParser(BaseParser):
self.skip_ws()
semicolon = self.skip_string(';')
return ASTDeclaration(objectType, directiveType, visibility,
- templatePrefix, declaration, semicolon)
+ templatePrefix, requiresClause, declaration,
+ trailingRequiresClause, semicolon)
def parse_namespace_object(self) -> ASTNamespace:
templatePrefix = self._parse_template_declaration_prefix(objectType="namespace")
diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py
index 6dc597022..fbbed3a6b 100644
--- a/sphinx/domains/std.py
+++ b/sphinx/domains/std.py
@@ -43,7 +43,7 @@ logger = logging.getLogger(__name__)
# RE for option descriptions
-option_desc_re = re.compile(r'((?:/|--|-|\+)?[^\s=]+)(=?\s*.*)')
+option_desc_re = re.compile(r'((?:/|--|-|\+)?[^\s=[]+)(=?\s*.*)')
# RE for grammar tokens
token_re = re.compile(r'`(\w+)`', re.U)
diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py
index 4dde73829..fe7daf214 100644
--- a/sphinx/ext/autosummary/generate.py
+++ b/sphinx/ext/autosummary/generate.py
@@ -143,11 +143,11 @@ class AutosummaryRenderer:
if isinstance(app, (Sphinx, DummyApplication)):
if app.translator:
self.env.add_extension("jinja2.ext.i18n")
- self.env.install_gettext_translations(app.translator) # type: ignore
+ self.env.install_gettext_translations(app.translator)
elif isinstance(app, Builder):
if app.app.translator:
self.env.add_extension("jinja2.ext.i18n")
- self.env.install_gettext_translations(app.app.translator) # type: ignore
+ self.env.install_gettext_translations(app.app.translator)
def exists(self, template_name: str) -> bool:
"""Check if template file exists."""
diff --git a/sphinx/jinja2glue.py b/sphinx/jinja2glue.py
index e943cfb1e..52d0257e5 100644
--- a/sphinx/jinja2glue.py
+++ b/sphinx/jinja2glue.py
@@ -186,7 +186,7 @@ class BuiltinTemplateLoader(TemplateBridge, BaseLoader):
self.environment.globals['accesskey'] = contextfunction(accesskey)
self.environment.globals['idgen'] = idgen
if use_i18n:
- self.environment.install_gettext_translations(builder.app.translator) # type: ignore # NOQA
+ self.environment.install_gettext_translations(builder.app.translator)
def render(self, template: str, context: Dict) -> str: # type: ignore
return self.environment.get_template(template).render(context)
diff --git a/sphinx/search/__init__.py b/sphinx/search/__init__.py
index 74fbaade9..b531145f4 100644
--- a/sphinx/search/__init__.py
+++ b/sphinx/search/__init__.py
@@ -297,8 +297,8 @@ class IndexBuilder:
frozen.get('envversion') != self.env.version:
raise ValueError('old format')
index2fn = frozen['docnames']
- self._filenames = dict(zip(index2fn, frozen['filenames']))
- self._titles = dict(zip(index2fn, frozen['titles']))
+ self._filenames = dict(zip(index2fn, frozen['filenames'])) # type: ignore
+ self._titles = dict(zip(index2fn, frozen['titles'])) # type: ignore
def load_terms(mapping: Dict[str, Any]) -> Dict[str, Set[str]]:
rv = {}
@@ -359,13 +359,13 @@ class IndexBuilder:
def get_terms(self, fn2index: Dict) -> Tuple[Dict[str, List[str]], Dict[str, List[str]]]:
rvs = {}, {} # type: Tuple[Dict[str, List[str]], Dict[str, List[str]]]
for rv, mapping in zip(rvs, (self._mapping, self._title_mapping)):
- for k, v in mapping.items():
+ for k, v in mapping.items(): # type: ignore
if len(v) == 1:
fn, = v
if fn in fn2index:
- rv[k] = fn2index[fn]
+ rv[k] = fn2index[fn] # type: ignore
else:
- rv[k] = sorted([fn2index[fn] for fn in v if fn in fn2index])
+ rv[k] = sorted([fn2index[fn] for fn in v if fn in fn2index]) # type: ignore # NOQA
return rvs
def freeze(self) -> Dict[str, Any]:
diff --git a/sphinx/util/console.py b/sphinx/util/console.py
index 98563f58e..d429be602 100644
--- a/sphinx/util/console.py
+++ b/sphinx/util/console.py
@@ -35,8 +35,7 @@ def get_terminal_width() -> int:
import termios
import fcntl
import struct
- call = fcntl.ioctl(0, termios.TIOCGWINSZ, # type: ignore
- struct.pack('hhhh', 0, 0, 0, 0))
+ call = fcntl.ioctl(0, termios.TIOCGWINSZ, struct.pack('hhhh', 0, 0, 0, 0))
height, width = struct.unpack('hhhh', call)[:2]
terminal_width = width
except Exception:
diff --git a/sphinx/util/images.py b/sphinx/util/images.py
index 115007d31..0ddf64908 100644
--- a/sphinx/util/images.py
+++ b/sphinx/util/images.py
@@ -54,7 +54,7 @@ def get_image_size(filename: str) -> Optional[Tuple[int, int]]:
def guess_mimetype_for_stream(stream: IO, default: Optional[str] = None) -> Optional[str]:
- imgtype = imghdr.what(stream) # type: ignore
+ imgtype = imghdr.what(stream)
if imgtype:
return 'image/' + imgtype
else:
diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py
index a18eac580..1ec3a19d0 100644
--- a/sphinx/util/nodes.py
+++ b/sphinx/util/nodes.py
@@ -29,6 +29,7 @@ if False:
# For type annotation
from typing import Type # for python3.5.1
from sphinx.builders import Builder
+ from sphinx.domain import IndexEntry
from sphinx.environment import BuildEnvironment
from sphinx.utils.tags import Tags
@@ -313,7 +314,7 @@ def get_prev_node(node: Node) -> Node:
return None
-def traverse_translatable_index(doctree: Element) -> Iterable[Tuple[Element, List[str]]]:
+def traverse_translatable_index(doctree: Element) -> Iterable[Tuple[Element, List["IndexEntry"]]]: # NOQA
"""Traverse translatable index node from a document tree."""
for node in doctree.traverse(NodeMatcher(addnodes.index, inline=False)): # type: addnodes.index # NOQA
if 'raw_entries' in node:
diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py
index 6decc1cef..664387cac 100644
--- a/sphinx/util/pycompat.py
+++ b/sphinx/util/pycompat.py
@@ -90,7 +90,7 @@ def execfile_(filepath: str, _globals: Any, open: Callable = open) -> None:
deprecated_alias('sphinx.util.pycompat',
{
- 'NoneType': NoneType, # type: ignore
+ 'NoneType': NoneType,
'TextIOWrapper': io.TextIOWrapper,
'htmlescape': html.escape,
'indent': textwrap.indent,
diff --git a/sphinx/util/template.py b/sphinx/util/template.py
index 2449a60a1..18047d687 100644
--- a/sphinx/util/template.py
+++ b/sphinx/util/template.py
@@ -28,7 +28,7 @@ class BaseRenderer:
def __init__(self, loader: BaseLoader = None) -> None:
self.env = SandboxedEnvironment(loader=loader, extensions=['jinja2.ext.i18n'])
self.env.filters['repr'] = repr
- self.env.install_gettext_translations(get_translator()) # type: ignore
+ self.env.install_gettext_translations(get_translator())
def render(self, template_name: str, context: Dict) -> str:
return self.env.get_template(template_name).render(context)
diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py
index de92e7593..18b363eca 100644
--- a/sphinx/util/typing.py
+++ b/sphinx/util/typing.py
@@ -53,7 +53,7 @@ def stringify(annotation: Any) -> str:
return annotation.__name__
elif not annotation:
return repr(annotation)
- elif annotation is NoneType: # type: ignore
+ elif annotation is NoneType:
return 'None'
elif (getattr(annotation, '__module__', None) == 'builtins' and
hasattr(annotation, '__qualname__')):
@@ -91,7 +91,7 @@ def _stringify_py37(annotation: Any) -> str:
if getattr(annotation, '__args__', None):
if qualname == 'Union':
- if len(annotation.__args__) > 1 and annotation.__args__[-1] is NoneType: # type: ignore # NOQA
+ if len(annotation.__args__) > 1 and annotation.__args__[-1] is NoneType:
if len(annotation.__args__) > 2:
args = ', '.join(stringify(a) for a in annotation.__args__[:-1])
return 'Optional[Union[%s]]' % args
@@ -165,7 +165,7 @@ def _stringify_py36(annotation: Any) -> str:
hasattr(annotation, '__union_params__')): # for Python 3.5
params = annotation.__union_params__
if params is not None:
- if len(params) == 2 and params[1] is NoneType: # type: ignore
+ if len(params) == 2 and params[1] is NoneType:
return 'Optional[%s]' % stringify(params[0])
else:
param_str = ', '.join(stringify(p) for p in params)
@@ -174,7 +174,7 @@ def _stringify_py36(annotation: Any) -> str:
annotation.__origin__ is typing.Union): # for Python 3.5.2+
params = annotation.__args__
if params is not None:
- if len(params) > 1 and params[-1] is NoneType: # type: ignore
+ if len(params) > 1 and params[-1] is NoneType:
if len(params) > 2:
param_str = ", ".join(stringify(p) for p in params[:-1])
return 'Optional[Union[%s]]' % param_str