Skip to content

Commit

Permalink
Support empty raise (re-raise)
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Oct 17, 2024
1 parent cf0ee84 commit e1e590a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rewrite/rewrite/python/_parser_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,11 @@ def visit_AsyncWith(self, node):


def visit_Raise(self, node):
return py.Throw(
return j.Throw(
random_id(),
self.__source_before('raise'),
Markers.EMPTY,
self.__convert(node.exc),
self.__convert(node.exc) if node.exc else j.Empty(random_id(), Space.EMPTY, Markers.EMPTY),
)


Expand Down
14 changes: 14 additions & 0 deletions rewrite/tests/python/all/try_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ def test():
)


def test_reraise():
# language=python
rewrite_run(
python(
"""\
try:
pass
except OverflowError:
raise
"""
)
)


@pytest.mark.xfail(reason="Implementation still not quite correct", strict=True)
def test_try_else():
# language=python
Expand Down

0 comments on commit e1e590a

Please sign in to comment.