Skip to content

Commit

Permalink
Improved error message when passing an invalid tween to animate
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-james authored and lordmauve committed Sep 19, 2018
1 parent f0cddc7 commit f2020c1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pgzero/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from math import sin, pow, pi

from .clock import each_tick, unschedule
from .spellcheck import suggest

TWEEN_FUNCTIONS = {}

Expand Down Expand Up @@ -151,7 +152,14 @@ class Animation:
def __init__(self, object, tween='linear', duration=1, on_finished=None,
**targets):
self.targets = targets
self.function = TWEEN_FUNCTIONS[tween]
try:
self.function = TWEEN_FUNCTIONS[tween]
except KeyError:
suggested_tween = suggest(tween, TWEEN_FUNCTIONS.keys())
if len(suggested_tween) > 0:
raise KeyError('No tween called %s found, did you mean %s?' % (tween, suggested_tween[0]))
else:
raise KeyError('No tween called %s found.' % tween)
self.duration = duration
self.on_finished = on_finished
self.t = 0
Expand Down

0 comments on commit f2020c1

Please sign in to comment.