Skip to content

Commit

Permalink
fix patchedast to match as token in excepthandler
Browse files Browse the repository at this point in the history
  • Loading branch information
enomado authored and Matěj Cepl committed Dec 1, 2013
1 parent 61794e8 commit 7d9aecd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion rope/refactor/patchedast.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def __init__(self, source, children=False):

Number = object()
String = object()
semicolon_or_as_in_except = object()

def __call__(self, node):
method = getattr(self, '_' + node.__class__.__name__, None)
Expand Down Expand Up @@ -111,6 +112,9 @@ def _handle(self, node, base_children, eat_parens=False, eat_spaces=False):
elif child == '!=':
# INFO: This has been added to handle deprecated ``<>``
region = self.source.consume_not_equal()
elif child == self.semicolon_or_as_in_except:
# INFO: This has been added to handle deprecated semicolon in except
region = self.source.consume_except_as_or_semicolon()
else:
region = self.source.consume(child)
child = self.source[region[0]:region[1]]
Expand Down Expand Up @@ -568,13 +572,16 @@ def _ExceptHandler(self, node):
self._excepthandler(node)

def _excepthandler(self, node):
# self._handle(node, [self.semicolon_or_as_in_except])
children = ['except']
if node.type:
children.append(node.type)
if node.name:
children.extend([',', node.name])
children.append(self.semicolon_or_as_in_except)
children.append(node.name)
children.append(':')
children.extend(node.body)

self._handle(node, children)

def _Tuple(self, node):
Expand Down Expand Up @@ -663,6 +670,12 @@ def consume_not_equal(self):
repattern = _Source._not_equals_pattern
return self._consume_pattern(repattern)


def consume_except_as_or_semicolon(self):
repattern = re.compile(r'as|,')
return self._consume_pattern(repattern)


def _good_token(self, token, offset, start=None):
"""Checks whether consumed token is in comments"""
if start is None:
Expand Down

0 comments on commit 7d9aecd

Please sign in to comment.