mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
raise exception at end of plural5.plural() if no rule matched. a rule should always match
This commit is contained in:
@@ -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
@@ -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’s look at an interactive example first.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user