diff options
Diffstat (limited to 'sphinx/domains/cpp.py')
-rw-r--r-- | sphinx/domains/cpp.py | 1004 |
1 files changed, 560 insertions, 444 deletions
diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index 62767c15e..51ebe35f1 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ sphinx.domains.cpp ~~~~~~~~~~~~~~~~~~ @@ -10,13 +9,14 @@ """ import re +import warnings from copy import deepcopy from docutils import nodes, utils from docutils.parsers.rst import directives -from six import iteritems, text_type from sphinx import addnodes +from sphinx.deprecation import RemovedInSphinx40Warning from sphinx.directives import ObjectDescription from sphinx.domains import Domain, ObjType from sphinx.environment import NoUri @@ -26,7 +26,6 @@ from sphinx.util import logging from sphinx.util.docfields import Field, GroupedField from sphinx.util.docutils import SphinxDirective from sphinx.util.nodes import make_refnode -from sphinx.util.pycompat import UnicodeMixin if False: @@ -72,7 +71,7 @@ logger = logging.getLogger(__name__) Grammar ---------------------------------------------------------------------------- - See http://www.nongnu.org/hcb/ for the grammar, + See https://www.nongnu.org/hcb/ for the grammar, and https://github.com/cplusplus/draft/blob/master/source/grammar.tex, and https://github.com/cplusplus/concepts-ts for the newest grammar. @@ -347,7 +346,7 @@ _fold_operator_re = re.compile(r'''(?x) | != | [<>=/*%+|&^~-]=? ''') -# see http://en.cppreference.com/w/cpp/keyword +# see https://en.cppreference.com/w/cpp/keyword _keywords = [ 'alignas', 'alignof', 'and', 'and_eq', 'asm', 'auto', 'bitand', 'bitor', 'bool', 'break', 'case', 'catch', 'char', 'char16_t', 'char32_t', 'class', @@ -382,7 +381,7 @@ _id_fundamental_v1 = { 'signed long': 'l', 'unsigned long': 'L', 'bool': 'b' -} # type: Dict[unicode, unicode] +} _id_shorthands_v1 = { 'std::string': 'ss', 'std::ostream': 'os', @@ -390,7 +389,7 @@ _id_shorthands_v1 = { 'std::iostream': 'ios', 'std::vector': 'v', 'std::map': 'm' -} # type: Dict[unicode, unicode] +} _id_operator_v1 = { 'new': 'new-operator', 'new[]': 'new-array-operator', @@ -439,7 +438,7 @@ _id_operator_v1 = { '->': 'pointer-operator', '()': 'call-operator', '[]': 'subscript-operator' -} # type: Dict[unicode, unicode] +} # ------------------------------------------------------------------------------ # Id v > 1 constants @@ -484,7 +483,7 @@ _id_fundamental_v2 = { 'auto': 'Da', 'decltype(auto)': 'Dc', 'std::nullptr_t': 'Dn' -} # type: Dict[unicode, unicode] +} _id_operator_v2 = { 'new': 'nw', 'new[]': 'na', @@ -535,7 +534,7 @@ _id_operator_v2 = { '()': 'cl', '[]': 'ix', '.*': 'ds' # this one is not overloadable, but we need it for expressions -} # type: Dict[unicode, unicode] +} _id_operator_unary_v2 = { '++': 'pp_', '--': 'mm_', @@ -549,7 +548,7 @@ _id_operator_unary_v2 = { _id_char_from_prefix = { None: 'c', 'u8': 'c', 'u': 'Ds', 'U': 'Di', 'L': 'w' -} # type: Dict[unicode, unicode] +} # type: Dict[Any, str] # these are ordered by preceedence _expression_bin_ops = [ ['||'], @@ -575,28 +574,28 @@ _id_explicit_cast = { } -class NoOldIdError(UnicodeMixin, Exception): +class NoOldIdError(Exception): # Used to avoid implementing unneeded id generation for old id schmes. - def __init__(self, description=""): - # type: (unicode) -> None - self.description = description - - def __unicode__(self): - # type: () -> unicode - return self.description - + @property + def description(self): + # type: () -> str + warnings.warn('%s.description is deprecated. ' + 'Coerce the instance to a string instead.' % self.__class__.__name__, + RemovedInSphinx40Warning, stacklevel=2) + return str(self) -class DefinitionError(UnicodeMixin, Exception): - def __init__(self, description): - # type: (unicode) -> None - self.description = description - def __unicode__(self): - # type: () -> unicode - return self.description +class DefinitionError(Exception): + @property + def description(self): + # type: () -> str + warnings.warn('%s.description is deprecated. ' + 'Coerce the instance to a string instead.' % self.__class__.__name__, + RemovedInSphinx40Warning, stacklevel=2) + return str(self) -class _DuplicateSymbolError(UnicodeMixin, Exception): +class _DuplicateSymbolError(Exception): def __init__(self, symbol, declaration): # type: (Symbol, Any) -> None assert symbol @@ -604,28 +603,24 @@ class _DuplicateSymbolError(UnicodeMixin, Exception): self.symbol = symbol self.declaration = declaration - def __unicode__(self): - # type: () -> unicode + def __str__(self): + # type: () -> str return "Internal C++ duplicate symbol error:\n%s" % self.symbol.dump(0) -class ASTBase(UnicodeMixin): +class ASTBase: def __eq__(self, other): # type: (Any) -> bool if type(self) is not type(other): return False try: - for key, value in iteritems(self.__dict__): + for key, value in self.__dict__.items(): if value != getattr(other, key): return False except AttributeError: return False return True - def __ne__(self, other): - # type: (Any) -> bool - return not self.__eq__(other) - __hash__ = None # type: Callable[[], int] def clone(self): @@ -634,15 +629,15 @@ class ASTBase(UnicodeMixin): return deepcopy(self) def _stringify(self, transform): - # type: (Callable[[Any], unicode]) -> unicode + # type: (Callable[[Any], str]) -> str raise NotImplementedError(repr(self)) - def __unicode__(self): - # type: () -> unicode - return self._stringify(lambda ast: text_type(ast)) + def __str__(self): + # type: () -> str + return self._stringify(lambda ast: str(ast)) def get_display_string(self): - # type: () -> unicode + # type: () -> str return self._stringify(lambda ast: ast.get_display_string()) def __repr__(self): @@ -651,7 +646,7 @@ class ASTBase(UnicodeMixin): def _verify_description_mode(mode): - # type: (unicode) -> None + # type: (str) -> None if mode not in ('lastIsName', 'noneIsName', 'markType', 'param'): raise Exception("Description mode '%s' is invalid." % mode) @@ -662,7 +657,7 @@ def _verify_description_mode(mode): class ASTCPPAttribute(ASTBase): def __init__(self, arg): - # type: (unicode) -> None + # type: (str) -> None self.arg = arg def _stringify(self, transform): @@ -670,18 +665,19 @@ class ASTCPPAttribute(ASTBase): def describe_signature(self, signode): # type: (addnodes.desc_signature) -> None - txt = text_type(self) + txt = str(self) signode.append(nodes.Text(txt, txt)) class ASTGnuAttribute(ASTBase): def __init__(self, name, args): - # type: (unicode, Any) -> None + # type: (str, Any) -> None self.name = name self.args = args def _stringify(self, transform): - res = [self.name] # type: List[unicode] + # type: (Callable[[Any], str]) -> str + res = [self.name] if self.args: res.append('(') res.append(transform(self.args)) @@ -695,7 +691,8 @@ class ASTGnuAttributeList(ASTBase): self.attrs = attrs def _stringify(self, transform): - res = ['__attribute__(('] # type: List[unicode] + # type: (Callable[[Any], str]) -> str + res = ['__attribute__(('] first = True for attr in self.attrs: if not first: @@ -707,7 +704,7 @@ class ASTGnuAttributeList(ASTBase): def describe_signature(self, signode): # type: (addnodes.desc_signature) -> None - txt = text_type(self) + txt = str(self) signode.append(nodes.Text(txt, txt)) @@ -715,10 +712,11 @@ class ASTIdAttribute(ASTBase): """For simple attributes defined by the user.""" def __init__(self, id): - # type: (unicode) -> None + # type: (str) -> None self.id = id def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return self.id def describe_signature(self, signode): @@ -730,16 +728,17 @@ class ASTParenAttribute(ASTBase): """For paren attributes defined by the user.""" def __init__(self, id, arg): - # type: (unicode, unicode) -> None + # type: (str, str) -> None self.id = id self.arg = arg def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return self.id + '(' + self.arg + ')' def describe_signature(self, signode): # type: (addnodes.desc_signature) -> None - txt = text_type(self) + txt = str(self) signode.append(nodes.Text(txt, txt)) @@ -749,9 +748,11 @@ class ASTParenAttribute(ASTBase): class ASTPointerLiteral(ASTBase): def _stringify(self, transform): - return u'nullptr' + # type: (Callable[[Any], str]) -> str + return 'nullptr' def get_id(self, version): + # type: (int) -> str return 'LDnE' def describe_signature(self, signode, mode, env, symbol): @@ -763,45 +764,54 @@ class ASTBooleanLiteral(ASTBase): self.value = value def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str if self.value: - return u'true' + return 'true' else: - return u'false' + return 'false' def get_id(self, version): + # type: (int) -> str if self.value: return 'L1E' else: return 'L0E' def describe_signature(self, signode, mode, env, symbol): - signode.append(nodes.Text(text_type(self))) + signode.append(nodes.Text(str(self))) class ASTNumberLiteral(ASTBase): def __init__(self, data): - # type: (unicode) -> None + # type: (str) -> None self.data = data def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return self.data def get_id(self, version): + # type: (int) -> str return "L%sE" % self.data def describe_signature(self, signode, mode, env, symbol): - txt = text_type(self) + txt = str(self) signode.append(nodes.Text(txt, txt)) -class UnsupportedMultiCharacterCharLiteral(UnicodeMixin, Exception): - def __init__(self, decoded): - self.decoded = decoded +class UnsupportedMultiCharacterCharLiteral(Exception): + @property + def decoded(self): + # type: () -> str + warnings.warn('%s.decoded is deprecated. ' + 'Coerce the instance to a string instead.' % self.__class__.__name__, + RemovedInSphinx40Warning, stacklevel=2) + return str(self) class ASTCharLiteral(ASTBase): def __init__(self, prefix, data): - # type: (unicode, unicode) -> None + # type: (str, str) -> None self.prefix = prefix # may be None when no prefix self.data = data assert prefix in _id_char_from_prefix @@ -813,41 +823,47 @@ class ASTCharLiteral(ASTBase): raise UnsupportedMultiCharacterCharLiteral(decoded) def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str if self.prefix is None: return "'" + self.data + "'" else: return self.prefix + "'" + self.data + "'" def get_id(self, version): + # type: (int) -> str return self.type + str(self.value) def describe_signature(self, signode, mode, env, symbol): - txt = text_type(self) + txt = str(self) signode.append(nodes.Text(txt, txt)) class ASTStringLiteral(ASTBase): def __init__(self, data): - # type: (unicode) -> None + # type: (str) -> None self.data = data def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return self.data def get_id(self, version): + # type: (int) -> str # note: the length is not really correct with escaping return "LA%d_KcE" % (len(self.data) - 2) def describe_signature(self, signode, mode, env, symbol): - txt = text_type(self) + txt = str(self) signode.append(nodes.Text(txt, txt)) class ASTThisLiteral(ASTBase): def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return "this" def get_id(self, version): + # type: (int) -> str return "fpT" def describe_signature(self, signode, mode, env, symbol): @@ -859,9 +875,11 @@ class ASTParenExpr(ASTBase): self.expr = expr def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return '(' + transform(self.expr) + ')' def get_id(self, version): + # type: (int) -> str return self.expr.get_id(version) def describe_signature(self, signode, mode, env, symbol): @@ -878,25 +896,27 @@ class ASTFoldExpr(ASTBase): self.rightExpr = rightExpr def _stringify(self, transform): - res = [u'('] + # type: (Callable[[Any], str]) -> str + res = ['('] if self.leftExpr: res.append(transform(self.leftExpr)) - res.append(u' ') + res.append(' ') res.append(transform(self.op)) - res.append(u' ') - res.append(u'...') + res.append(' ') + res.append('...') if self.rightExpr: - res.append(u' ') + res.append(' ') res.append(transform(self.op)) - res.append(u' ') + res.append(' ') res.append(transform(self.rightExpr)) - res.append(u')') - return u''.join(res) + res.append(')') + return ''.join(res) def get_id(self, version): + # type: (int) -> str assert version >= 3 if version == 3: - return text_type(self) + return str(self) # TODO: find the right mangling scheme assert False @@ -924,6 +944,7 @@ class ASTBinOpExpr(ASTBase): self.ops = ops def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = [] res.append(transform(self.exprs[0])) for i in range(1, len(self.exprs)): @@ -931,16 +952,17 @@ class ASTBinOpExpr(ASTBase): res.append(self.ops[i - 1]) res.append(' ') res.append(transform(self.exprs[i])) - return u''.join(res) + return ''.join(res) def get_id(self, version): + # type: (int) -> str assert version >= 2 res = [] for i in range(len(self.ops)): res.append(_id_operator_v2[self.ops[i]]) res.append(self.exprs[i].get_id(version)) res.append(self.exprs[-1].get_id(version)) - return u''.join(res) + return ''.join(res) def describe_signature(self, signode, mode, env, symbol): self.exprs[0].describe_signature(signode, mode, env, symbol) @@ -959,6 +981,7 @@ class ASTAssignmentExpr(ASTBase): self.ops = ops def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = [] res.append(transform(self.exprs[0])) for i in range(1, len(self.exprs)): @@ -966,15 +989,16 @@ class ASTAssignmentExpr(ASTBase): res.append(self.ops[i - 1]) res.append(' ') res.append(transform(self.exprs[i])) - return u''.join(res) + return ''.join(res) def get_id(self, version): + # type: (int) -> str res = [] for i in range(len(self.ops)): res.append(_id_operator_v2[self.ops[i]]) res.append(self.exprs[i].get_id(version)) res.append(self.exprs[-1].get_id(version)) - return u''.join(res) + return ''.join(res) def describe_signature(self, signode, mode, env, symbol): self.exprs[0].describe_signature(signode, mode, env, symbol) @@ -991,13 +1015,15 @@ class ASTCastExpr(ASTBase): self.expr = expr def _stringify(self, transform): - res = [u'('] + # type: (Callable[[Any], str]) -> str + res = ['('] res.append(transform(self.typ)) - res.append(u')') + res.append(')') res.append(transform(self.expr)) - return u''.join(res) + return ''.join(res) def get_id(self, version): + # type: (int) -> str return 'cv' + self.typ.get_id(version) + self.expr.get_id(version) def describe_signature(self, signode, mode, env, symbol): @@ -1013,9 +1039,11 @@ class ASTUnaryOpExpr(ASTBase): self.expr = expr def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return transform(self.op) + transform(self.expr) def get_id(self, version): + # type: (int) -> str return _id_operator_unary_v2[self.op] + self.expr.get_id(version) def describe_signature(self, signode, mode, env, symbol): @@ -1028,9 +1056,11 @@ class ASTSizeofParamPack(ASTBase): self.identifier = identifier def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return "sizeof...(" + transform(self.identifier) + ")" def get_id(self, version): + # type: (int) -> str return 'sZ' + self.identifier.get_id(version) def describe_signature(self, signode, mode, env, symbol): @@ -1045,9 +1075,11 @@ class ASTSizeofType(ASTBase): self.typ = typ def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return "sizeof(" + transform(self.typ) + ")" def get_id(self, version): + # type: (int) -> str return 'st' + self.typ.get_id(version) def describe_signature(self, signode, mode, env, symbol): @@ -1061,9 +1093,11 @@ class ASTSizeofExpr(ASTBase): self.expr = expr def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return "sizeof " + transform(self.expr) def get_id(self, version): + # type: (int) -> str return 'sz' + self.expr.get_id(version) def describe_signature(self, signode, mode, env, symbol): @@ -1076,9 +1110,11 @@ class ASTAlignofExpr(ASTBase): self.typ = typ def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return "alignof(" + transform(self.typ) + ")" def get_id(self, version): + # type: (int) -> str return 'at' + self.typ.get_id(version) def describe_signature(self, signode, mode, env, symbol): @@ -1092,9 +1128,11 @@ class ASTNoexceptExpr(ASTBase): self.expr = expr def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return "noexcept(" + transform(self.expr) + ")" def get_id(self, version): + # type: (int) -> str return 'nx' + self.expr.get_id(version) def describe_signature(self, signode, mode, env, symbol): @@ -1105,7 +1143,7 @@ class ASTNoexceptExpr(ASTBase): class ASTNewExpr(ASTBase): def __init__(self, rooted, isNewTypeId, typ, initList, initType): - # type: (bool, bool, ASTType, List[Any], unicode) -> None + # type: (bool, bool, ASTType, List[Any], str) -> None self.rooted = rooted self.isNewTypeId = isNewTypeId self.typ = typ @@ -1115,6 +1153,7 @@ class ASTNewExpr(ASTBase): assert self.initType in ')}' def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = [] if self.rooted: res.append('::') @@ -1134,9 +1173,10 @@ class ASTNewExpr(ASTBase): first = False res.append(transform(e)) res.append(self.initType) - return u''.join(res) + return ''.join(res) def get_id(self, version): + # type: (int) -> str # the array part will be in the type mangling, so na is not used res = ['nw'] # TODO: placement @@ -1152,7 +1192,7 @@ class ASTNewExpr(ASTBase): assert False else: res.append('E') - return u''.join(res) + return ''.join(res) def describe_signature(self, signode, mode, env, symbol): if self.rooted: @@ -1184,6 +1224,7 @@ class ASTDeleteExpr(ASTBase): self.expr = expr def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = [] if self.rooted: res.append('::') @@ -1191,9 +1232,10 @@ class ASTDeleteExpr(ASTBase): if self.array: res.append('[] ') res.append(transform(self.expr)) - return u''.join(res) + return ''.join(res) def get_id(self, version): + # type: (int) -> str if self.array: id = "da" else: @@ -1217,15 +1259,17 @@ class ASTExplicitCast(ASTBase): self.expr = expr def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = [self.cast] res.append('<') res.append(transform(self.typ)) res.append('>(') res.append(transform(self.expr)) res.append(')') - return u''.join(res) + return ''.join(res) def get_id(self, version): + # type: (int) -> str return (_id_explicit_cast[self.cast] + self.typ.get_id(version) + self.expr.get_id(version)) @@ -1246,9 +1290,11 @@ class ASTTypeId(ASTBase): self.isType = isType def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return 'typeid(' + transform(self.typeOrExpr) + ')' def get_id(self, version): + # type: (int) -> str prefix = 'ti' if self.isType else 'te' return prefix + self.typeOrExpr.get_id(version) @@ -1264,22 +1310,24 @@ class ASTPostfixCallExpr(ASTBase): self.exprs = exprs def _stringify(self, transform): - res = [u'('] + # type: (Callable[[Any], str]) -> str + res = ['('] first = True for e in self.exprs: if not first: - res.append(u', ') + res.append(', ') first = False res.append(transform(e)) - res.append(u')') - return u''.join(res) + res.append(')') + return ''.join(res) def get_id(self, idPrefix, version): + # type: (str, int) -> str res = ['cl', idPrefix] for e in self.exprs: res.append(e.get_id(version)) res.append('E') - return u''.join(res) + return ''.join(res) def describe_signature(self, signode, mode, env, symbol): signode.append(nodes.Text('(')) @@ -1297,9 +1345,11 @@ class ASTPostfixArray(ASTBase): self.expr = expr def _stringify(self, transform): - return u'[' + transform(self.expr) + ']' + # type: (Callable[[Any], str]) -> str + return '[' + transform(self.expr) + ']' def get_id(self, idPrefix, version): + # type: (str, int) -> str return 'ix' + idPrefix + self.expr.get_id(version) def describe_signature(self, signode, mode, env, symbol): @@ -1310,9 +1360,11 @@ class ASTPostfixArray(ASTBase): class ASTPostfixInc(ASTBase): def _stringify(self, transform): - return u'++' + # type: (Callable[[Any], str]) -> str + return '++' def get_id(self, idPrefix, version): + # type: (str, int) -> str return 'pp' + idPrefix def describe_signature(self, signode, mode, env, symbol): @@ -1321,9 +1373,11 @@ class ASTPostfixInc(ASTBase): class ASTPostfixDec(ASTBase): def _stringify(self, transform): - return u'--' + # type: (Callable[[Any], str]) -> str + return '--' def get_id(self, idPrefix, version): + # type: (str, int) -> str return 'mm' + idPrefix def describe_signature(self, signode, mode, env, symbol): @@ -1335,9 +1389,11 @@ class ASTPostfixMember(ASTBase): self.name = name def _stringify(self, transform): - return u'.' + transform(self.name) + # type: (Callable[[Any], str]) -> str + return '.' + transform(self.name) def get_id(self, idPrefix, version): + # type: (str, int) -> str return 'dt' + idPrefix + self.name.get_id(version) def describe_signature(self, signode, mode, env, symbol): @@ -1350,9 +1406,11 @@ class ASTPostfixMemberOfPointer(ASTBase): self.name = name def _stringify(self, transform): - return u'->' + transform(self.name) + # type: (Callable[[Any], str]) -> str + return '->' + transform(self.name) def get_id(self, idPrefix, version): + # type: (str, int) -> str return 'pt' + idPrefix + self.name.get_id(version) def describe_signature(self, signode, mode, env, symbol): @@ -1367,12 +1425,14 @@ class ASTPostfixExpr(ASTBase): self.postFixes = postFixes def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = [transform(self.prefix)] for p in self.postFixes: res.append(transform(p)) - return u''.join(res) + return ''.join(res) def get_id(self, version): + # type: (int) -> str id = self.prefix.get_id(version) for p in self.postFixes: id = p.get_id(id, version) @@ -1389,9 +1449,11 @@ class ASTPackExpansionExpr(ASTBase): self.expr = expr def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return transform(self.expr) + '...' def get_id(self, version): + # type: (int) -> str id = self.expr.get_id(version) return 'sp' + id @@ -1405,10 +1467,12 @@ class ASTFallbackExpr(ASTBase): self.expr = expr def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return self.expr def get_id(self, version): - return text_type(self.expr) + # type: (int) -> str + return str(self.expr) def describe_signature(self, signode, mode, env, symbol): signode += nodes.Text(self.expr) @@ -1420,7 +1484,7 @@ class ASTFallbackExpr(ASTBase): class ASTIdentifier(ASTBase): def __init__(self, identifier): - # type: (unicode) -> None + # type: (str) -> None assert identifier is not None assert len(identifier) != 0 self.identifier = identifier @@ -1429,7 +1493,7 @@ class ASTIdentifier(ASTBase): return self.identifier[0] == '@' def get_id(self, version): - # type: (int) -> unicode + # type: (int) -> str if self.is_anon() and version < 3: raise NoOldIdError() if version == 1: @@ -1444,22 +1508,22 @@ class ASTIdentifier(ASTBase): return 'D0' else: if self.is_anon(): - return u'Ut%d_%s' % (len(self.identifier) - 1, self.identifier[1:]) + return 'Ut%d_%s' % (len(self.identifier) - 1, self.identifier[1:]) else: - return text_type(len(self.identifier)) + self.identifier + return str(len(self.identifier)) + self.identifier - # and this is where we finally make a difference between __unicode__ and the display string + # and this is where we finally make a difference between __str__ and the display string - def __unicode__(self): - # type: () -> unicode + def __str__(self): + # type: () -> str return self.identifier def get_display_string(self): - # type: () -> unicode - return u"[anonymous]" if self.is_anon() else self.identifier + # type: () -> str + return "[anonymous]" if self.is_anon() else self.identifier def describe_signature(self, signode, mode, env, prefix, templateArgs, symbol): - # type: (Any, unicode, BuildEnvironment, unicode, unicode, Symbol) -> None + # type: (Any, str, BuildEnvironment, str, str, Symbol) -> None _verify_description_mode(mode) if mode == 'markType': targetText = prefix + self.identifier + templateArgs @@ -1490,7 +1554,7 @@ class ASTIdentifier(ASTBase): class ASTTemplateKeyParamPackIdDefault(ASTBase): def __init__(self, key, identifier, parameterPack, default): - # type: (unicode, ASTIdentifier, bool, ASTType) -> None + # type: (str, ASTIdentifier, bool, ASTType) -> None assert key if parameterPack: assert default is None @@ -1504,7 +1568,7 @@ class ASTTemplateKeyParamPackIdDefault(ASTBase): return self.identifier def get_id(self, version): - # type: (int) -> unicode + # type: (int) -> str assert version >= 2 # this is not part of the normal name mangling in C++ res = [] @@ -1515,7 +1579,8 @@ class ASTTemplateKeyParamPackIdDefault(ASTBase): return ''.join(res) def _stringify(self, transform): - res = [self.key] # type: List[unicode] + # type: (Callable[[Any], str]) -> str + res = [self.key] if self.parameterPack: if self.identifier: res.append(' ') @@ -1530,7 +1595,7 @@ class ASTTemplateKeyParamPackIdDefault(ASTBase): return ''.join(res) def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None signode += nodes.Text(self.key) if self.parameterPack: if self.identifier: @@ -1559,6 +1624,7 @@ class ASTTemplateParamType(ASTBase): @property def isPack(self): + # type: () -> bool return self.data.parameterPack def get_identifier(self): @@ -1566,7 +1632,7 @@ class ASTTemplateParamType(ASTBase): return self.data.get_identifier() def get_id(self, version, objectType=None, symbol=None): - # type: (int, unicode, Symbol) -> unicode + # type: (int, str, Symbol) -> str # this is not part of the normal name mangling in C++ assert version >= 2 if symbol: @@ -1576,10 +1642,11 @@ class ASTTemplateParamType(ASTBase): return self.data.get_id(version) def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return transform(self.data) def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None self.data.describe_signature(signode, mode, env, symbol) @@ -1597,10 +1664,11 @@ class ASTTemplateParamConstrainedTypeWithInit(ASTBase): @property def isPack(self): + # type: () -> bool return self.type.isPack def get_id(self, version, objectType=None, symbol=None): - # type: (int, unicode, Symbol) -> unicode + # type: (int, str, Symbol) -> str # this is not part of the normal name mangling in C++ assert version >= 2 if symbol: @@ -1610,6 +1678,7 @@ class ASTTemplateParamConstrainedTypeWithInit(ASTBase): return self.type.get_id(version) def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = transform(self.type) if self.init: res += " = " @@ -1617,7 +1686,7 @@ class ASTTemplateParamConstrainedTypeWithInit(ASTBase): return res def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None self.type.describe_signature(signode, mode, env, symbol) if self.init: signode += nodes.Text(" = ") @@ -1640,6 +1709,7 @@ class ASTTemplateParamTemplateType(ASTBase): @property def isPack(self): + # type: () -> bool return self.data.parameterPack def get_identifier(self): @@ -1647,7 +1717,7 @@ class ASTTemplateParamTemplateType(ASTBase): return self.data.get_identifier() def get_id(self, version, objectType=None, symbol=None): - # type: (int, unicode, Symbol) -> unicode + # type: (int, str, Symbol) -> str assert version >= 2 # this is not part of the normal name mangling in C++ if symbol: @@ -1657,10 +1727,11 @@ class ASTTemplateParamTemplateType(ASTBase): return self.nestedParams.get_id(version) + self.data.get_id(version) def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return transform(self.nestedParams) + transform(self.data) def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None self.nestedParams.describe_signature(signode, 'noneIsName', env, symbol) signode += nodes.Text(' ') self.data.describe_signature(signode, mode, env, symbol) @@ -1680,6 +1751,7 @@ class ASTTemplateParamNonType(ASTBase): @property def isPack(self): + # type: () -> bool return self.param.isPack def get_identifier(self): @@ -1694,7 +1766,7 @@ class ASTTemplateParamNonType(ASTBase): return None def get_id(self, version, objectType=None, symbol=None): - # type: (int, unicode, Symbol) -> unicode + # type: (int, str, Symbol) -> str assert version >= 2 # this is not part of the normal name mangling in C++ if symbol: @@ -1704,10 +1776,11 @@ class ASTTemplateParamNonType(ASTBase): return '_' + self.param.get_id(version) def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return transform(self.param) def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None self.param.describe_signature(signode, mode, env, symbol) @@ -1719,7 +1792,7 @@ class ASTTemplateParams(ASTBase): self.isNested = False # whether it's a template template param def get_id(self, version): - # type: (int) -> unicode + # type: (int) -> str assert version >= 2 res = [] res.append("I") @@ -1729,14 +1802,15 @@ class ASTTemplateParams(ASTBase): return ''.join(res) def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = [] - res.append(u"template<") - res.append(u", ".join(transform(a) for a in self.params)) - res.append(u"> ") + res.append("template<") + res.append(", ".join(transform(a) for a in self.params)) + res.append("> ") return ''.join(res) def describe_signature(self, parentNode, mode, env, symbol, lineSpec=None): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol, bool) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol, bool) -> None # 'lineSpec' is defaulted becuase of template template parameters def makeLine(parentNode=parentNode): signode = addnodes.desc_signature_line() @@ -1775,6 +1849,7 @@ class ASTTemplateIntroductionParameter(ASTBase): @property def isPack(self): + # type: () -> bool return self.parameterPack def get_identifier(self): @@ -1782,7 +1857,7 @@ class ASTTemplateIntroductionParameter(ASTBase): return self.identifier def get_id(self, version, objectType=None, symbol=None): - # type: (int, unicode, Symbol) -> unicode + # type: (int, str, Symbol) -> str assert version >= 2 # this is not part of the normal name mangling in C++ if symbol: @@ -1795,24 +1870,25 @@ class ASTTemplateIntroductionParameter(ASTBase): return '0' # we need to put something def get_id_as_arg(self, version): - # type: (int) -> unicode + # type: (int) -> str assert version >= 2 # used for the implicit requires clause res = self.identifier.get_id(version) if self.parameterPack: - return u'sp' + res + return 'sp' + res else: return res def _stringify(self, transform): - res = [] # type: List[unicode] + # type: (Callable[[Any], str]) -> str + res = [] if self.parameterPack: res.append('...') res.append(transform(self.identifier)) return ''.join(res) def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None if self.parameterPack: signode += nodes.Text('...') self.identifier.describe_signature(signode, mode, env, '', '', symbol) @@ -1826,7 +1902,7 @@ class ASTTemplateIntroduction(ASTBase): self.params = params def get_id(self, version): - # type: (int) -> unicode + # type: (int) -> str assert version >= 2 # first do the same as a normal template parameter list res = [] @@ -1845,6 +1921,7 @@ class ASTTemplateIntroduction(ASTBase): return ''.join(res) def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = [] res.append(transform(self.concept)) res.append('{') @@ -1853,7 +1930,7 @@ class ASTTemplateIntroduction(ASTBase): return ''.join(res) def describe_signature(self, parentNode, mode, env, symbol, lineSpec): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol, bool) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol, bool) -> None # Note: 'lineSpec' has no effect on template introductions. signode = addnodes.desc_signature_line() parentNode += signode @@ -1876,22 +1953,23 @@ class ASTTemplateDeclarationPrefix(ASTBase): self.templates = templates def get_id(self, version): - # type: (int) -> unicode + # type: (int) -> str assert version >= 2 # this is not part of a normal name mangling system res = [] for t in self.templates: res.append(t.get_id(version)) - return u''.join(res) + return ''.join(res) def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = [] for t in self.templates: res.append(transform(t)) - return u''.join(res) + return ''.join(res) def describe_signature(self, signode, mode, env, symbol, lineSpec): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol, bool) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol, bool) -> None _verify_description_mode(mode) for t in self.templates: t.describe_signature(signode, 'lastIsName', env, symbol, lineSpec) @@ -1909,13 +1987,13 @@ class ASTOperator(ASTBase): return True def get_id(self, version): - # type: (int) -> unicode + # type: (int) -> str raise NotImplementedError() def describe_signature(self, signode, mode, env, prefix, templateArgs, symbol): - # type: (addnodes.desc_signature, unicode, Any, unicode, unicode, Symbol) -> None + # type: (addnodes.desc_signature, str, Any, str, str, Symbol) -> None _verify_description_mode(mode) - identifier = text_type(self) + identifier = str(self) if mode == 'lastIsName': signode += addnodes.desc_name(identifier, identifier) else: @@ -1924,11 +2002,11 @@ class ASTOperator(ASTBase): class ASTOperatorBuildIn(ASTOperator): def __init__(self, op): - # type: (unicode) -> None + # type: (str) -> None self.op = op def get_id(self, version): - # type: (int) -> unicode + # type: (int) -> str if version == 1: ids = _id_operator_v1 else: @@ -1939,10 +2017,11 @@ class ASTOperatorBuildIn(ASTOperator): return ids[self.op] def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str if self.op in ('new', 'new[]', 'delete', 'delete[]'): - return u'operator ' + self.op + return 'operator ' + self.op else: - return u'operator' + self.op + return 'operator' + self.op class ASTOperatorType(ASTOperator): @@ -1951,18 +2030,19 @@ class ASTOperatorType(ASTOperator): self.type = type def get_id(self, version): - # type: (int) -> unicode + # type: (int) -> str if version == 1: - return u'castto-%s-operator' % self.type.get_id(version) + return 'castto-%s-operator' % self.type.get_id(version) else: - return u'cv' + self.type.get_id(version) + return 'cv' + self.type.get_id(version) def _stringify(self, transform): - return u''.join(['operator ', transform(self.type)]) + # type: (Callable[[Any], str]) -> str + return ''.join(['operator ', transform(self.type)]) def get_name_no_template(self): - # type: () -> unicode - return text_type(self) + # type: () -> str + return str(self) class ASTOperatorLiteral(ASTOperator): @@ -1971,14 +2051,15 @@ class ASTOperatorLiteral(ASTOperator): self.identifier = identifier def get_id(self, version): - # type: (int) -> unicode + # type: (int) -> str if version == 1: raise NoOldIdError() else: - return u'li' + self.identifier.get_id(version) + return 'li' + self.identifier.get_id(version) def _stringify(self, transform): - return u'operator""' + transform(self.identifier) + # type: (Callable[[Any], str]) -> str + return 'operator""' + transform(self.identifier) ############################################################################################## @@ -1990,18 +2071,19 @@ class ASTTemplateArgConstant(ASTBase): self.value = value def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return transform(self.value) def get_id(self, version): - # type: (int) -> unicode + # type: (int) -> str if version == 1: - return text_type(self).replace(u' ', u'-') + return str(self).replace(' ', '-') if version == 2: - return u'X' + text_type(self) + u'E' - return u'X' + self.value.get_id(version) + u'E' + return 'X' + str(self) + 'E' + return 'X' + self.value.get_id(version) + 'E' def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) self.value.describe_signature(signode, mode, env, symbol) @@ -2013,27 +2095,28 @@ class ASTTemplateArgs(ASTBase): self.args = args def get_id(self, version): - # type: (int) -> unicode + # type: (int) -> str if version == 1: - res = [] # type: List[unicode] + res = [] res.append(':') - res.append(u'.'.join(a.get_id(version) for a in self.args)) + res.append('.'.join(a.get_id(version) for a in self.args)) res.append(':') - return u''.join(res) + return ''.join(res) res = [] res.append('I') for a in self.args: res.append(a.get_id(version)) res.append('E') - return u''.join(res) + return ''.join(res) def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = ', '.join(transform(a) for a in self.args) return '<' + res + '>' def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) signode += nodes.Text('<') first = True @@ -2056,21 +2139,22 @@ class ASTNestedNameElement(ASTBase): return False def get_id(self, version): - # type: (int) -> unicode + # type: (int) -> str res = self.identOrOp.get_id(version) if self.templateArgs: res += self.templateArgs.get_id(version) return res def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = transform(self.identOrOp) if self.templateArgs: res += transform(self.templateArgs) return res def describe_signature(self, signode, mode, env, prefix, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, unicode, Symbol) -> None - tArgs = text_type(self.templateArgs) if self.templateArgs is not None else '' + # type: (addnodes.desc_signature, str, BuildEnvironment, str, Symbol) -> None + tArgs = str(self.templateArgs) if self.templateArgs is not None else '' self.identOrOp.describe_signature(signode, mode, env, prefix, tArgs, symbol) if self.templateArgs is not None: self.templateArgs.describe_signature(signode, mode, env, symbol) @@ -2101,14 +2185,15 @@ class ASTNestedName(ASTBase): return count def get_id(self, version, modifiers=''): - # type: (int, unicode) -> unicode + # type: (int, str) -> str if version == 1: - tt = text_type(self) + tt = str(self) if tt in _id_shorthands_v1: return _id_shorthands_v1[tt] else: - return u'::'.join(n.get_id(version) for n in self.names) - res = [] # type: List[unicode] + return '::'.join(n.get_id(version) for n in self.names) + + res = [] if len(self.names) > 1 or len(modifiers) > 0: res.append('N') res.append(modifiers) @@ -2116,10 +2201,11 @@ class ASTNestedName(ASTBase): res.append(n.get_id(version)) if len(self.names) > 1 or len(modifiers) > 0: res.append('E') - return u''.join(res) + return ''.join(res) def _stringify(self, transform): - res = [] # type: List[unicode] + # type: (Callable[[Any], str]) -> str + res = [] if self.rooted: res.append('') for i in range(len(self.names)): @@ -2132,13 +2218,13 @@ class ASTNestedName(ASTBase): return '::'.join(res) def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) # just print the name part, with template args, not template params if mode == 'noneIsName': - signode += nodes.Text(text_type(self)) + signode += nodes.Text(str(self)) elif mode == 'param': - name = text_type(self) + name = str(self) signode += nodes.emphasis(name, name) elif mode == 'markType' or mode == 'lastIsName': # Each element should be a pending xref targeting the complete @@ -2151,8 +2237,8 @@ class ASTNestedName(ASTBase): if symbol.declaration.templatePrefix is not None: templateParams = symbol.declaration.templatePrefix.templates iTemplateParams = 0 - templateParamsPrefix = u'' - prefix = '' # type: unicode + templateParamsPrefix = '' + prefix = '' first = True names = self.names[:-1] if mode == 'lastIsName' else self.names # If lastIsName, then wrap all of the prefix in a desc_addname, @@ -2161,7 +2247,7 @@ class ASTNestedName(ASTBase): # so it can remove it in inner declarations. dest = signode if mode == 'lastIsName': - dest = addnodes.desc_addname() + dest = addnodes.desc_addname() # type: ignore for i in range(len(names)): nne = names[i] template = self.templates[i] @@ -2171,10 +2257,10 @@ class ASTNestedName(ASTBase): if template: dest += nodes.Text("template ") first = False - txt_nne = text_type(nne) + txt_nne = str(nne) if txt_nne != '': if nne.templateArgs and iTemplateParams < len(templateParams): - templateParamsPrefix += text_type(templateParams[iTemplateParams]) + templateParamsPrefix += str(templateParams[iTemplateParams]) iTemplateParams += 1 nne.describe_signature(dest, 'markType', env, templateParamsPrefix + prefix, symbol) @@ -2192,14 +2278,15 @@ class ASTNestedName(ASTBase): class ASTTrailingTypeSpecFundamental(ASTBase): def __init__(self, name): - # type: (unicode) -> None + # type: (str) -> None self.name = name def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return self.name def get_id(self, version): - # type: (int) -> unicode + # type: (int) -> str if version == 1: res = [] for a in self.name.split(' '): @@ -2207,7 +2294,7 @@ class ASTTrailingTypeSpecFundamental(ASTBase): res.append(_id_fundamental_v1[a]) else: res.append(a) - return u'-'.join(res) + return '-'.join(res) if self.name not in _id_fundamental_v2: raise Exception( @@ -2217,13 +2304,13 @@ class ASTTrailingTypeSpecFundamental(ASTBase): return _id_fundamental_v2[self.name] def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None - signode += nodes.Text(text_type(self.name)) + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None + signode += nodes.Text(str(self.name)) class ASTTrailingTypeSpecName(ASTBase): def __init__(self, prefix, nestedName): - # type: (unicode, Any) -> None + # type: (str, Any) -> None self.prefix = prefix self.nestedName = nestedName @@ -2233,19 +2320,20 @@ class ASTTrailingTypeSpecName(ASTBase): return self.nestedName def get_id(self, version): - # type: (int) -> unicode + # type: (int) -> str return self.nestedName.get_id(version) def _stringify(self, transform): - res = [] # type: List[unicode] + # type: (Callable[[Any], str]) -> str + res = [] if self.prefix: res.append(self.prefix) res.append(' ') res.append(transform(self.nestedName)) - return u''.join(res) + return ''.join(res) def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None if self.prefix: signode += addnodes.desc_annotation(self.prefix, self.prefix) signode += nodes.Text(' ') @@ -2254,16 +2342,18 @@ class ASTTrailingTypeSpecName(ASTBase): class ASTTrailingTypeSpecDecltypeAuto(ASTBase): def _stringify(self, transform): - return u'decltype(auto)' + # type: (Callable[[Any], str]) -> str + return 'decltype(auto)' def get_id(self, version): + # type: (int) -> str if version == 1: raise NoOldIdError() return 'Dc' def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None - signode.append(nodes.Text(text_type(self))) + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None + signode.append(nodes.Text(str(self))) class ASTTrailingTypeSpecDecltype(ASTBase): @@ -2271,14 +2361,17 @@ class ASTTrailingTypeSpecDecltype(ASTBase): self.expr = expr def _stringify(self, transform): - return u'decltype(' + transform(self.expr) + ')' + # type: (Callable[[Any], str]) -> str + return 'decltype(' + transform(self.expr) + ')' def get_id(self, version): + # type: (int) -> str if version == 1: raise NoOldIdError() return 'DT' + self.expr.get_id(version) + "E" def describe_signature(self, signode, mode, env, symbol): + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None signode.append(nodes.Text('decltype(')) self.expr.describe_signature(signode, mode, env, symbol) signode.append(nodes.Text(')')) @@ -2291,7 +2384,7 @@ class ASTFunctionParameter(ASTBase): self.ellipsis = ellipsis def get_id(self, version, objectType=None, symbol=None): - # type: (int, unicode, Symbol) -> unicode + # type: (int, str, Symbol) -> str # this is not part of the normal name mangling in C++ if symbol: # the anchor will be our parent @@ -2303,13 +2396,14 @@ class ASTFunctionParameter(ASTBase): return self.arg.get_id(version) def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str if self.ellipsis: return '...' else: return transform(self.arg) def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) if self.ellipsis: signode += nodes.Text('...') @@ -2320,7 +2414,7 @@ class ASTFunctionParameter(ASTBase): class ASTParametersQualifiers(ASTBase): def __init__(self, args, volatile, const, refQual, exceptionSpec, override, final, initializer): - # type: (List[Any], bool, bool, unicode, unicode, bool, bool, unicode) -> None + # type: (List[Any], bool, bool, str, str, bool, bool, str) -> None self.args = args self.volatile = volatile self.const = const @@ -2336,7 +2430,7 @@ class ASTParametersQualifiers(ASTBase): return self.args def get_modifiers_id(self, version): - # type: (int) -> unicode + # type: (int) -> str res = [] if self.volatile: res.append('V') @@ -2349,29 +2443,30 @@ class ASTParametersQualifiers(ASTBase): res.append('O') elif self.refQual == '&': res.append('R') - return u''.join(res) + return ''.join(res) def get_param_id(self, version): - # type: (int) -> unicode + # type: (int) -> str if version == 1: if len(self.args) == 0: return '' else: - return u'__' + u'.'.join(a.get_id(version) for a in self.args) + return '__' + '.'.join(a.get_id(version) for a in self.args) if len(self.args) == 0: return 'v' else: - return u''.join(a.get_id(version) for a in self.args) + return ''.join(a.get_id(version) for a in self.args) def _stringify(self, transform): - res = [] # type: List[unicode] + # type: (Callable[[Any], str]) -> str + res = [] res.append('(') first = True for a in self.args: if not first: res.append(', ') first = False - res.append(text_type(a)) + res.append(str(a)) res.append(')') if self.volatile: res.append(' volatile') @@ -2382,7 +2477,7 @@ class ASTParametersQualifiers(ASTBase): res.append(self.refQual) if self.exceptionSpec: res.append(' ') - res.append(text_type(self.exceptionSpec)) + res.append(str(self.exceptionSpec)) if self.final: res.append(' final') if self.override: @@ -2390,10 +2485,10 @@ class ASTParametersQualifiers(ASTBase): if self.initializer: res.append(' = ') res.append(self.initializer) - return u''.join(res) + return ''.join(res) def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) paramlist = addnodes.desc_parameterlist() for arg in self.args: @@ -2419,19 +2514,19 @@ class ASTParametersQualifiers(ASTBase): if self.refQual: _add_text(signode, self.refQual) if self.exceptionSpec: - _add_anno(signode, text_type(self.exceptionSpec)) + _add_anno(signode, str(self.exceptionSpec)) if self.final: _add_anno(signode, 'final') if self.override: _add_anno(signode, 'override') if self.initializer: - _add_text(signode, '= ' + text_type(self.initializer)) + _add_text(signode, '= ' + str(self.initializer)) class ASTDeclSpecsSimple(ASTBase): def __init__(self, storage, threadLocal, inline, virtual, explicit, constexpr, volatile, const, friend, attrs): - # type: (unicode, bool, bool, bool, bool, bool, bool, bool, bool, List[Any]) -> None + # type: (str, bool, bool, bool, bool, bool, bool, bool, bool, List[Any]) -> None self.storage = storage self.threadLocal = threadLocal self.inline = inline @@ -2459,7 +2554,8 @@ class ASTDeclSpecsSimple(ASTBase): self.attrs + other.attrs) def _stringify(self, transform): - res = [] # type: List[unicode] + # type: (Callable[[Any], str]) -> str + res = [] # type: List[str] res.extend(transform(attr) for attr in self.attrs) if self.storage: res.append(self.storage) @@ -2479,7 +2575,7 @@ class ASTDeclSpecsSimple(ASTBase): res.append('volatile') if self.const: res.append('const') - return u' '.join(res) + return ' '.join(res) def describe_signature(self, modifiers): # type: (List[nodes.Node]) -> None @@ -2527,7 +2623,7 @@ class ASTDeclSpecs(ASTBase): return self.trailingTypeSpec.name def get_id(self, version): - # type: (int) -> unicode + # type: (int) -> str if version == 1: res = [] res.append(self.trailingTypeSpec.get_id(version)) @@ -2535,17 +2631,18 @@ class ASTDeclSpecs(ASTBase): res.append('V') if self.allSpecs.const: res.append('C') - return u''.join(res) + return ''.join(res) res = [] if self.leftSpecs.volatile or self.rightSpecs.volatile: res.append('V') if self.leftSpecs.const or self.rightSpecs.volatile: res.append('K') res.append(self.trailingTypeSpec.get_id(version)) - return u''.join(res) + return ''.join(res) def _stringify(self, transform): - res = [] # type: List[unicode] + # type: (Callable[[Any], str]) -> str + res = [] # type: List[str] l = transform(self.leftSpecs) if len(l) > 0: if len(res) > 0: @@ -2555,7 +2652,7 @@ class ASTDeclSpecs(ASTBase): if len(res) > 0: res.append(" ") res.append(transform(self.trailingTypeSpec)) - r = text_type(self.rightSpecs) + r = str(self.rightSpecs) if len(r) > 0: if len(res) > 0: res.append(" ") @@ -2563,7 +2660,7 @@ class ASTDeclSpecs(ASTBase): return "".join(res) def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) modifiers = [] # type: List[nodes.Node] @@ -2594,24 +2691,25 @@ class ASTArray(ASTBase): self.size = size def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str if self.size: - return u'[' + transform(self.size) + ']' + return '[' + transform(self.size) + ']' else: - return u'[]' + return '[]' def get_id(self, version): - # type: (int) -> unicode + # type: (int) -> str if version == 1: - return u'A' + return 'A' if version == 2: if self.size: - return u'A' + text_type(self.size) + u'_' + return 'A' + str(self.size) + '_' else: - return u'A_' + return 'A_' if self.size: - return u'A' + self.size.get_id(version) + u'_' + return 'A' + self.size.get_id(version) + '_' else: - return u'A_' + return 'A_' def describe_signature(self, signode, mode, env, symbol): _verify_description_mode(mode) @@ -2646,7 +2744,8 @@ class ASTDeclaratorPtr(ASTBase): return True def _stringify(self, transform): - res = ['*'] # type: List[unicode] + # type: (Callable[[Any], str]) -> str + res = ['*'] for a in self.attrs: res.append(transform(a)) if len(self.attrs) > 0 and (self.volatile or self.const): @@ -2661,18 +2760,18 @@ class ASTDeclaratorPtr(ASTBase): if self.next.require_space_after_declSpecs: res.append(' ') res.append(transform(self.next)) - return u''.join(res) + return ''.join(res) def get_modifiers_id(self, version): - # type: (int) -> unicode + # type: (int) -> str return self.next.get_modifiers_id(version) def get_param_id(self, version): - # type: (int) -> unicode + # type: (int) -> str return self.next.get_param_id(version) def get_ptr_suffix_id(self, version): - # type: (int) -> unicode + # type: (int) -> str if version == 1: res = ['P'] if self.volatile: @@ -2680,7 +2779,7 @@ class ASTDeclaratorPtr(ASTBase): if self.const: res.append('C') res.append(self.next.get_ptr_suffix_id(version)) - return u''.join(res) + return ''.join(res) res = [self.next.get_ptr_suffix_id(version)] res.append('P') @@ -2688,25 +2787,25 @@ class ASTDeclaratorPtr(ASTBase): res.append('V') if self.const: res.append('C') - return u''.join(res) + return ''.join(res) def get_type_id(self, version, returnTypeId): - # type: (int, unicode) -> unicode + # type: (int, str) -> str # ReturnType *next, so we are part of the return type of 'next - res = ['P'] # type: List[unicode] + res = ['P'] if self.volatile: res.append('V') if self.const: res.append('C') res.append(returnTypeId) - return self.next.get_type_id(version, returnTypeId=u''.join(res)) + return self.next.get_type_id(version, returnTypeId=''.join(res)) def is_function_type(self): # type: () -> bool return self.next.is_function_type() def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) signode += nodes.Text("*") for a in self.attrs: @@ -2742,6 +2841,7 @@ class ASTDeclaratorRef(ASTBase): @property def isPack(self): + # type: () -> bool return True @property @@ -2754,41 +2854,42 @@ class ASTDeclaratorRef(ASTBase): return self.next.require_space_after_declSpecs() def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = ['&'] for a in self.attrs: res.append(transform(a)) if len(self.attrs) > 0 and self.next.require_space_after_declSpecs: res.append(' ') res.append(transform(self.next)) - return u''.join(res) + return ''.join(res) def get_modifiers_id(self, version): - # type: (int) -> unicode + # type: (int) -> str return self.next.get_modifiers_id(version) def get_param_id(self, version): # only the parameters (if any) - # type: (int) -> unicode + # type: (int) -> str return self.next.get_param_id(version) def get_ptr_suffix_id(self, version): - # type: (int) -> unicode + # type: (int) -> str if version == 1: - return u'R' + self.next.get_ptr_suffix_id(version) + return 'R' + self.next.get_ptr_suffix_id(version) else: - return self.next.get_ptr_suffix_id(version) + u'R' + return self.next.get_ptr_suffix_id(version) + 'R' def get_type_id(self, version, returnTypeId): - # type: (int, unicode) -> unicode + # type: (int, str) -> str assert version >= 2 # ReturnType &next, so we are part of the return type of 'next - return self.next.get_type_id(version, returnTypeId=u'R' + returnTypeId) + return self.next.get_type_id(version, returnTypeId='R' + returnTypeId) def is_function_type(self): # type: () -> bool return self.next.is_function_type() def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) signode += nodes.Text("&") for a in self.attrs: @@ -2819,38 +2920,39 @@ class ASTDeclaratorParamPack(ASTBase): return False def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = transform(self.next) if self.next.name: res = ' ' + res return '...' + res def get_modifiers_id(self, version): - # type: (int) -> unicode + # type: (int) -> str return self.next.get_modifiers_id(version) def get_param_id(self, version): # only the parameters (if any) - # type: (int) -> unicode + # type: (int) -> str return self.next.get_param_id(version) def get_ptr_suffix_id(self, version): - # type: (int) -> unicode + # type: (int) -> str if version == 1: return 'Dp' + self.next.get_ptr_suffix_id(version) else: - return self.next.get_ptr_suffix_id(version) + u'Dp' + return self.next.get_ptr_suffix_id(version) + 'Dp' def get_type_id(self, version, returnTypeId): - # type: (int, unicode) -> unicode + # type: (int, str) -> str assert version >= 2 # ReturnType... next, so we are part of the return type of 'next - return self.next.get_type_id(version, returnTypeId=u'Dp' + returnTypeId) + return self.next.get_type_id(version, returnTypeId='Dp' + returnTypeId) def is_function_type(self): # type: () -> bool return self.next.is_function_type() def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) signode += nodes.Text("...") if self.next.name: @@ -2883,6 +2985,7 @@ class ASTDeclaratorMemPtr(ASTBase): return True def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = [] res.append(transform(self.className)) res.append('::*') @@ -2896,32 +2999,32 @@ class ASTDeclaratorMemPtr(ASTBase): return ''.join(res) def get_modifiers_id(self, version): - # type: (int) -> unicode + # type: (int) -> str if version == 1: raise NoOldIdError() else: return self.next.get_modifiers_id(version) def get_param_id(self, version): # only the parameters (if any) - # type: (int) -> unicode + # type: (int) -> str if version == 1: raise NoOldIdError() else: return self.next.get_param_id(version) def get_ptr_suffix_id(self, version): - # type: (int) -> unicode + # type: (int) -> str if version == 1: raise NoOldIdError() else: raise NotImplementedError() - return self.next.get_ptr_suffix_id(version) + u'Dp' + return self.next.get_ptr_suffix_id(version) + 'Dp' def get_type_id(self, version, returnTypeId): - # type: (int, unicode) -> unicode + # type: (int, str) -> str assert version >= 2 # ReturnType name::* next, so we are part of the return type of next - nextReturnTypeId = '' # type: unicode + nextReturnTypeId = '' if self.volatile: nextReturnTypeId += 'V' if self.const: @@ -2936,7 +3039,7 @@ class ASTDeclaratorMemPtr(ASTBase): return self.next.is_function_type() def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) self.className.describe_signature(signode, mode, env, symbol) signode += nodes.Text('::*') @@ -2979,22 +3082,23 @@ class ASTDeclaratorParen(ASTBase): return True def _stringify(self, transform): - res = ['('] # type: List[unicode] + # type: (Callable[[Any], str]) -> str + res = ['('] res.append(transform(self.inner)) res.append(')') res.append(transform(self.next)) return ''.join(res) def get_modifiers_id(self, version): - # type: (int) -> unicode + # type: (int) -> str return self.inner.get_modifiers_id(version) def get_param_id(self, version): # only the parameters (if any) - # type: (int) -> unicode + # type: (int) -> str return self.inner.get_param_id(version) def get_ptr_suffix_id(self, version): - # type: (int) -> unicode + # type: (int) -> str if version == 1: raise NoOldIdError() # TODO: was this implemented before? return self.next.get_ptr_suffix_id(version) + \ @@ -3004,7 +3108,7 @@ class ASTDeclaratorParen(ASTBase): self.next.get_ptr_suffix_id(version) def get_type_id(self, version, returnTypeId): - # type: (int, unicode) -> unicode + # type: (int, str) -> str assert version >= 2 # ReturnType (inner)next, so 'inner' returns everything outside nextId = self.next.get_type_id(version, returnTypeId) @@ -3015,7 +3119,7 @@ class ASTDeclaratorParen(ASTBase): return self.inner.is_function_type() def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) signode += nodes.Text('(') self.inner.describe_signature(signode, mode, env, symbol) @@ -3037,6 +3141,7 @@ class ASTDeclaratorNameParamQual(ASTBase): @property def isPack(self): + # type: () -> bool return False @property @@ -3045,26 +3150,25 @@ class ASTDeclaratorNameParamQual(ASTBase): return self.paramQual.function_params def get_modifiers_id(self, version): # only the modifiers for a function, e.g., - # type: (int) -> unicode + # type: (int) -> str # cv-qualifiers if self.paramQual: return self.paramQual.get_modifiers_id(version) - raise Exception( - "This should only be called on a function: %s" % text_type(self)) + raise Exception("This should only be called on a function: %s" % self) def get_param_id(self, version): # only the parameters (if any) - # type: (int) -> unicode + # type: (int) -> str if self.paramQual: return self.paramQual.get_param_id(version) else: return '' def get_ptr_suffix_id(self, version): # only the array specifiers - # type: (int) -> unicode - return u''.join(a.get_id(version) for a in self.arrayOps) + # type: (int) -> str + return ''.join(a.get_id(version) for a in self.arrayOps) def get_type_id(self, version, returnTypeId): - # type: (int, unicode) -> unicode + # type: (int, str) -> str assert version >= 2 res = [] # TOOD: can we actually have both array ops and paramQual? @@ -3077,7 +3181,7 @@ class ASTDeclaratorNameParamQual(ASTBase): res.append('E') else: res.append(returnTypeId) - return u''.join(res) + return ''.join(res) # ------------------------------------------------------------------------ @@ -3090,6 +3194,7 @@ class ASTDeclaratorNameParamQual(ASTBase): return self.paramQual is not None def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = [] if self.declId: res.append(transform(self.declId)) @@ -3097,10 +3202,10 @@ class ASTDeclaratorNameParamQual(ASTBase): res.append(transform(op)) if self.paramQual: res.append(transform(self.paramQual)) - return u''.join(res) + return ''.join(res) def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) if self.declId: self.declId.describe_signature(signode, mode, env, symbol) @@ -3115,10 +3220,11 @@ class ASTInitializer(ASTBase): self.value = value def _stringify(self, transform): - return u' = ' + transform(self.value) + # type: (Callable[[Any], str]) -> str + return ' = ' + transform(self.value) def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) signode.append(nodes.Text(' = ')) self.value.describe_signature(signode, 'markType', env, symbol) @@ -3139,6 +3245,7 @@ class ASTType(ASTBase): @property def isPack(self): + # type: () -> bool return self.decl.isPack @property @@ -3147,7 +3254,7 @@ class ASTType(ASTBase): return self.decl.function_params def get_id(self, version, objectType=None, symbol=None): - # type: (int, unicode, Symbol) -> unicode + # type: (int, str, Symbol) -> str if version == 1: res = [] if objectType: # needs the name @@ -3170,7 +3277,7 @@ class ASTType(ASTBase): res.append(self.declSpecs.get_id(version)) res.append(self.decl.get_ptr_suffix_id(version)) res.append(self.decl.get_param_id(version)) - return u''.join(res) + return ''.join(res) # other versions res = [] if objectType: # needs the name @@ -3189,30 +3296,31 @@ class ASTType(ASTBase): returnTypeId = self.declSpecs.get_id(version) typeId = self.decl.get_type_id(version, returnTypeId) res.append(typeId) - return u''.join(res) + return ''.join(res) def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = [] declSpecs = transform(self.declSpecs) res.append(declSpecs) if self.decl.require_space_after_declSpecs() and len(declSpecs) > 0: - res.append(u' ') + res.append(' ') res.append(transform(self.decl)) - return u''.join(res) + return ''.join(res) def get_type_declaration_prefix(self): - # type: () -> unicode + # type: () -> str if self.declSpecs.trailingTypeSpec: return 'typedef' else: return 'type' def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) self.declSpecs.describe_signature(signode, 'markType', env, symbol) if (self.decl.require_space_after_declSpecs() and - len(text_type(self.declSpecs)) > 0): + len(str(self.declSpecs)) > 0): signode += nodes.Text(' ') # for parameters that don't really declare new names we get 'markType', # this should not be propagated, but be 'noneIsName'. @@ -3234,26 +3342,28 @@ class ASTTypeWithInit(ASTBase): @property def isPack(self): + # type: () -> bool return self.type.isPack def get_id(self, version, objectType=None, symbol=None): - # type: (int, unicode, Symbol) -> unicode + # type: (int, str, Symbol) -> str if objectType != 'member': return self.type.get_id(version, objectType) if version == 1: - return symbol.get_full_nested_name().get_id(version) + u'__' \ - + self.type.get_id(version) + return (symbol.get_full_nested_name().get_id(version) + '__' + + self.type.get_id(version)) return symbol.get_full_nested_name().get_id(version) def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = [] res.append(transform(self.type)) if self.init: res.append(transform(self.init)) - return u''.join(res) + return ''.join(res) def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) self.type.describe_signature(signode, mode, env, symbol) if self.init: @@ -3267,25 +3377,26 @@ class ASTTypeUsing(ASTBase): self.type = type def get_id(self, version, objectType=None, symbol=None): - # type: (int, unicode, Symbol) -> unicode + # type: (int, str, Symbol) -> str if version == 1: raise NoOldIdError() return symbol.get_full_nested_name().get_id(version) def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = [] res.append(transform(self.name)) if self.type: res.append(' = ') res.append(transform(self.type)) - return u''.join(res) + return ''.join(res) def get_type_declaration_prefix(self): - # type: () -> unicode + # type: () -> str return 'using' def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) self.name.describe_signature(signode, mode, env, symbol=symbol) if self.type: @@ -3305,19 +3416,20 @@ class ASTConcept(ASTBase): return self.nestedName def get_id(self, version, objectType=None, symbol=None): - # type: (int, unicode, Symbol) -> unicode + # type: (int, str, Symbol) -> str if version == 1: raise NoOldIdError() return symbol.get_full_nested_name().get_id(version) def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = transform(self.nestedName) if self.initializer: res += transform(self.initializer) return res def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None self.nestedName.describe_signature(signode, mode, env, symbol) if self.initializer: self.initializer.describe_signature(signode, mode, env, symbol) @@ -3325,14 +3437,15 @@ class ASTConcept(ASTBase): class ASTBaseClass(ASTBase): def __init__(self, name, visibility, virtual, pack): - # type: (Any, unicode, bool, bool) -> None + # type: (Any, str, bool, bool) -> None self.name = name self.visibility = visibility self.virtual = virtual self.pack = pack def _stringify(self, transform): - res = [] # type: List[unicode] + # type: (Callable[[Any], str]) -> str + res = [] if self.visibility != 'private': res.append(self.visibility) res.append(' ') @@ -3341,10 +3454,10 @@ class ASTBaseClass(ASTBase): res.append(transform(self.name)) if self.pack: res.append('...') - return u''.join(res) + return ''.join(res) def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) if self.visibility != 'private': signode += addnodes.desc_annotation(self.visibility, @@ -3366,10 +3479,11 @@ class ASTClass(ASTBase): self.bases = bases def get_id(self, version, objectType, symbol): - # type: (int, unicode, Symbol) -> unicode + # type: (int, str, Symbol) -> str return symbol.get_full_nested_name().get_id(version) def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = [] res.append(transform(self.name)) if self.final: @@ -3382,10 +3496,10 @@ class ASTClass(ASTBase): res.append(', ') first = False res.append(transform(b)) - return u''.join(res) + return ''.join(res) def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) self.name.describe_signature(signode, mode, env, symbol=symbol) if self.final: @@ -3405,35 +3519,37 @@ class ASTUnion(ASTBase): self.name = name def get_id(self, version, objectType, symbol): - # type: (int, unicode, Symbol) -> unicode + # type: (int, str, Symbol) -> str if version == 1: raise NoOldIdError() return symbol.get_full_nested_name().get_id(version) def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str return transform(self.name) def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) self.name.describe_signature(signode, mode, env, symbol=symbol) class ASTEnum(ASTBase): def __init__(self, name, scoped, underlyingType): - # type: (Any, unicode, Any) -> None + # type: (Any, str, Any) -> None self.name = name self.scoped = scoped self.underlyingType = underlyingType def get_id(self, version, objectType, symbol): - # type: (int, unicode, Symbol) -> unicode + # type: (int, str, Symbol) -> str if version == 1: raise NoOldIdError() return symbol.get_full_nested_name().get_id(version) def _stringify(self, transform): - res = [] # type: List[unicode] + # type: (Callable[[Any], str]) -> str + res = [] if self.scoped: res.append(self.scoped) res.append(' ') @@ -3441,10 +3557,10 @@ class ASTEnum(ASTBase): if self.underlyingType: res.append(' : ') res.append(transform(self.underlyingType)) - return u''.join(res) + return ''.join(res) def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) # self.scoped has been done by the CPPEnumObject self.name.describe_signature(signode, mode, env, symbol=symbol) @@ -3461,20 +3577,21 @@ class ASTEnumerator(ASTBase): self.init = init def get_id(self, version, objectType, symbol): - # type: (int, unicode, Symbol) -> unicode + # type: (int, str, Symbol) -> str if version == 1: raise NoOldIdError() return symbol.get_full_nested_name().get_id(version) def _stringify(self, transform): + # type: (Callable[[Any], str]) -> str res = [] res.append(transform(self.name)) if self.init: res.append(transform(self.init)) - return u''.join(res) + return ''.join(res) def describe_signature(self, signode, mode, env, symbol): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Symbol) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None _verify_description_mode(mode) self.name.describe_signature(signode, mode, env, symbol) if self.init: @@ -3483,7 +3600,7 @@ class ASTEnumerator(ASTBase): class ASTDeclaration(ASTBase): def __init__(self, objectType, visibility, templatePrefix, declaration): - # type: (unicode, unicode, Any, Any) -> None + # type: (str, str, Any, Any) -> None self.objectType = objectType self.visibility = visibility self.templatePrefix = templatePrefix @@ -3516,7 +3633,7 @@ class ASTDeclaration(ASTBase): return self.declaration.function_params def get_id(self, version, prefixed=True): - # type: (int, bool) -> unicode + # type: (int, bool) -> str if version == 1: if self.templatePrefix: raise NoOldIdError() @@ -3533,24 +3650,25 @@ class ASTDeclaration(ASTBase): if self.templatePrefix: res.append(self.templatePrefix.get_id(version)) res.append(self.declaration.get_id(version, self.objectType, self.symbol)) - return u''.join(res) + return ''.join(res) def get_newest_id(self): - # type: () -> unicode + # type: () -> str return self.get_id(_max_id, True) def _stringify(self, transform): - res = [] # type: List[unicode] + # type: (Callable[[Any], str]) -> str + res = [] if self.visibility and self.visibility != "public": res.append(self.visibility) - res.append(u' ') + res.append(' ') if self.templatePrefix: res.append(transform(self.templatePrefix)) res.append(transform(self.declaration)) - return u''.join(res) + return ''.join(res) def describe_signature(self, signode, mode, env, options): - # type: (addnodes.desc_signature, unicode, BuildEnvironment, Dict) -> None + # type: (addnodes.desc_signature, str, BuildEnvironment, Dict) -> None _verify_description_mode(mode) assert self.symbol # The caller of the domain added a desc_signature node. @@ -3603,7 +3721,7 @@ class ASTNamespace(ASTBase): self.templatePrefix = templatePrefix -class SymbolLookupResult(object): +class SymbolLookupResult: def __init__(self, symbols, parentSymbol, identOrOp, templateParams, templateArgs): # type: (Iterator[Symbol], Symbol, Union[ASTIdentifier, ASTOperator], Any, ASTTemplateArgs) -> None # NOQA self.symbols = symbols @@ -3613,7 +3731,7 @@ class SymbolLookupResult(object): self.templateArgs = templateArgs -class Symbol(object): +class Symbol: debug_lookup = False debug_show_tree = False @@ -3634,7 +3752,7 @@ class Symbol(object): if key == "children": assert False else: - return object.__setattr__(self, key, value) + return super().__setattr__(key, value) def __init__(self, parent, # type: Symbol @@ -3642,7 +3760,7 @@ class Symbol(object): templateParams, # type: Any templateArgs, # type: Any declaration, # type: ASTDeclaration - docname # type: unicode + docname # type: str ): # type: (...) -> None self.parent = parent @@ -3667,7 +3785,7 @@ class Symbol(object): self._add_template_and_function_params() def _fill_empty(self, declaration, docname): - # type: (ASTDeclaration, unicode) -> None + # type: (ASTDeclaration, str) -> None self._assert_invariants() assert not self.declaration assert not self.docname @@ -3719,7 +3837,7 @@ class Symbol(object): self.parent = None def clear_doc(self, docname): - # type: (unicode) -> None + # type: (str) -> None newChildren = [] for sChild in self._children: sChild.clear_doc(docname) @@ -3742,9 +3860,8 @@ class Symbol(object): yield c if not c.identOrOp.is_anon(): continue - # TODO: change to 'yield from' when Python 2 support is dropped - for nested in c.children_recurse_anon: - yield nested + + yield from c.children_recurse_anon def get_lookup_key(self): # type: () -> List[Tuple[ASTNestedNameElement, Any]] @@ -3811,8 +3928,8 @@ class Symbol(object): param = templateParams.params[i] arg = templateArgs.args[i] # TODO: doing this by string manipulation is probably not the most efficient - paramName = text_type(param.name) - argTxt = text_type(arg) + paramName = str(param.name) + argTxt = str(arg) isArgPackExpansion = argTxt.endswith('...') if param.isPack != isArgPackExpansion: return True @@ -3840,13 +3957,13 @@ class Symbol(object): return False if templateParams: # TODO: do better comparison - if text_type(s.templateParams) != text_type(templateParams): + if str(s.templateParams) != str(templateParams): return False if (s.templateArgs is None) != (templateArgs is None): return False if s.templateArgs: # TODO: do better comparison - if text_type(s.templateArgs) != text_type(templateArgs): + if str(s.templateArgs) != str(templateArgs): return False return True if matchSelf and matches(self): @@ -3863,7 +3980,7 @@ class Symbol(object): onMissingQualifiedSymbol, # type: Callable[[Symbol, Union[ASTIdentifier, ASTOperator], Any, ASTTemplateArgs], Symbol] # NOQA strictTemplateParamArgLists, # type: bool - ancestorLookupType, # type: unicode + ancestorLookupType, # type: str templateShorthand, # type: bool matchSelf, # type: bool recurseInAnon, # type: bool @@ -3964,7 +4081,7 @@ class Symbol(object): identOrOp, templateParams, templateArgs) def _add_symbols(self, nestedName, templateDecls, declaration, docname): - # type: (ASTNestedName, List[Any], ASTDeclaration, unicode) -> Symbol + # type: (ASTNestedName, List[Any], ASTDeclaration, str) -> Symbol # Used for adding a whole path of symbols, where the last may or may not # be an actual declaration. @@ -4116,7 +4233,7 @@ class Symbol(object): return symbol def merge_with(self, other, docnames, env): - # type: (Symbol, List[unicode], BuildEnvironment) -> None + # type: (Symbol, List[str], BuildEnvironment) -> None assert other is not None for otherChild in other._children: ourChild = self._find_first_named_symbol( @@ -4135,7 +4252,7 @@ class Symbol(object): if not ourChild.declaration: ourChild._fill_empty(otherChild.declaration, otherChild.docname) elif ourChild.docname != otherChild.docname: - name = text_type(ourChild.declaration) + name = str(ourChild.declaration) msg = __("Duplicate declaration, also defined in '%s'.\n" "Declaration is '%s'.") msg = msg % (ourChild.docname, name) @@ -4157,7 +4274,7 @@ class Symbol(object): declaration=None, docname=None) def add_declaration(self, declaration, docname): - # type: (ASTDeclaration, unicode) -> Symbol + # type: (ASTDeclaration, str) -> Symbol assert declaration assert docname nestedName = declaration.name @@ -4195,7 +4312,7 @@ class Symbol(object): def find_name(self, nestedName, templateDecls, typ, templateShorthand, matchSelf, recurseInAnon): - # type: (ASTNestedName, List[Any], unicode, bool, bool, bool) -> Symbol + # type: (ASTNestedName, List[Any], str, bool, bool, bool) -> Symbol # templateShorthand: missing template parameter lists for templates is ok def onMissingQualifiedSymbol(parentSymbol, identOrOp, templateParams, templateArgs): @@ -4233,7 +4350,7 @@ class Symbol(object): def find_declaration(self, declaration, typ, templateShorthand, matchSelf, recurseInAnon): - # type: (ASTDeclaration, unicode, bool, bool, bool) -> Symbol + # type: (ASTDeclaration, str, bool, bool, bool) -> Symbol # templateShorthand: missing template parameter lists for templates is ok nestedName = declaration.name if declaration.templatePrefix: @@ -4277,26 +4394,26 @@ class Symbol(object): return None def to_string(self, indent): - # type: (int) -> unicode - res = ['\t' * indent] # type: List[unicode] + # type: (int) -> str + res = ['\t' * indent] if not self.parent: res.append('::') else: if self.templateParams: - res.append(text_type(self.templateParams)) + res.append(str(self.templateParams)) res.append('\n') res.append('\t' * indent) if self.identOrOp: - res.append(text_type(self.identOrOp)) + res.append(str(self.identOrOp)) else: - res.append(text_type(self.declaration)) + res.append(str(self.declaration)) if self.templateArgs: - res.append(text_type(self.templateArgs)) + res.append(str(self.templateArgs)) if self.declaration: res.append(": ") if self.isRedeclaration: res.append('!!duplicate!! ') - res.append(text_type(self.declaration)) + res.append(str(self.declaration)) if self.docname: res.append('\t(') res.append(self.docname) @@ -4305,16 +4422,16 @@ class Symbol(object): return ''.join(res) def dump(self, indent): - # type: (int) -> unicode + # type: (int) -> str res = [self.to_string(indent)] for c in self._children: res.append(c.dump(indent + 1)) return ''.join(res) -class DefinitionParser(object): +class DefinitionParser: # those without signedness and size modifiers - # see http://en.cppreference.com/w/cpp/language/types + # see https://en.cppreference.com/w/cpp/language/types _simple_fundemental_types = ( 'void', 'bool', 'char', 'wchar_t', 'char16_t', 'char32_t', 'int', 'float', 'double', 'auto' @@ -4337,36 +4454,36 @@ class DefinitionParser(object): self.config = config def _make_multi_error(self, errors, header): - # type: (List[Any], unicode) -> DefinitionError + # type: (List[Any], str) -> DefinitionError if len(errors) == 1: if len(header) > 0: - return DefinitionError(header + '\n' + errors[0][0].description) + return DefinitionError(header + '\n' + str(errors[0][0])) else: - return DefinitionError(errors[0][0].description) + return DefinitionError(str(errors[0][0])) result = [header, '\n'] for e in errors: if len(e[1]) > 0: ident = ' ' result.append(e[1]) result.append(':\n') - for line in e[0].description.split('\n'): + for line in str(e[0]).split('\n'): if len(line) == 0: continue result.append(ident) result.append(line) result.append('\n') else: - result.append(e[0].description) + result.append(str(e[0])) return DefinitionError(''.join(result)) def status(self, msg): - # type: (unicode) -> None + # type: (str) -> None # for debugging indicator = '-' * self.pos + '^' print("%s\n%s\n%s" % (msg, self.definition, indicator)) def fail(self, msg): - # type: (unicode) -> None + # type: (str) -> None errors = [] indicator = '-' * self.pos + '^' exMain = DefinitionError( @@ -4379,7 +4496,7 @@ class DefinitionParser(object): raise self._make_multi_error(errors, '') def warn(self, msg): - # type: (unicode) -> None + # type: (str) -> None if self.warnEnv: self.warnEnv.warn(msg) else: @@ -4400,7 +4517,7 @@ class DefinitionParser(object): self.pos, self.last_match = self._previous_state def skip_string(self, string): - # type: (unicode) -> bool + # type: (str) -> bool strlen = len(string) if self.definition[self.pos:self.pos + strlen] == string: self.pos += strlen @@ -4408,7 +4525,7 @@ class DefinitionParser(object): return False def skip_word(self, word): - # type: (unicode) -> bool + # type: (str) -> bool return self.match(re.compile(r'\b%s\b' % re.escape(word))) def skip_ws(self): @@ -4416,14 +4533,14 @@ class DefinitionParser(object): return self.match(_whitespace_re) def skip_word_and_ws(self, word): - # type: (unicode) -> bool + # type: (str) -> bool if self.skip_word(word): self.skip_ws() return True return False def skip_string_and_ws(self, string): - # type: (unicode) -> bool + # type: (str) -> bool if self.skip_string(string): self.skip_ws() return True @@ -4436,7 +4553,7 @@ class DefinitionParser(object): @property def current_char(self): - # type: () -> unicode + # type: () -> str try: return self.definition[self.pos] except IndexError: @@ -4444,14 +4561,14 @@ class DefinitionParser(object): @property def matched_text(self): - # type: () -> unicode + # type: () -> str if self.last_match is not None: return self.last_match.group() else: return None def read_rest(self): - # type: () -> unicode + # type: () -> str rv = self.definition[self.pos:] self.pos = self.end return rv @@ -4482,11 +4599,11 @@ class DefinitionParser(object): return self.definition[startPos:self.pos] def _parse_balanced_token_seq(self, end): - # type: (List[unicode]) -> unicode + # type: (List[str]) -> str # TODO: add handling of string literals and similar - brackets = {'(': ')', '[': ']', '{': '}'} # type: Dict[unicode, unicode] + brackets = {'(': ')', '[': ']', '{': '}'} startPos = self.pos - symbols = [] # type: List[unicode] + symbols = [] # type: List[str] while not self.eof: if len(symbols) == 0 and self.current_char in end: break @@ -4652,7 +4769,7 @@ class DefinitionParser(object): return self._parse_nested_name() def _parse_expression_list_or_braced_init_list(self): - # type: () -> Tuple[List[Any], unicode] + # type: () -> Tuple[List[Any], str] self.skip_ws() if self.skip_string_and_ws('('): close = ')' @@ -5064,7 +5181,7 @@ class DefinitionParser(object): if not allow or not self.allowFallbackExpressionParsing: raise self.warn("Parsing of expression failed. Using fallback parser." - " Error was:\n%s" % e.description) + " Error was:\n%s" % e) self.pos = prevPos # and then the fallback scanning assert end is not None @@ -5074,8 +5191,8 @@ class DefinitionParser(object): value = self.matched_text else: # TODO: add handling of more bracket-like things, and quote handling - brackets = {'(': ')', '[': ']', '<': '>'} # type: Dict[unicode, unicode] - symbols = [] # type: List[unicode] + brackets = {'(': ')', '[': ']', '<': '>'} + symbols = [] # type: List[str] while not self.eof: if (len(symbols) == 0 and self.current_char in end): break @@ -5248,7 +5365,7 @@ class DefinitionParser(object): elif self.skip_word_and_ws('double'): elements.append('double') if len(elements) > 0: - return ASTTrailingTypeSpecFundamental(u' '.join(elements)) + return ASTTrailingTypeSpecFundamental(' '.join(elements)) # decltype self.skip_ws() @@ -5277,7 +5394,7 @@ class DefinitionParser(object): return ASTTrailingTypeSpecName(prefix, nestedName) def _parse_parameters_and_qualifiers(self, paramMode): - # type: (unicode) -> ASTParametersQualifiers + # type: (str) -> ASTParametersQualifiers if paramMode == 'new': return None self.skip_ws() @@ -5362,14 +5479,14 @@ class DefinitionParser(object): if not initializer: self.fail( 'Expected "%s" in initializer-specifier.' - % u'" or "'.join(valid)) + % '" or "'.join(valid)) return ASTParametersQualifiers( args, volatile, const, refQual, exceptionSpec, override, final, initializer) def _parse_decl_specs_simple(self, outer, typed): - # type: (unicode, bool) -> ASTDeclSpecsSimple + # type: (str, bool) -> ASTDeclSpecsSimple """Just parse the simple ones.""" storage = None threadLocal = None @@ -5444,7 +5561,7 @@ class DefinitionParser(object): friend, attrs) def _parse_decl_specs(self, outer, typed=True): - # type: (unicode, bool) -> ASTDeclSpecs + # type: (str, bool) -> ASTDeclSpecs if outer: if outer not in ('type', 'member', 'function', 'templateParam'): raise Exception('Internal error, unknown outer "%s".' % outer) @@ -5472,7 +5589,7 @@ class DefinitionParser(object): return ASTDeclSpecs(outer, leftSpecs, rightSpecs, trailing) def _parse_declarator_name_param_qual(self, named, paramMode, typed): - # type: (Union[bool, unicode], unicode, bool) -> ASTDeclaratorNameParamQual + # type: (Union[bool, str], str, bool) -> ASTDeclaratorNameParamQual # now we should parse the name, and then suffixes if named == 'maybe': pos = self.pos @@ -5519,7 +5636,7 @@ class DefinitionParser(object): paramQual=paramQual) def _parse_declarator(self, named, paramMode, typed=True): - # type: (Union[bool, unicode], unicode, bool) -> Any + # type: (Union[bool, str], str, bool) -> Any # 'typed' here means 'parse return type stuff' if paramMode not in ('type', 'function', 'operatorCast', 'new'): raise Exception( @@ -5631,7 +5748,7 @@ class DefinitionParser(object): raise self._make_multi_error(prevErrors, header) def _parse_initializer(self, outer=None, allowFallback=True): - # type: (unicode, bool) -> ASTInitializer + # type: (str, bool) -> ASTInitializer self.skip_ws() # TODO: support paren and brace initialization for memberObject if not self.skip_string('='): @@ -5658,7 +5775,7 @@ class DefinitionParser(object): return ASTInitializer(value) def _parse_type(self, named, outer=None): - # type: (Union[bool, unicode], unicode) -> ASTType + # type: (Union[bool, str], str) -> ASTType """ named=False|'maybe'|True: 'maybe' is e.g., for function objects which doesn't need to name the arguments @@ -5741,7 +5858,7 @@ class DefinitionParser(object): return ASTType(declSpecs, decl) def _parse_type_with_init(self, named, outer): - # type: (Union[bool, unicode], unicode) -> Any + # type: (Union[bool, str], str) -> Any if outer: assert outer in ('type', 'member', 'function', 'templateParam') type = self._parse_type(outer=outer, named=named) @@ -5810,7 +5927,7 @@ class DefinitionParser(object): if self.skip_string(':'): while 1: self.skip_ws() - visibility = 'private' # type: unicode + visibility = 'private' virtual = False pack = False if self.skip_word_and_ws('virtual'): @@ -5838,7 +5955,7 @@ class DefinitionParser(object): def _parse_enum(self): # type: () -> ASTEnum - scoped = None # type: unicode # is set by CPPEnumObject + scoped = None # is set by CPPEnumObject self.skip_ws() name = self._parse_nested_name() self.skip_ws() @@ -5973,8 +6090,8 @@ class DefinitionParser(object): return ASTTemplateIntroduction(concept, params) def _parse_template_declaration_prefix(self, objectType): - # type: (unicode) -> ASTTemplateDeclarationPrefix - templates = [] # type: List + # type: (str) -> ASTTemplateDeclarationPrefix + templates = [] # type: List[str] while 1: self.skip_ws() # the saved position is only used to provide a better error message @@ -6029,11 +6146,11 @@ class DefinitionParser(object): msg = "Too many template argument lists compared to parameter" \ " lists. Argument lists: %d, Parameter lists: %d," \ " Extra empty parameters lists prepended: %d." \ - % (numArgs, numParams, numExtra) # type: unicode + % (numArgs, numParams, numExtra) msg += " Declaration:\n\t" if templatePrefix: - msg += "%s\n\t" % text_type(templatePrefix) - msg += text_type(nestedName) + msg += "%s\n\t" % templatePrefix + msg += str(nestedName) self.warn(msg) newTemplates = [] @@ -6045,7 +6162,7 @@ class DefinitionParser(object): return templatePrefix def parse_declaration(self, objectType): - # type: (unicode) -> ASTDeclaration + # type: (str) -> ASTDeclaration if objectType not in ('type', 'concept', 'member', 'function', 'class', 'union', 'enum', 'enumerator'): raise Exception('Internal error, unknown objectType "%s".' % objectType) @@ -6188,7 +6305,7 @@ class CPPObject(ObjectDescription): option_spec['tparam-line-spec'] = directives.flag def warn(self, msg): - # type: (unicode) -> None + # type: (Union[str, Exception]) -> None self.state_machine.reporter.warning(msg, line=self.lineno) def _add_enumerator_to_parent(self, ast): @@ -6234,7 +6351,7 @@ class CPPObject(ObjectDescription): docname=self.env.docname) def add_target_and_index(self, ast, sig, signode): - # type: (Any, unicode, addnodes.desc_signature) -> None + # type: (Any, str, addnodes.desc_signature) -> None # general note: name must be lstrip(':')'ed, to remove "::" ids = [] for i in range(1, _max_id + 1): @@ -6249,7 +6366,7 @@ class CPPObject(ObjectDescription): assert newestId # shouldn't be None if not re.compile(r'^[a-zA-Z0-9_]*$').match(newestId): self.warn('Index id generation for C++ object "%s" failed, please ' - 'report as bug (id=%s).' % (text_type(ast), newestId)) + 'report as bug (id=%s).' % (ast, newestId)) name = ast.symbol.get_full_nested_name().get_display_string().lstrip(':') # Add index entry, but not if it's a declaration inside a concept @@ -6293,6 +6410,10 @@ class CPPObject(ObjectDescription): signode['first'] = (not self.names) # hmm, what is this about? self.state.document.note_explicit_target(signode) + def get_index_text(self, name): + # type: (str) -> str + raise NotImplementedError() + def parse_definition(self, parser): # type: (Any) -> Any raise NotImplementedError() @@ -6323,15 +6444,15 @@ class CPPObject(ObjectDescription): parentDecl = parentSymbol.declaration if parentDecl is not None and parentDecl.objectType == 'function': self.warn("C++ declarations inside functions are not supported." + - " Parent function is " + text_type(parentSymbol.get_full_nested_name())) + " Parent function is " + str(parentSymbol.get_full_nested_name())) name = _make_phony_error_name() symbol = parentSymbol.add_name(name) env.temp_data['cpp:last_symbol'] = symbol return [] - return ObjectDescription.run(self) + return super().run() def handle_signature(self, sig, signode): - # type: (unicode, addnodes.desc_signature) -> Any + # type: (str, addnodes.desc_signature) -> Any parentSymbol = self.env.temp_data['cpp:parent_symbol'] parser = DefinitionParser(sig, self, self.env.config) @@ -6339,7 +6460,7 @@ class CPPObject(ObjectDescription): ast = self.parse_definition(parser) parser.assert_end() except DefinitionError as e: - self.warn(e.description) + self.warn(e) # It is easier to assume some phony name than handling the error in # the possibly inner declarations. name = _make_phony_error_name() @@ -6383,7 +6504,7 @@ class CPPObject(ObjectDescription): class CPPTypeObject(CPPObject): def get_index_text(self, name): - # type: (unicode) -> unicode + # type: (str) -> str return _('%s (C++ type)') % name def parse_definition(self, parser): @@ -6393,7 +6514,7 @@ class CPPTypeObject(CPPObject): class CPPConceptObject(CPPObject): def get_index_text(self, name): - # type: (unicode) -> unicode + # type: (str) -> str return _('%s (C++ concept)') % name def parse_definition(self, parser): @@ -6403,7 +6524,7 @@ class CPPConceptObject(CPPObject): class CPPMemberObject(CPPObject): def get_index_text(self, name): - # type: (unicode) -> unicode + # type: (str) -> str return _('%s (C++ member)') % name def parse_definition(self, parser): @@ -6413,7 +6534,7 @@ class CPPMemberObject(CPPObject): class CPPFunctionObject(CPPObject): def get_index_text(self, name): - # type: (unicode) -> unicode + # type: (str) -> str return _('%s (C++ function)') % name def parse_definition(self, parser): @@ -6423,7 +6544,7 @@ class CPPFunctionObject(CPPObject): class CPPClassObject(CPPObject): def get_index_text(self, name): - # type: (unicode) -> unicode + # type: (str) -> str return _('%s (C++ class)') % name def parse_definition(self, parser): @@ -6433,7 +6554,7 @@ class CPPClassObject(CPPObject): class CPPUnionObject(CPPObject): def get_index_text(self, name): - # type: (unicode) -> unicode + # type: (str) -> str return _('%s (C++ union)') % name def parse_definition(self, parser): @@ -6443,7 +6564,7 @@ class CPPUnionObject(CPPObject): class CPPEnumObject(CPPObject): def get_index_text(self, name): - # type: (unicode) -> unicode + # type: (str) -> str return _('%s (C++ enum)') % name def parse_definition(self, parser): @@ -6463,7 +6584,7 @@ class CPPEnumObject(CPPObject): class CPPEnumeratorObject(CPPObject): def get_index_text(self, name): - # type: (unicode) -> unicode + # type: (str) -> str return _('%s (C++ enumerator)') % name def parse_definition(self, parser): @@ -6484,7 +6605,7 @@ class CPPNamespaceObject(SphinxDirective): option_spec = {} # type: Dict def warn(self, msg): - # type: (unicode) -> None + # type: (Union[str, Exception]) -> None self.state_machine.reporter.warning(msg, line=self.lineno) def run(self): @@ -6499,7 +6620,7 @@ class CPPNamespaceObject(SphinxDirective): ast = parser.parse_namespace_object() parser.assert_end() except DefinitionError as e: - self.warn(e.description) + self.warn(e) name = _make_phony_error_name() ast = ASTNamespace(name, None) symbol = rootSymbol.add_name(ast.nestedName, ast.templatePrefix) @@ -6518,7 +6639,7 @@ class CPPNamespacePushObject(SphinxDirective): option_spec = {} # type: Dict def warn(self, msg): - # type: (unicode) -> None + # type: (Union[str, Exception]) -> None self.state_machine.reporter.warning(msg, line=self.lineno) def run(self): @@ -6530,7 +6651,7 @@ class CPPNamespacePushObject(SphinxDirective): ast = parser.parse_namespace_object() parser.assert_end() except DefinitionError as e: - self.warn(e.description) + self.warn(e) name = _make_phony_error_name() ast = ASTNamespace(name, None) oldParent = self.env.temp_data.get('cpp:parent_symbol', None) @@ -6553,7 +6674,7 @@ class CPPNamespacePopObject(SphinxDirective): option_spec = {} # type: Dict def warn(self, msg): - # type: (unicode) -> None + # type: (Union[str, Exception]) -> None self.state_machine.reporter.warning(msg, line=self.lineno) def run(self): @@ -6576,7 +6697,7 @@ class CPPNamespacePopObject(SphinxDirective): class CPPXRefRole(XRefRole): def process_link(self, env, refnode, has_explicit_title, title, target): - # type: (BuildEnvironment, nodes.Node, bool, unicode, unicode) -> Tuple[unicode, unicode] # NOQA + # type: (BuildEnvironment, nodes.Element, bool, str, str) -> Tuple[str, str] refnode.attributes.update(env.ref_context) if not has_explicit_title: @@ -6604,7 +6725,7 @@ class CPPXRefRole(XRefRole): return title, target -class CPPExprRole(object): +class CPPExprRole: def __init__(self, asCode): if asCode: # render the expression as inline code @@ -6616,7 +6737,7 @@ class CPPExprRole(object): self.node_type = nodes.inline def __call__(self, typ, rawtext, text, lineno, inliner, options={}, content=[]): - class Warner(object): + class Warner: def warn(self, msg): inliner.reporter.warning(msg, line=lineno) text = utils.unescape(text).replace('\n', ' ') @@ -6627,8 +6748,7 @@ class CPPExprRole(object): try: ast = parser.parse_expression() except DefinitionError as ex: - Warner().warn('Unparseable C++ expression: %r\n%s' - % (text, text_type(ex.description))) + Warner().warn('Unparseable C++ expression: %r\n%s' % (text, ex)) # see below return [self.node_type(text, text, classes=classes)], [] parentSymbol = env.temp_data.get('cpp:parent_symbol', None) @@ -6692,7 +6812,7 @@ class CPPDomain(Domain): } def clear_doc(self, docname): - # type: (unicode) -> None + # type: (str) -> None if Symbol.debug_show_tree: print("clear_doc:", docname) print("\tbefore:") @@ -6712,18 +6832,18 @@ class CPPDomain(Domain): del self.data['names'][name] def process_doc(self, env, docname, document): - # type: (BuildEnvironment, unicode, nodes.Node) -> None + # type: (BuildEnvironment, str, nodes.document) -> None if Symbol.debug_show_tree: print("process_doc:", docname) print(self.data['root_symbol'].dump(0)) print("process_doc end:", docname) def process_field_xref(self, pnode): - # type: (nodes.Node) -> None + # type: (addnodes.pending_xref) -> None pnode.attributes.update(self.env.ref_context) def merge_domaindata(self, docnames, otherdata): - # type: (List[unicode], Dict) -> None + # type: (List[str], Dict) -> None if Symbol.debug_show_tree: print("merge_domaindata:") print("\tself:") @@ -6749,9 +6869,8 @@ class CPPDomain(Domain): def _resolve_xref_inner(self, env, fromdocname, builder, typ, target, node, contnode, emitWarnings=True): - # type: (BuildEnvironment, unicode, Builder, unicode, unicode, nodes.Node, nodes.Node, bool) -> nodes.Node # NOQA - - class Warner(object): + # type: (BuildEnvironment, str, Builder, str, str, addnodes.pending_xref, nodes.Element, bool) -> Tuple[nodes.Element, str] # NOQA + class Warner: def warn(self, msg): if emitWarnings: logger.warning(msg, location=node) @@ -6777,8 +6896,7 @@ class CPPDomain(Domain): # strange, that we don't get the error now, use the original return target, e t, ex = findWarning(e) - warner.warn('Unparseable C++ cross-reference: %r\n%s' - % (t, text_type(ex.description))) + warner.warn('Unparseable C++ cross-reference: %r\n%s' % (t, ex)) return None, None parentKey = node.get("cpp:parent_key", None) rootSymbol = self.data['root_symbol'] @@ -6809,7 +6927,7 @@ class CPPDomain(Domain): templateShorthand=True, matchSelf=True, recurseInAnon=True) if s is None or s.declaration is None: - txtName = text_type(name) + txtName = str(name) if txtName.startswith('std::') or txtName == 'std': raise NoUri() return None, None @@ -6847,7 +6965,7 @@ class CPPDomain(Domain): # the non-identifier refs are cross-references, which should be processed: # - fix parenthesis due to operator() and add_function_parentheses if typ != "identifier": - title = contnode.pop(0).astext() + title = contnode.pop(0).astext() # type: ignore # If it's operator(), we need to add '()' if explicit function parens # are requested. Then the Sphinx machinery will add another pair. # Also, if it's an 'any' ref that resolves to a function, we need to add @@ -6887,34 +7005,32 @@ class CPPDomain(Domain): declaration.get_newest_id(), contnode, displayName ), declaration.objectType - def resolve_xref(self, env, fromdocname, builder, - typ, target, node, contnode): - # type: (BuildEnvironment, unicode, Builder, unicode, unicode, nodes.Node, nodes.Node) -> nodes.Node # NOQA + def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode): + # type: (BuildEnvironment, str, Builder, str, str, addnodes.pending_xref, nodes.Element) -> nodes.Element # NOQA return self._resolve_xref_inner(env, fromdocname, builder, typ, target, node, contnode)[0] - def resolve_any_xref(self, env, fromdocname, builder, target, - node, contnode): - # type: (BuildEnvironment, unicode, Builder, unicode, nodes.Node, nodes.Node) -> List[Tuple[unicode, nodes.Node]] # NOQA - node, objtype = self._resolve_xref_inner(env, fromdocname, builder, - 'any', target, node, contnode, - emitWarnings=False) - if node: + def resolve_any_xref(self, env, fromdocname, builder, target, node, contnode): + # type: (BuildEnvironment, str, Builder, str, addnodes.pending_xref, nodes.Element) -> List[Tuple[str, nodes.Element]] # NOQA + retnode, objtype = self._resolve_xref_inner(env, fromdocname, builder, + 'any', target, node, contnode, + emitWarnings=False) + if retnode: if objtype == 'templateParam': - return [('cpp:templateParam', node)] + return [('cpp:templateParam', retnode)] else: - return [('cpp:' + self.role_for_objtype(objtype), node)] + return [('cpp:' + self.role_for_objtype(objtype), retnode)] return [] def get_objects(self): - # type: () -> Iterator[Tuple[unicode, unicode, unicode, unicode, unicode, int]] + # type: () -> Iterator[Tuple[str, str, str, str, str, int]] rootSymbol = self.data['root_symbol'] for symbol in rootSymbol.get_all_symbols(): if symbol.declaration is None: continue assert symbol.docname fullNestedName = symbol.get_full_nested_name() - name = text_type(fullNestedName).lstrip(':') + name = str(fullNestedName).lstrip(':') dispname = fullNestedName.get_display_string().lstrip(':') objectType = symbol.declaration.objectType docname = symbol.docname @@ -6922,7 +7038,7 @@ class CPPDomain(Domain): yield (name, dispname, objectType, docname, newestId, 1) def get_full_qualified_name(self, node): - # type: (nodes.Node) -> unicode + # type: (nodes.Element) -> str target = node.get('reftarget', None) if target is None: return None @@ -6933,11 +7049,11 @@ class CPPDomain(Domain): rootSymbol = self.data['root_symbol'] parentSymbol = rootSymbol.direct_lookup(parentKey) parentName = parentSymbol.get_full_nested_name() - return '::'.join([text_type(parentName), target]) + return '::'.join([str(parentName), target]) def setup(app): - # type: (Sphinx) -> Dict[unicode, Any] + # type: (Sphinx) -> Dict[str, Any] app.add_domain(CPPDomain) app.add_config_value("cpp_index_common_prefix", [], 'env') app.add_config_value("cpp_id_attributes", [], 'env') |