From 0fb8a303b1aa2e36736911626351d0410c9e8ea6 Mon Sep 17 00:00:00 2001 From: Ruslan Kamaldinov Date: Thu, 3 Jul 2014 18:09:29 +0400 Subject: [PATCH] Fixed pep8 checks: E203,E226,E302,E303 * E203 whitespace before ':' * E226 missing whitespace around arithmetic operator * E302 expected 2 blank lines * E303 too many blank lines --- tox.ini | 7 +------ yaql/cli/run.py | 2 +- yaql/functions/arithmetic.py | 2 ++ yaql/functions/boolean.py | 2 ++ yaql/functions/containers.py | 2 +- yaql/functions/ns.py | 1 + yaql/functions/strings.py | 2 ++ yaql/functions/system.py | 1 + yaql/language/lexer.py | 31 ++++++++++++++--------------- yaql/language/parser.py | 1 - yaql/tests/test_execution_chains.py | 4 +--- yaql/tests/test_tuples.py | 1 - 12 files changed, 27 insertions(+), 29 deletions(-) diff --git a/tox.ini b/tox.ini index 63fc5d4..4ff077b 100644 --- a/tox.ini +++ b/tox.ini @@ -29,11 +29,6 @@ commands = python setup.py build_sphinx # E123, E125 skipped as they are invalid PEP-8. # H404 multi line docstring should start with a summary ## TODO(ruhe) following checks should be fixed -# E125 continuation line does not distinguish itself from next logical line -# E203 whitespace before ':' -# E226 missing whitespace around arithmetic operator -# E302 expected 2 blank lines -# E303 too many blank lines # E501 line too long # E721 do not compare types, use 'isinstance()' # F401 something imported but unused @@ -46,6 +41,6 @@ commands = python setup.py build_sphinx # W292 no newline at end of file # W391 blank line at end of file show-source = True -ignore = E123,E125,E203,E226,E302,E303,E501,E721,F401,F403,F841,H201,H202,H306,H404,H803,H902,W292,W391 +ignore = E123,E125,E501,E721,F401,F403,F841,H201,H202,H306,H404,H803,H902,W292,W391 builtins = _ exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build diff --git a/yaql/cli/run.py b/yaql/cli/run.py index 39dc06f..c5a894b 100755 --- a/yaql/cli/run.py +++ b/yaql/cli/run.py @@ -32,7 +32,7 @@ def main(): decoder = JSONDecoder() data = decoder.decode(json_str) except: - print "Unable to load data from "+options.data + print "Unable to load data from " + options.data return else: data = None diff --git a/yaql/functions/arithmetic.py b/yaql/functions/arithmetic.py index 335dc82..a007bcb 100644 --- a/yaql/functions/arithmetic.py +++ b/yaql/functions/arithmetic.py @@ -19,6 +19,7 @@ from yaql.language.exceptions import YaqlExecutionException def _is_a_number(value): return isinstance(value, (int, long, float, complex)) + @parameter('value', custom_validator=_is_a_number) def unary_minus(value): return -1 * value @@ -34,6 +35,7 @@ def unary_plus(value): def plus(a, b): return a + b + @parameter('a', custom_validator=_is_a_number) @parameter('b', custom_validator=_is_a_number) def minus(a, b): diff --git a/yaql/functions/boolean.py b/yaql/functions/boolean.py index c2e14ec..94338cc 100644 --- a/yaql/functions/boolean.py +++ b/yaql/functions/boolean.py @@ -21,11 +21,13 @@ from yaql.language.exceptions import YaqlExecutionException def _and(a, b): return a and b + @parameter('a', arg_type=types.BooleanType) @parameter('b', arg_type=types.BooleanType) def _or(a, b): return a or b + @parameter('data', arg_type=types.BooleanType) def _not(data): return not data diff --git a/yaql/functions/containers.py b/yaql/functions/containers.py index fd9aad4..7e43986 100644 --- a/yaql/functions/containers.py +++ b/yaql/functions/containers.py @@ -151,6 +151,7 @@ def take_while(self, predicate): else: return + @parameter('self', arg_type=types.GeneratorType) def _list(self): return limit(self) @@ -180,4 +181,3 @@ def add_to_context(context): context.register_function(take_while) context.register_function(_list, 'list') context.register_function(for_each) - diff --git a/yaql/functions/ns.py b/yaql/functions/ns.py index 4d1b136..974dd38 100644 --- a/yaql/functions/ns.py +++ b/yaql/functions/ns.py @@ -59,6 +59,7 @@ def resolve_prop(alias, symbol, context): namespace.validate(symbol) return namespace.name + '.' + symbol + @context_aware @parameter('symbol', function_only=True, lazy=True) def resolve_function(self, alias, symbol, context): diff --git a/yaql/functions/strings.py b/yaql/functions/strings.py index 9bfa781..0a6a29f 100644 --- a/yaql/functions/strings.py +++ b/yaql/functions/strings.py @@ -21,6 +21,7 @@ from yaql.language.engine import parameter def string_concatenation(a, b): return a + b + @parameter('self', arg_type=types.StringTypes, is_self=True) def as_list(self): return list(self) @@ -29,6 +30,7 @@ def as_list(self): def to_string(self): return str(self) + def _to_string_func(data): return to_string(data) diff --git a/yaql/functions/system.py b/yaql/functions/system.py index a6daea6..7c23996 100644 --- a/yaql/functions/system.py +++ b/yaql/functions/system.py @@ -54,6 +54,7 @@ def dict_attribution(self, att_name): def method_call(self, method): return method(sender=self) + @context_aware @parameter('tuple_preds', lazy=True) def _as(self, context, *tuple_preds): diff --git a/yaql/language/lexer.py b/yaql/language/lexer.py index 2183d25..9c30346 100644 --- a/yaql/language/lexer.py +++ b/yaql/language/lexer.py @@ -39,19 +39,19 @@ unary_prefix = { op_to_level = { 'abc': 0, - '|' : 1, - '^' : 2, - '&' : 3, - '<' : 4, - '>' : 4, - '=' : 5, - '!' : 5, - '+' : 6, - '-' : 6, - '*' : 7, - '/' : 7, - '%' : 7, - '.' : 8 + '|': 1, + '^': 2, + '&': 3, + '<': 4, + '>': 4, + '=': 5, + '!': 5, + '+': 6, + '-': 6, + '*': 7, + '/': 7, + '%': 7, + '.': 8 } ops = { @@ -86,7 +86,7 @@ tokens = [ 'FILTER', 'NOT', 'DOLLAR' -] + list(keywords.values())+list(ops.values()) + list(unary_prefix.values()) +] + list(keywords.values()) + list(ops.values()) + list(unary_prefix.values()) literals = "()]," @@ -162,12 +162,11 @@ def t_CHAR_ORB(t): return t - def get_orb_op_type(first_char, last_char): if first_char.isalpha() or first_char == '_': level = op_to_level['abc'] else: - level = op_to_level.get(first_char, max(op_to_level.values())+1) + level = op_to_level.get(first_char, max(op_to_level.values()) + 1) asc = 'r' if last_char in right_associative else 'l' return ops.get((level, asc)) diff --git a/yaql/language/parser.py b/yaql/language/parser.py index 09bf679..82374d9 100644 --- a/yaql/language/parser.py +++ b/yaql/language/parser.py @@ -140,7 +140,6 @@ def p_binary(p): p[0] = expressions.BinaryOperator(p[2], p[1], p[3]) - def p_unary_prefix(p): """ value : UNARY_TILDE value diff --git a/yaql/tests/test_execution_chains.py b/yaql/tests/test_execution_chains.py index bf90b89..5616087 100644 --- a/yaql/tests/test_execution_chains.py +++ b/yaql/tests/test_execution_chains.py @@ -50,6 +50,7 @@ def override_with_caps(self, context): def _print(self): return "data is: %s" % self + @parameter('self', arg_type=types.StringType) def print_string(self): return "print %s" % self @@ -63,7 +64,6 @@ class TestExecutionChain(YaqlTest): self.context.register_function(_print, 'print') self.context.register_function(override_with_caps, 'caps_on') - def test_chain1(self): expression = 'f1(abc).f2().f3()' self.assertEquals('f3(f2(f1(abc)))', self.eval(expression)) @@ -103,7 +103,5 @@ class TestExecutionChain(YaqlTest): self.assertRaises(YaqlExecutionException, self.eval, wrong_expression) - - if __name__ == '__main__': unittest.main() diff --git a/yaql/tests/test_tuples.py b/yaql/tests/test_tuples.py index b7968d6..2eba222 100644 --- a/yaql/tests/test_tuples.py +++ b/yaql/tests/test_tuples.py @@ -54,6 +54,5 @@ class TestTuples(YaqlTest): self.assertEquals((5, 'a'), self.eval(expression2)) - if __name__ == '__main__': unittest.main()