瀏覽代碼

Don't use assertions here.

tags/v0.2
Ben Kurtovic 10 年之前
父節點
當前提交
f9a49c4378
共有 1 個文件被更改,包括 5 次插入3 次删除
  1. +5
    -3
      earwigbot/commands/remind.py

+ 5
- 3
earwigbot/commands/remind.py 查看文件

@@ -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…
取消
儲存