Skip to content

Commit b822831

Browse files
committed
clear expection after try (see custom-components#807)
1 parent ba2e791 commit b822831

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

custom_components/pyscript/eval.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,10 @@ async def ast_try(self, arg):
13431343
val = await self.aeval(arg1)
13441344
if isinstance(val, EvalStopFlow):
13451345
return val # pylint: disable=lost-exception,return-in-finally
1346+
self.exception = None
1347+
self.exception_obj = None
1348+
self.exception_long = None
1349+
self.exception_curr = None
13461350
return None
13471351

13481352
async def ast_raise(self, arg):

tests/test_unit_eval.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,26 @@ def func():
19071907
""",
19081908
"Exception in test line 4 column 0: can only specify single decorator of pyscript_compile, pyscript_executor",
19091909
],
1910+
[
1911+
"""
1912+
try:
1913+
raise ValueError("Random error")
1914+
except KeyError:
1915+
pass
1916+
""",
1917+
"Exception in test line 3 column 21: Random error",
1918+
],
1919+
[
1920+
"""
1921+
try:
1922+
raise ValueError("Random error")
1923+
except ValueError as e:
1924+
pass
1925+
1926+
raise
1927+
""",
1928+
"Exception in test line 7 column 0: No active exception to reraise",
1929+
],
19101930
]
19111931

19121932

0 commit comments

Comments
 (0)