summaryrefslogtreecommitdiff
path: root/sphinx/domains/cpp.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2018-12-15 20:13:28 -0800
committerJon Dufresne <jon.dufresne@gmail.com>2018-12-18 16:23:10 -0800
commit6978918ffc14b0b096285adfa0c90f95de281efa (patch)
treea7ba01358ee56c41853c488dc5808818f08e79c6 /sphinx/domains/cpp.py
parent4405366e223246045fb2ca465a8a3ebac1feb0e8 (diff)
downloadsphinx-git-6978918ffc14b0b096285adfa0c90f95de281efa.tar.gz
Replace use of six.text_type with str
This removes the last use of the six package allowing Sphinx to remove it as a dependency.
Diffstat (limited to 'sphinx/domains/cpp.py')
-rw-r--r--sphinx/domains/cpp.py97
1 files changed, 47 insertions, 50 deletions
diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py
index 1550154d3..b8a7da02f 100644
--- a/sphinx/domains/cpp.py
+++ b/sphinx/domains/cpp.py
@@ -13,7 +13,6 @@ from copy import deepcopy
from docutils import nodes, utils
from docutils.parsers.rst import directives
-from six import text_type
from sphinx import addnodes
from sphinx.directives import ObjectDescription
@@ -633,7 +632,7 @@ class ASTBase:
def __str__(self):
# type: () -> str
- return self._stringify(lambda ast: text_type(ast))
+ return self._stringify(lambda ast: str(ast))
def get_display_string(self):
# type: () -> str
@@ -664,7 +663,7 @@ 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))
@@ -703,7 +702,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))
@@ -737,7 +736,7 @@ class ASTParenAttribute(ASTBase):
def describe_signature(self, signode):
# type: (addnodes.desc_signature) -> None
- txt = text_type(self)
+ txt = str(self)
signode.append(nodes.Text(txt, txt))
@@ -777,7 +776,7 @@ class ASTBooleanLiteral(ASTBase):
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):
@@ -794,7 +793,7 @@ class ASTNumberLiteral(ASTBase):
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))
@@ -828,7 +827,7 @@ class ASTCharLiteral(ASTBase):
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))
@@ -847,7 +846,7 @@ class ASTStringLiteral(ASTBase):
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))
@@ -910,7 +909,7 @@ class ASTFoldExpr(ASTBase):
# type: (int) -> str
assert version >= 3
if version == 3:
- return text_type(self)
+ return str(self)
# TODO: find the right mangling scheme
assert False
@@ -1466,7 +1465,7 @@ class ASTFallbackExpr(ASTBase):
def get_id(self, version):
# type: (int) -> str
- return text_type(self.expr)
+ return str(self.expr)
def describe_signature(self, signode, mode, env, symbol):
signode += nodes.Text(self.expr)
@@ -1504,7 +1503,7 @@ class ASTIdentifier(ASTBase):
if self.is_anon():
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 __str__ and the display string
@@ -1987,7 +1986,7 @@ class ASTOperator(ASTBase):
def describe_signature(self, signode, mode, env, prefix, templateArgs, symbol):
# 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:
@@ -2036,7 +2035,7 @@ class ASTOperatorType(ASTOperator):
def get_name_no_template(self):
# type: () -> str
- return text_type(self)
+ return str(self)
class ASTOperatorLiteral(ASTOperator):
@@ -2071,9 +2070,9 @@ class ASTTemplateArgConstant(ASTBase):
def get_id(self, version):
# type: (int) -> str
if version == 1:
- return text_type(self).replace(' ', '-')
+ return str(self).replace(' ', '-')
if version == 2:
- return 'X' + text_type(self) + 'E'
+ return 'X' + str(self) + 'E'
return 'X' + self.value.get_id(version) + 'E'
def describe_signature(self, signode, mode, env, symbol):
@@ -2148,7 +2147,7 @@ class ASTNestedNameElement(ASTBase):
def describe_signature(self, signode, mode, env, prefix, symbol):
# type: (addnodes.desc_signature, str, BuildEnvironment, str, Symbol) -> None
- tArgs = text_type(self.templateArgs) if self.templateArgs is not None else ''
+ 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)
@@ -2181,7 +2180,7 @@ class ASTNestedName(ASTBase):
def get_id(self, version, modifiers=''):
# 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:
@@ -2216,9 +2215,9 @@ class ASTNestedName(ASTBase):
_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
@@ -2251,10 +2250,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)
@@ -2299,7 +2298,7 @@ class ASTTrailingTypeSpecFundamental(ASTBase):
def describe_signature(self, signode, mode, env, symbol):
# type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
- signode += nodes.Text(text_type(self.name))
+ signode += nodes.Text(str(self.name))
class ASTTrailingTypeSpecName(ASTBase):
@@ -2347,7 +2346,7 @@ class ASTTrailingTypeSpecDecltypeAuto(ASTBase):
def describe_signature(self, signode, mode, env, symbol):
# type: (addnodes.desc_signature, str, BuildEnvironment, Symbol) -> None
- signode.append(nodes.Text(text_type(self)))
+ signode.append(nodes.Text(str(self)))
class ASTTrailingTypeSpecDecltype(ASTBase):
@@ -2460,7 +2459,7 @@ class ASTParametersQualifiers(ASTBase):
if not first:
res.append(', ')
first = False
- res.append(text_type(a))
+ res.append(str(a))
res.append(')')
if self.volatile:
res.append(' volatile')
@@ -2471,7 +2470,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:
@@ -2508,13 +2507,13 @@ 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):
@@ -2646,7 +2645,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(" ")
@@ -2697,7 +2696,7 @@ class ASTArray(ASTBase):
return 'A'
if version == 2:
if self.size:
- return 'A' + text_type(self.size) + '_'
+ return 'A' + str(self.size) + '_'
else:
return 'A_'
if self.size:
@@ -3314,7 +3313,7 @@ class ASTType(ASTBase):
_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'.
@@ -3922,8 +3921,8 @@ class Symbol:
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
@@ -3951,13 +3950,13 @@ class Symbol:
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):
@@ -4246,7 +4245,7 @@ class Symbol:
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)
@@ -4394,20 +4393,20 @@ class Symbol:
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)
@@ -6144,7 +6143,7 @@ class DefinitionParser:
msg += " Declaration:\n\t"
if templatePrefix:
msg += "%s\n\t" % templatePrefix
- msg += text_type(nestedName)
+ msg += str(nestedName)
self.warn(msg)
newTemplates = []
@@ -6438,7 +6437,7 @@ 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
@@ -6742,8 +6741,7 @@ class CPPExprRole:
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)
@@ -6891,8 +6889,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']
@@ -6923,7 +6920,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
@@ -7026,7 +7023,7 @@ class CPPDomain(Domain):
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
@@ -7045,7 +7042,7 @@ 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):