raise exception at end of plural5.plural() if no rule matched. a rule should always match

This commit is contained in:
Mark Pilgrim
2009-07-09 01:26:39 -04:00
parent 3478b62a6d
commit 948bb064c8
2 changed files with 3 additions and 1 deletions
+1
View File
@@ -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
+2 -1
View File
@@ -304,7 +304,8 @@ rules = []
def plural(noun):
for matches_rule, apply_rule in rules():
if matches_rule(noun):
return apply_rule(noun)</code></pre>
return apply_rule(noun)
raise ValueError('no matching rule for {0}'.format(noun))</code></pre>
<p>How the heck does <em>that</em> work? Let&#8217;s look at an interactive example first.