Skip to content

Commit

Permalink
Avoid an (expensive) exception in transform.
Browse files Browse the repository at this point in the history
  • Loading branch information
eevee committed Apr 8, 2014
1 parent d6a8969 commit 23dbb7c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,13 @@ def transform(self, node):
"""Call matching transforms for the given node if any and return the
transformed node.
"""
try:
transforms = self.transforms[type(node)]
except KeyError:
return node # no transform registered for this class of node
orig_node = node # copy the reference
cls = node.__class__
if cls not in self.transforms:
# no transform registered for this class of node
return node

transforms = self.transforms[cls]
orig_node = node # copy the reference
for transform_func, predicate in transforms:
if predicate is None or predicate(node):
ret = transform_func(node)
Expand Down

0 comments on commit 23dbb7c

Please sign in to comment.