refactor: Update type annotation for cpp domain

This commit is contained in:
Takeshi KOMIYA 2020-03-27 00:30:55 +09:00
parent fd9d9f97bf
commit fa10309322
3 changed files with 24 additions and 24 deletions

View File

@ -10,7 +10,7 @@
import re import re
from typing import ( from typing import (
Any, Callable, Dict, Iterator, List, Type, Tuple, Union Any, Callable, Dict, Generator, Iterator, List, Type, Tuple, Union
) )
from typing import cast from typing import cast
@ -339,7 +339,7 @@ class ASTPostfixCallExpr(ASTPostfixOp):
class ASTPostfixArray(ASTPostfixOp): class ASTPostfixArray(ASTPostfixOp):
def __init__(self, expr): def __init__(self, expr: ASTExpression) -> None:
self.expr = expr self.expr = expr
def _stringify(self, transform: StringifyTransform) -> str: def _stringify(self, transform: StringifyTransform) -> str:
@ -1353,7 +1353,7 @@ class LookupKey:
def __init__(self, data: List[Tuple[ASTIdentifier, str]]) -> None: def __init__(self, data: List[Tuple[ASTIdentifier, str]]) -> None:
self.data = data self.data = data
def __str__(self): def __str__(self) -> str:
return '[{}]'.format(', '.join("({}, {})".format( return '[{}]'.format(', '.join("({}, {})".format(
ident, id_) for ident, id_ in self.data)) ident, id_) for ident, id_ in self.data))
@ -1378,7 +1378,7 @@ class Symbol:
if self.declaration: if self.declaration:
assert self.docname assert self.docname
def __setattr__(self, key, value): def __setattr__(self, key: str, value: Any) -> None:
if key == "children": if key == "children":
assert False assert False
else: else:
@ -1540,7 +1540,7 @@ class Symbol:
Symbol.debug_print("recurseInAnon: ", recurseInAnon) Symbol.debug_print("recurseInAnon: ", recurseInAnon)
Symbol.debug_print("searchInSiblings: ", searchInSiblings) Symbol.debug_print("searchInSiblings: ", searchInSiblings)
def candidates(): def candidates() -> Generator["Symbol", None, None]:
s = self s = self
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_print("searching in self:") Symbol.debug_print("searching in self:")
@ -1732,7 +1732,7 @@ class Symbol:
# First check if one of those with a declaration matches. # First check if one of those with a declaration matches.
# If it's a function, we need to compare IDs, # If it's a function, we need to compare IDs,
# otherwise there should be only one symbol with a declaration. # otherwise there should be only one symbol with a declaration.
def makeCandSymbol(): def makeCandSymbol() -> "Symbol":
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_print("begin: creating candidate symbol") Symbol.debug_print("begin: creating candidate symbol")
symbol = Symbol(parent=lookupResult.parentSymbol, symbol = Symbol(parent=lookupResult.parentSymbol,
@ -1748,7 +1748,7 @@ class Symbol:
else: else:
candSymbol = makeCandSymbol() candSymbol = makeCandSymbol()
def handleDuplicateDeclaration(symbol, candSymbol): def handleDuplicateDeclaration(symbol: "Symbol", candSymbol: "Symbol") -> None:
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_indent += 1 Symbol.debug_indent += 1
Symbol.debug_print("redeclaration") Symbol.debug_print("redeclaration")
@ -2350,7 +2350,7 @@ class DefinitionParser(BaseParser):
return ASTBinOpExpr(exprs, ops) return ASTBinOpExpr(exprs, ops)
return _parse_bin_op_expr(self, 0) 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 # -> "?" expression ":" assignment-expression
return None return None
@ -2643,7 +2643,7 @@ class DefinitionParser(BaseParser):
arrayOps.append(ASTArray(None)) arrayOps.append(ASTArray(None))
continue continue
def parser(): def parser() -> ASTExpression:
return self._parse_expression() return self._parse_expression()
value = self._parse_expression_fallback([']'], parser) value = self._parse_expression_fallback([']'], parser)
@ -2892,7 +2892,7 @@ class DefinitionParser(BaseParser):
if self.skip_string('='): if self.skip_string('='):
self.skip_ws() self.skip_ws()
def parser(): def parser() -> ASTExpression:
return self._parse_constant_expression() return self._parse_constant_expression()
initVal = self._parse_expression_fallback([], parser) initVal = self._parse_expression_fallback([], parser)

View File

@ -10,7 +10,7 @@
import re import re
from typing import ( 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 from docutils import nodes
@ -3717,7 +3717,7 @@ class Symbol:
if self.declaration: if self.declaration:
assert self.docname assert self.docname
def __setattr__(self, key, value): def __setattr__(self, key: str, value: Any) -> None:
if key == "children": if key == "children":
assert False assert False
else: else:
@ -3829,7 +3829,7 @@ class Symbol:
yield s yield s
@property @property
def children_recurse_anon(self): def children_recurse_anon(self) -> Generator["Symbol", None, None]:
for c in self._children: for c in self._children:
yield c yield c
if not c.identOrOp.is_anon(): if not c.identOrOp.is_anon():
@ -3936,7 +3936,7 @@ class Symbol:
if not isSpecialization(): if not isSpecialization():
templateArgs = None templateArgs = None
def matches(s): def matches(s: "Symbol") -> bool:
if s.identOrOp != identOrOp: if s.identOrOp != identOrOp:
return False return False
if (s.templateParams is None) != (templateParams is None): if (s.templateParams is None) != (templateParams is None):
@ -3958,7 +3958,7 @@ class Symbol:
return False return False
return True return True
def candidates(): def candidates() -> Generator[Symbol, None, None]:
s = self s = self
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_print("searching in self:") Symbol.debug_print("searching in self:")
@ -4220,7 +4220,7 @@ class Symbol:
# First check if one of those with a declaration matches. # First check if one of those with a declaration matches.
# If it's a function, we need to compare IDs, # If it's a function, we need to compare IDs,
# otherwise there should be only one symbol with a declaration. # otherwise there should be only one symbol with a declaration.
def makeCandSymbol(): def makeCandSymbol() -> "Symbol":
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_print("begin: creating candidate symbol") Symbol.debug_print("begin: creating candidate symbol")
symbol = Symbol(parent=lookupResult.parentSymbol, symbol = Symbol(parent=lookupResult.parentSymbol,
@ -4237,7 +4237,7 @@ class Symbol:
else: else:
candSymbol = makeCandSymbol() candSymbol = makeCandSymbol()
def handleDuplicateDeclaration(symbol, candSymbol): def handleDuplicateDeclaration(symbol: "Symbol", candSymbol: "Symbol") -> None:
if Symbol.debug_lookup: if Symbol.debug_lookup:
Symbol.debug_indent += 1 Symbol.debug_indent += 1
Symbol.debug_print("redeclaration") Symbol.debug_print("redeclaration")
@ -4951,7 +4951,7 @@ class DefinitionParser(BaseParser):
if not self.skip_string("("): if not self.skip_string("("):
self.fail("Expected '(' in '%s'." % cast) self.fail("Expected '(' in '%s'." % cast)
def parser(): def parser() -> ASTExpression:
return self._parse_expression() return self._parse_expression()
expr = self._parse_expression_fallback([')'], parser) expr = self._parse_expression_fallback([')'], parser)
self.skip_ws() self.skip_ws()
@ -4972,7 +4972,7 @@ class DefinitionParser(BaseParser):
self.pos = pos self.pos = pos
try: try:
def parser(): def parser() -> ASTExpression:
return self._parse_expression() return self._parse_expression()
expr = self._parse_expression_fallback([')'], parser) expr = self._parse_expression_fallback([')'], parser)
prefix = ASTTypeId(expr, isType=False) prefix = ASTTypeId(expr, isType=False)
@ -5230,7 +5230,7 @@ class DefinitionParser(BaseParser):
return ASTBinOpExpr(exprs, ops) return ASTBinOpExpr(exprs, ops)
return _parse_bin_op_expr(self, 0, inTemplate=inTemplate) 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 # -> "?" expression ":" assignment-expression
return None return None
@ -5762,7 +5762,7 @@ class DefinitionParser(BaseParser):
arrayOps.append(ASTArray(None)) arrayOps.append(ASTArray(None))
continue continue
def parser(): def parser() -> ASTExpression:
return self._parse_expression() return self._parse_expression()
value = self._parse_expression_fallback([']'], parser) value = self._parse_expression_fallback([']'], parser)
if not self.skip_string(']'): if not self.skip_string(']'):
@ -5945,7 +5945,7 @@ class DefinitionParser(BaseParser):
inTemplate = outer == 'templateParam' inTemplate = outer == 'templateParam'
def parser(): def parser() -> ASTExpression:
return self._parse_assignment_expression(inTemplate=inTemplate) return self._parse_assignment_expression(inTemplate=inTemplate)
value = self._parse_expression_fallback(fallbackEnd, parser, allow=allowFallback) value = self._parse_expression_fallback(fallbackEnd, parser, allow=allowFallback)
return ASTInitializer(value) return ASTInitializer(value)
@ -6141,7 +6141,7 @@ class DefinitionParser(BaseParser):
if self.skip_string('='): if self.skip_string('='):
self.skip_ws() self.skip_ws()
def parser(): def parser() -> ASTExpression:
return self._parse_constant_expression(inTemplate=False) return self._parse_constant_expression(inTemplate=False)
initVal = self._parse_expression_fallback([], parser) initVal = self._parse_expression_fallback([], parser)
init = ASTInitializer(initVal) init = ASTInitializer(initVal)

View File

@ -210,7 +210,7 @@ class SigElementFallbackTransform(SphinxPostTransform):
else: else:
self.fallback() self.fallback()
def fallback(self): def fallback(self) -> None:
for node in self.document.traverse(addnodes.desc_sig_element): for node in self.document.traverse(addnodes.desc_sig_element):
newnode = nodes.inline() newnode = nodes.inline()
newnode.update_all_atts(node) newnode.update_all_atts(node)