Browse Source

Don't use assertions here.

tags/v0.2
Ben Kurtovic 10 years ago
parent
commit
f9a49c4378
1 changed files with 5 additions and 3 deletions
  1. +5
    -3
      earwigbot/commands/remind.py

+ 5
- 3
earwigbot/commands/remind.py View File

@@ -60,7 +60,8 @@ class Remind(Command):
def _evaluate(node):
"""Convert an AST node into a real number or raise an exception."""
if isinstance(node, ast.Num):
assert isinstance(node.n, (int, long, float))
if not isinstance(node.n, (int, long, float)):
raise ValueError(node.n)
return node.n
elif isinstance(node, ast.BinOp):
left, right = _evaluate(node.left), _evaluate(node.right)
@@ -69,9 +70,10 @@ class Remind(Command):
raise ValueError(node)
try:
parsed = int(_evaluate(ast.parse(arg, mode="eval").body))
assert parsed > 0
except (SyntaxError, AssertionError, KeyError):
except (SyntaxError, KeyError):
raise ValueError(arg)
if parsed <= 0:
raise ValueError(parsed)
return parsed

def _really_get_reminder_by_id(self, user, rid):


Loading…
Cancel
Save