Skip to content

Commit f2a57f7

Browse files
committed
Format
1 parent b15dae7 commit f2a57f7

File tree

5 files changed

+24
-37
lines changed

5 files changed

+24
-37
lines changed

cpp/ast.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ def __init__(self, start, end, name, templated_types, modifiers,
350350
templated_types: [Class (Type?)] template type info between <>
351351
modifiers: [str] type modifiers (keywords) eg, const, mutable, etc.
352352
reference, pointer, array: bools
353-
354353
"""
355354
_GenericDeclaration.__init__(self, start, end, name, [])
356355
self.templated_types = templated_types
@@ -414,7 +413,6 @@ def to_type(self, tokens):
414413
415414
Returns:
416415
[Class(...), ...]
417-
418416
"""
419417
result = []
420418
name_tokens = []
@@ -833,12 +831,12 @@ def _get_var_tokens_up_to_w_function(self, skip_bracket_content,
833831
names = [token.name for token in tokens]
834832
ctr = collections.Counter(names)
835833
if ('(' in expected_tokens and
836-
ctr['<'] != ctr['>'] and
837-
ctr['function'] == 1 and
838-
last.name == '('):
834+
ctr['<'] != ctr['>'] and
835+
ctr['function'] == 1 and
836+
last.name == '('):
839837

840-
idx = names.index("function")
841-
if idx + 1 < len(tokens) and tokens[idx + 1].name == "<":
838+
idx = names.index('function')
839+
if idx + 1 < len(tokens) and tokens[idx + 1].name == '<':
842840
new_tokens, new_last = \
843841
self._get_var_tokens_up_to(False, '(', ';')
844842
tokens.append(last)
@@ -1096,10 +1094,10 @@ def _get_method(self, return_type_and_name, modifiers, templated_types,
10961094
member = member[0]
10971095
if token.name == '(' or token.name == '{':
10981096
end = '}' if token.name == '{' else ')'
1099-
initializers[member] = [x
1100-
for x in list(self._get_matching_char(
1101-
token.name, end))
1102-
if x.name != ',' and x.name != end]
1097+
initializers[member] = [
1098+
x for x in list(self._get_matching_char(token.name,
1099+
end))
1100+
if x.name != ',' and x.name != end]
11031101
token = self._get_next_token()
11041102

11051103
# Handle pointer to functions.
@@ -1448,7 +1446,7 @@ def handle_template(self):
14481446
elif token.name == 'template':
14491447
return self.handle_template()
14501448
self._add_back_token(token)
1451-
tokens, last = self._get_var_tokens_up_to_w_function(False, "(", ";")
1449+
tokens, last = self._get_var_tokens_up_to_w_function(False, '(', ';')
14521450
tokens.append(last)
14531451
self._add_back_tokens(tokens)
14541452
if last.name == '(':
@@ -1625,7 +1623,7 @@ def handle_using(self):
16251623
tokens = self._get_tokens_up_to(';')
16261624
assert tokens
16271625
new_type = self.converter.to_type(tokens)
1628-
if "namespace" in new_type[0].modifiers:
1626+
if 'namespace' in new_type[0].modifiers:
16291627
return Using(tokens[0].start, tokens[0].end, tokens)
16301628
else:
16311629
# aside from namespaces, "using" can be used just like a typedef
@@ -1659,7 +1657,6 @@ def builder_from_source(source, filename, system_includes,
16591657
16601658
Returns:
16611659
ASTBuilder
1662-
16631660
"""
16641661
return ASTBuilder(tokenize.get_tokens(source),
16651662
filename,

cpp/find_warnings.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
warnings will always be displayed. There is no way to suppress any.
2121
There also needs to be a way to use annotations in the source code to
2222
suppress warnings.
23-
2423
"""
2524

2625
from __future__ import absolute_import
@@ -303,13 +302,13 @@ def _add_use(node, namespace, name=''):
303302
# Try to search for the value of the variable declaration for any
304303
# symbols, such as `#define` values or other variable names which
305304
# may be included in other files.
306-
obj = getattr(node, "initial_value", None)
305+
obj = getattr(node, 'initial_value', None)
307306
if obj:
308307
_do_lookup(obj, namespace)
309308

310309
# If node is a VariableDeclaration, check if the variable type is
311310
# a symbol used in other includes.
312-
obj = getattr(node, "type", None)
311+
obj = getattr(node, 'type', None)
313312
if obj and isinstance(obj.name, basestring):
314313
_do_lookup(obj.name, namespace)
315314

@@ -319,7 +318,8 @@ def _add_use(node, namespace, name=''):
319318
return
320319

321320
def _add_variable(node, namespace, reference=False):
322-
obj = node.type if isinstance(node, ast.VariableDeclaration) else node
321+
obj = node.type if isinstance(
322+
node, ast.VariableDeclaration) else node
323323

324324
if obj.reference or obj.pointer or reference:
325325
_add_reference(obj.name, namespace)
@@ -397,7 +397,7 @@ def _add_template_use(name, types, namespace, reference=False):
397397
# These are things like auto_ptr which do
398398
# not require the class definition, only decl.
399399
_add_reference(cls.name, namespace)
400-
elif name.startswith('Q') and name.endswith("Pointer"):
400+
elif name.startswith('Q') and name.endswith('Pointer'):
401401
# Special case templated classes from the Qt framework.
402402
_add_reference(cls.name, namespace)
403403
else:

cpp/symbols.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def _lookup_namespace(self, symbol, namespace):
5252
Args:
5353
symbol: Symbol
5454
namespace: pointer into self.namespaces
55-
5655
"""
5756
for namespace_part in symbol.parts:
5857
namespace = namespace.get(namespace_part)
@@ -67,7 +66,6 @@ def _lookup_global(self, symbol):
6766
6867
Args:
6968
symbol: Symbol
70-
7169
"""
7270
assert symbol.parts
7371
namespace = self.namespaces
@@ -91,7 +89,6 @@ def _lookup_in_all_namespaces(self, symbol):
9189
9290
Args:
9391
symbol: Symbol
94-
9592
"""
9693
namespace = self.namespaces
9794
# Create a stack of namespaces.
@@ -123,7 +120,6 @@ def lookup_symbol(self, name, namespace_stack):
123120
124121
Raises:
125122
Error if the symbol cannot be found.
126-
127123
"""
128124
# TODO(nnorwitz): a convenient API for this depends on the
129125
# representation of the name. e.g., does symbol_name contain
@@ -148,7 +144,6 @@ def _add(self, symbol_name, namespace, node, module):
148144
"""Helper function for adding symbols.
149145
150146
See add_symbol().
151-
152147
"""
153148
result = symbol_name in namespace
154149
namespace[symbol_name] = node, module
@@ -165,7 +160,6 @@ def add_symbol(self, symbol_name, namespace_stack, node, module):
165160
166161
Returns:
167162
bool(if symbol was *not* already present)
168-
169163
"""
170164
# TODO(nnorwitz): verify symbol_name doesn't contain :: ?
171165
if namespace_stack:
@@ -185,7 +179,6 @@ def get_namespace(self, name_seq):
185179
186180
Returns:
187181
['names', 'that', 'are', 'namespaces', 'possibly', 'empty', 'list']
188-
189182
"""
190183
namespaces = self.namespaces
191184
result = []

cpp/tokenize.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
_letters = 'abcdefghijklmnopqrstuvwxyz'
2828
_valid_identifier_first_char = _letters + _letters.upper() + '_$'
2929
_valid_identifier_char = _valid_identifier_first_char + '0123456789'
30-
VALID_IDENTIFIER_FIRST_CHARS = frozenset( _valid_identifier_first_char )
30+
VALID_IDENTIFIER_FIRST_CHARS = frozenset(_valid_identifier_first_char)
3131
VALID_IDENTIFIER_CHARS = frozenset(_valid_identifier_char)
3232
HEX_DIGITS = frozenset('0123456789abcdefABCDEF')
3333
INT_OR_FLOAT_DIGITS = frozenset('01234567890eE-+')
@@ -59,7 +59,6 @@ class Token(object):
5959
6060
start contains the index of the first char of the token in the source
6161
end contains the index of the last char of the token in the source
62-
6362
"""
6463

6564
def __init__(self, token_type, name, start, end):
@@ -110,7 +109,6 @@ def get_tokens(source):
110109
111110
Yields:
112111
Token that represents the next token in the source.
113-
114112
"""
115113
if not source.endswith('\n'):
116114
source += '\n'
@@ -137,7 +135,8 @@ def get_tokens(source):
137135
token_type = UNKNOWN
138136
start = i
139137
c = source[i]
140-
if c in valid_identifier_first_chars or c == '_': # Find a string token.
138+
# Find a string token.
139+
if c in valid_identifier_first_chars or c == '_':
141140
token_type = NAME
142141
while source[i] in valid_identifier_chars:
143142
i += 1
@@ -291,7 +290,6 @@ def _find(string, sub_string, start_index):
291290
"""Return index of sub_string in string.
292291
293292
Raise TokenError if sub_string is not found.
294-
295293
"""
296294
result = string.find(sub_string, start_index)
297295
if result == -1:

test_ast.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def _install_generic_equal(cls, attrs):
3535
Args:
3636
cls: Python class to add __eq__ method to
3737
attrs: string - space separated of attribute names to compare
38-
3938
"""
4039
attrs = attrs.split()
4140

@@ -610,7 +609,6 @@ class ASTBuilderIntegrationTest(unittest.TestCase):
610609
an integration test.
611610
612611
It doesn't test any individual method. It tests whole code blocks.
613-
614612
"""
615613

616614
def test_variable_array(self):
@@ -993,7 +991,8 @@ class Foo {
993991
arg2 = nodes[0].body[2]
994992
arg3 = nodes[0].body[3]
995993

996-
exp_ctor = Function('Foo', [], [], modifiers=ast.FUNCTION_CTOR, body=[])
994+
exp_ctor = Function(
995+
'Foo', [], [], modifiers=ast.FUNCTION_CTOR, body=[])
997996
exp_var = [VariableDeclaration('arg1', Type('int'), initial_value='1'),
998997
VariableDeclaration('arg2', Type('int'), initial_value='2'),
999998
VariableDeclaration('arg3', Type('int'), initial_value='3')]
@@ -1024,7 +1023,8 @@ class Foo {
10241023
arg2 = nodes[0].body[2]
10251024
arg3 = nodes[0].body[3]
10261025

1027-
exp_ctor = Function('Foo', [], [], modifiers=ast.FUNCTION_CTOR, body=[])
1026+
exp_ctor = Function(
1027+
'Foo', [], [], modifiers=ast.FUNCTION_CTOR, body=[])
10281028
exp_var = [VariableDeclaration('arg1', Type('int'), initial_value='1'),
10291029
VariableDeclaration('arg2', Type('int'), initial_value='2'),
10301030
VariableDeclaration('arg3', Type('int'), initial_value='3')]
@@ -1125,7 +1125,7 @@ def test_system_include(self):
11251125

11261126
def test_include_path_overrides(self):
11271127
paths = [os.path.dirname(os.path.realpath(__file__))]
1128-
fname = "test/include.h"
1128+
fname = 'test/include.h'
11291129

11301130
def _tokens():
11311131
tokens_quotes = get_tokens('#include "test/include.h"')
@@ -1235,6 +1235,5 @@ def test_inline_function(self):
12351235
nodes[0])
12361236

12371237

1238-
12391238
if __name__ == '__main__':
12401239
unittest.main()

0 commit comments

Comments
 (0)