'return' inside a 'with' block does not call the __exit__() method of the context manager
SyamGadde opened this issue · 1 comments
SyamGadde commented
class MyWidget(flx.Widget):
def init(self):
with flx.HBox():
return
app = flx.App(MyWidget)
app.launch()
flx.run()
Output:
[I 10:18:38 flexx.app] New session MyWidget MtRlNnIWtaIjQci7bC52hB7o
[E 10:18:38 flexx.app] JS: Error: RuntimeError: loop._deactivate_component: MyWidget_1 is not HBox_1js - stack trace in browser console (hit F12).
[E 10:18:38 flexx.app] JS: RuntimeError: RuntimeError: It seems that the event loop is processing events while a Component is active. This has a high risk on race conditions. - stack trace in browser console (hit F12).
Changing the return
to pass
avoids the error.
Looks like the PScript/Javascript conversion surrounds the contents of the 'with' block in a try/catch, which is in turn surrounded by calls to __enter__/__exit__
, so exceptions raised within the try/catch will be caught appropriately. However, __exit__
gets called after the 'catch' clause, and if there is a return statement inside the 'try' block, it never gets there. If the final error checking were in a 'finally' clause, it should work, but haven't tested.
almarklein commented
Nice catch, thanks! We should fix this ...