Mercurial > p > roundup > code
diff roundup/mlink_expr.py @ 6960:7b090bb35c25
flake8 fixes - exception handling changed
flake was flagging the bare except: expression. From testing, it
looks like that exception handler only gets ValueError. So changed it
to
except ValueError:
and added an
except BaseExpression
that just re-raises the exception. But I think this better expresses
the expected flow.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 12 Sep 2022 22:20:43 -0400 |
| parents | a0c0ee3ed8b1 |
| children | 87af08c75695 |
line wrap: on
line diff
--- a/roundup/mlink_expr.py Mon Sep 12 21:52:52 2022 -0400 +++ b/roundup/mlink_expr.py Mon Sep 12 22:20:43 2022 -0400 @@ -1,7 +1,7 @@ # # Copyright: 2010 Intevation GmbH. # 2021 Ralf Schlatterbeck, rsc@runtux.com. -# +# # This module is Free Software under the Roundup licensing, # see the COPYING.txt file coming with Roundup. @@ -17,6 +17,7 @@ self.x.visit(visitor) self.y.visit(visitor) + class Unary: def __init__(self, x): @@ -28,6 +29,7 @@ def visit(self, visitor): self.x.visit(visitor) + class Equals(Unary): def evaluate(self, v): @@ -36,6 +38,7 @@ def visit(self, visitor): visitor(self) + class Empty(Unary): def evaluate(self, v): @@ -44,6 +47,7 @@ def visit(self, visitor): visitor(self) + class Not(Unary): def evaluate(self, v): @@ -52,6 +56,7 @@ def generate(self, atom): return "NOT(%s)" % self.x.generate(atom) + class Or(Binary): def evaluate(self, v): @@ -62,6 +67,7 @@ self.x.generate(atom), self.y.generate(atom)) + class And(Binary): def evaluate(self, v): @@ -72,19 +78,21 @@ self.x.generate(atom), self.y.generate(atom)) + def compile_expression(opcodes): stack = [] push, pop = stack.append, stack.pop for opcode in opcodes: - if opcode == -1: push(Empty(opcode)) - elif opcode == -2: push(Not(pop())) - elif opcode == -3: push(And(pop(), pop())) - elif opcode == -4: push(Or(pop(), pop())) - else: push(Equals(opcode)) + if opcode == -1: push(Empty(opcode)) # noqa: E271,E701 + elif opcode == -2: push(Not(pop())) # noqa: E701 + elif opcode == -3: push(And(pop(), pop())) # noqa: E701 + elif opcode == -4: push(Or(pop(), pop())) # noqa: E701 + else: push(Equals(opcode)) # noqa: E701 return pop() + class Expression: def __init__(self, v, is_link=False): @@ -99,7 +107,7 @@ x and [int(x)] or []) else: self.evaluate = lambda x: compiled.evaluate([int(y) for y in x]) - except: + except ValueError: if is_link: v = [None if x == '-1' else x for x in v] self.evaluate = lambda x: x in v @@ -108,3 +116,5 @@ self.evaluate = lambda x: bool(set(x) & set(v)) or not x else: self.evaluate = lambda x: bool(set(x) & set(v)) + except BaseException: + raise
