summaryrefslogtreecommitdiff
path: root/sphinx/domains
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-03-30 01:58:17 +0900
committerGitHub <noreply@github.com>2020-03-30 01:58:17 +0900
commitfb9d759f09e3ae5ebd50fec9c5e01a81b98c2e7d (patch)
treef36d57ee067683c1675694ecbb8e598ffca2ebf5 /sphinx/domains
parent01a6dfdc5a2d60b7c59f00b03f56897782df8266 (diff)
parentfa10309322c51871e4d91edb700b613fa33c420b (diff)
downloadsphinx-git-fb9d759f09e3ae5ebd50fec9c5e01a81b98c2e7d.tar.gz
Merge pull request #7399 from tk0miya/refactor_type_annotation2
refactor: Update type annotation for cpp domain
Diffstat (limited to 'sphinx/domains')
-rw-r--r--sphinx/domains/c.py20
-rw-r--r--sphinx/domains/cpp.py26
2 files changed, 23 insertions, 23 deletions
diff --git a/sphinx/domains/c.py b/sphinx/domains/c.py
index a7b42cfd3..cf815bd04 100644
--- a/sphinx/domains/c.py
+++ b/sphinx/domains/c.py
@@ -10,7 +10,7 @@
import re
from typing import (
- Any, Callable, Dict, Iterator, List, Type, Tuple, Union
+ Any, Callable, Dict, Generator, Iterator, List, Type, Tuple, Union
)
from typing import cast
@@ -339,7 +339,7 @@ class ASTPostfixCallExpr(ASTPostfixOp):
class ASTPostfixArray(ASTPostfixOp):
- def __init__(self, expr):
+ def __init__(self, expr: ASTExpression) -> None:
self.expr = expr
def _stringify(self, transform: StringifyTransform) -> str:
@@ -1353,7 +1353,7 @@ class LookupKey:
def __init__(self, data: List[Tuple[ASTIdentifier, str]]) -> None:
self.data = data
- def __str__(self):
+ def __str__(self) -> str:
return '[{}]'.format(', '.join("({}, {})".format(
ident, id_) for ident, id_ in self.data))
@@ -1378,7 +1378,7 @@ class Symbol:
if self.declaration:
assert self.docname
- def __setattr__(self, key, value):
+ def __setattr__(self, key: str, value: Any) -> None:
if key == "children":
assert False
else:
@@ -1540,7 +1540,7 @@ class Symbol:
Symbol.debug_print("recurseInAnon: ", recurseInAnon)
Symbol.debug_print("searchInSiblings: ", searchInSiblings)
- def candidates():
+ def candidates() -> Generator["Symbol", None, None]:
s = self
if Symbol.debug_lookup:
Symbol.debug_print("searching in self:")
@@ -1732,7 +1732,7 @@ class Symbol:
# First check if one of those with a declaration matches.
# If it's a function, we need to compare IDs,
# otherwise there should be only one symbol with a declaration.
- def makeCandSymbol():
+ def makeCandSymbol() -> "Symbol":
if Symbol.debug_lookup:
Symbol.debug_print("begin: creating candidate symbol")
symbol = Symbol(parent=lookupResult.parentSymbol,
@@ -1748,7 +1748,7 @@ class Symbol:
else:
candSymbol = makeCandSymbol()
- def handleDuplicateDeclaration(symbol, candSymbol):
+ def handleDuplicateDeclaration(symbol: "Symbol", candSymbol: "Symbol") -> None:
if Symbol.debug_lookup:
Symbol.debug_indent += 1
Symbol.debug_print("redeclaration")
@@ -2350,7 +2350,7 @@ class DefinitionParser(BaseParser):
return ASTBinOpExpr(exprs, ops)
return _parse_bin_op_expr(self, 0)
- def _parse_conditional_expression_tail(self, orExprHead):
+ def _parse_conditional_expression_tail(self, orExprHead: Any) -> ASTExpression:
# -> "?" expression ":" assignment-expression
return None
@@ -2643,7 +2643,7 @@ class DefinitionParser(BaseParser):
arrayOps.append(ASTArray(None))
continue
- def parser():
+ def parser() -> ASTExpression:
return self._parse_expression()
value = self._parse_expression_fallback([']'], parser)
@@ -2892,7 +2892,7 @@ class DefinitionParser(BaseParser):
if self.skip_string('='):
self.skip_ws()
- def parser():
+ def parser() -> ASTExpression:
return self._parse_constant_expression()
initVal = self._parse_expression_fallback([], parser)
diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py
index dbb6d1a39..8787bc9ce 100644
--- a/sphinx/domains/cpp.py
+++ b/sphinx/domains/cpp.py
@@ -10,7 +10,7 @@
import re
from typing import (
- Any, Callable, Dict, Iterator, List, Tuple, Type, TypeVar, Union
+ Any, Callable, Dict, Generator, Iterator, List, Tuple, Type, TypeVar, Union
)
from docutils import nodes
@@ -3717,7 +3717,7 @@ class Symbol:
if self.declaration:
assert self.docname
- def __setattr__(self, key, value):
+ def __setattr__(self, key: str, value: Any) -> None:
if key == "children":
assert False
else:
@@ -3829,7 +3829,7 @@ class Symbol:
yield s
@property
- def children_recurse_anon(self):
+ def children_recurse_anon(self) -> Generator["Symbol", None, None]:
for c in self._children:
yield c
if not c.identOrOp.is_anon():
@@ -3936,7 +3936,7 @@ class Symbol:
if not isSpecialization():
templateArgs = None
- def matches(s):
+ def matches(s: "Symbol") -> bool:
if s.identOrOp != identOrOp:
return False
if (s.templateParams is None) != (templateParams is None):
@@ -3958,7 +3958,7 @@ class Symbol:
return False
return True
- def candidates():
+ def candidates() -> Generator[Symbol, None, None]:
s = self
if Symbol.debug_lookup:
Symbol.debug_print("searching in self:")
@@ -4220,7 +4220,7 @@ class Symbol:
# First check if one of those with a declaration matches.
# If it's a function, we need to compare IDs,
# otherwise there should be only one symbol with a declaration.
- def makeCandSymbol():
+ def makeCandSymbol() -> "Symbol":
if Symbol.debug_lookup:
Symbol.debug_print("begin: creating candidate symbol")
symbol = Symbol(parent=lookupResult.parentSymbol,
@@ -4237,7 +4237,7 @@ class Symbol:
else:
candSymbol = makeCandSymbol()
- def handleDuplicateDeclaration(symbol, candSymbol):
+ def handleDuplicateDeclaration(symbol: "Symbol", candSymbol: "Symbol") -> None:
if Symbol.debug_lookup:
Symbol.debug_indent += 1
Symbol.debug_print("redeclaration")
@@ -4951,7 +4951,7 @@ class DefinitionParser(BaseParser):
if not self.skip_string("("):
self.fail("Expected '(' in '%s'." % cast)
- def parser():
+ def parser() -> ASTExpression:
return self._parse_expression()
expr = self._parse_expression_fallback([')'], parser)
self.skip_ws()
@@ -4972,7 +4972,7 @@ class DefinitionParser(BaseParser):
self.pos = pos
try:
- def parser():
+ def parser() -> ASTExpression:
return self._parse_expression()
expr = self._parse_expression_fallback([')'], parser)
prefix = ASTTypeId(expr, isType=False)
@@ -5230,7 +5230,7 @@ class DefinitionParser(BaseParser):
return ASTBinOpExpr(exprs, ops)
return _parse_bin_op_expr(self, 0, inTemplate=inTemplate)
- def _parse_conditional_expression_tail(self, orExprHead):
+ def _parse_conditional_expression_tail(self, orExprHead: Any) -> None:
# -> "?" expression ":" assignment-expression
return None
@@ -5762,7 +5762,7 @@ class DefinitionParser(BaseParser):
arrayOps.append(ASTArray(None))
continue
- def parser():
+ def parser() -> ASTExpression:
return self._parse_expression()
value = self._parse_expression_fallback([']'], parser)
if not self.skip_string(']'):
@@ -5945,7 +5945,7 @@ class DefinitionParser(BaseParser):
inTemplate = outer == 'templateParam'
- def parser():
+ def parser() -> ASTExpression:
return self._parse_assignment_expression(inTemplate=inTemplate)
value = self._parse_expression_fallback(fallbackEnd, parser, allow=allowFallback)
return ASTInitializer(value)
@@ -6141,7 +6141,7 @@ class DefinitionParser(BaseParser):
if self.skip_string('='):
self.skip_ws()
- def parser():
+ def parser() -> ASTExpression:
return self._parse_constant_expression(inTemplate=False)
initVal = self._parse_expression_fallback([], parser)
init = ASTInitializer(initVal)