From 948bb064c87c169b54c02d9798fed692b6ab5104 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Thu, 9 Jul 2009 01:26:39 -0400 Subject: [PATCH] raise exception at end of plural5.plural() if no rule matched. a rule should always match --- examples/plural5.py | 1 + generators.html | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/plural5.py b/examples/plural5.py index 14845c7..31e192a 100644 --- a/examples/plural5.py +++ b/examples/plural5.py @@ -24,6 +24,7 @@ def plural(noun): for matches_rule, apply_rule in rules(): if matches_rule(noun): return apply_rule(noun) + raise ValueError('no matching rule for {0}'.format(noun)) if __name__ == '__main__': import sys diff --git a/generators.html b/generators.html index 245163b..c9008e4 100644 --- a/generators.html +++ b/generators.html @@ -304,7 +304,8 @@ rules = [] def plural(noun): for matches_rule, apply_rule in rules(): if matches_rule(noun): - return apply_rule(noun) + return apply_rule(noun) + raise ValueError('no matching rule for {0}'.format(noun))

How the heck does that work? Let’s look at an interactive example first.