domains/cpp: pep8 fixes

This commit is contained in:
Georg Brandl 2015-03-08 16:04:54 +01:00
parent 7b9f03e383
commit 3bd21b96e6

View File

@ -9,6 +9,23 @@
:license: BSD, see LICENSE for details.
"""
import re
from copy import deepcopy
from six import iteritems, text_type
from docutils import nodes
from sphinx import addnodes
from sphinx.roles import XRefRole
from sphinx.locale import l_, _
from sphinx.domains import Domain, ObjType
from sphinx.directives import ObjectDescription
from sphinx.util.nodes import make_refnode
from sphinx.util.compat import Directive
from sphinx.util.pycompat import UnicodeMixin
from sphinx.util.docfields import Field, GroupedField
"""
Important note on ids:
Multiple id generation schemes are used due to backwards compatibility.
@ -191,23 +208,6 @@
nested-name
"""
import re
from copy import deepcopy
from six import iteritems, text_type
from docutils import nodes
from sphinx import addnodes
from sphinx.roles import XRefRole
from sphinx.locale import l_, _
from sphinx.domains import Domain, ObjType
from sphinx.directives import ObjectDescription
from sphinx.util.nodes import make_refnode
from sphinx.util.compat import Directive
from sphinx.util.pycompat import UnicodeMixin
from sphinx.util.docfields import Field, GroupedField
_identifier_re = re.compile(r'(~?\b[a-zA-Z_][a-zA-Z0-9_]*)\b')
_whitespace_re = re.compile(r'\s+(?u)')
_string_re = re.compile(r"[LuU8]?('([^'\\]*(?:\\.[^'\\]*)*)'"
@ -238,9 +238,9 @@ _keywords = [
'while', 'xor', 'xor_eq'
]
#-------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Id v1 constants
#-------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
_id_fundamental_v1 = {
'char': 'c',
@ -312,9 +312,9 @@ _id_operator_v1 = {
'[]': 'subscript-operator'
}
#-------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Id v2 constants
#-------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
_id_prefix_v2 = '_CPPv2'
_id_fundamental_v2 = {
@ -1333,8 +1333,8 @@ class ASTDeclaratorParen(ASTBase):
def get_ptr_suffix_id_v1(self):
raise NoOldIdError() # TODO: was this implemented before?
return self.next.get_ptr_suffix_id_v2() \
+ self.inner.get_ptr_suffix_id_v2()
return self.next.get_ptr_suffix_id_v2() + \
self.inner.get_ptr_suffix_id_v2()
# Id v2 ------------------------------------------------------------------
@ -1345,8 +1345,8 @@ class ASTDeclaratorParen(ASTBase):
return self.inner.get_param_id_v2()
def get_ptr_suffix_id_v2(self):
return self.inner.get_ptr_suffix_id_v2() \
+ self.next.get_ptr_suffix_id_v2()
return self.inner.get_ptr_suffix_id_v2() + \
self.next.get_ptr_suffix_id_v2()
def get_type_id_v2(self, returnTypeId):
# ReturnType (inner)next, so 'inner' returns everything outside
@ -1434,7 +1434,7 @@ class ASTDecleratorNameParamQual(ASTBase):
return self.declId is not None
def is_function_type(self):
return self.paramQual != None
return self.paramQual is not None
def __unicode__(self):
res = []
@ -1490,9 +1490,9 @@ class ASTType(ASTBase):
res.append(self.name.get_id_v1())
res.append(self.decl.get_param_id_v1())
res.append(self.decl.get_modifiers_id_v1())
if (self.declSpecs.leftSpecs.constexpr
or (self.declSpecs.rightSpecs
and self.declSpecs.rightSpecs.constexpr)):
if (self.declSpecs.leftSpecs.constexpr or
(self.declSpecs.rightSpecs and
self.declSpecs.rightSpecs.constexpr)):
res.append('CE')
elif self.objectType == 'type': # just the name
res.append(self.name.get_id_v1())
@ -1886,11 +1886,11 @@ class DefinitionParser(object):
try:
type = self._parse_type(named=False)
templateArgs.append(type)
except DefinitionError as exType:
except DefinitionError:
self.pos = pos
try:
value = self._parse_expression(end=[',', '>'])
except DefinitionError as exConstant:
except DefinitionError:
assert False # TODO: make nice error
templateArgs.append(ASTTemplateArgConstant(value))
self.skip_ws()
@ -2112,7 +2112,7 @@ class DefinitionParser(object):
"constexpr" (only for member_object and function_object)
"""
visibility = None
leftSepcs = None
leftSpecs = None
rightSpecs = None
if outer:
self.skip_ws()
@ -2442,7 +2442,7 @@ class CPPObject(ObjectDescription):
signode['ids'].append(id)
signode['first'] = (not self.names)
self.state.document.note_explicit_target(signode)
if not name in objects:
if name not in objects:
objects.setdefault(name, (self.env.docname, ast))
if ast.objectType == 'enumerator':
# find the parent, if it exists && is an enum
@ -2459,7 +2459,7 @@ class CPPObject(ObjectDescription):
enumScope = ASTNestedName(parentAst.prefixedName.names[:-1])
unscopedName = enumeratorName.prefix_nested_name(enumScope)
txtUnscopedName = text_type(unscopedName).lstrip(':')
if not txtUnscopedName in objects:
if txtUnscopedName not in objects:
objects.setdefault(txtUnscopedName,
(self.env.docname, ast))
# add the uninstantiated template if it doesn't exist