From 39a03ab4e5c2ebffed20096d7942ccf114eae974 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Fri, 4 Dec 2020 14:58:18 -0600 Subject: [PATCH] [Web] Close stale file handle in exec() Eliminate the Python interpreter warning about failure to close a stale handle when using the `exec(open('%s').read()` idiom, enclosing it in a `with` clause. --- src/Mod/Web/Gui/BrowserView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mod/Web/Gui/BrowserView.cpp b/src/Mod/Web/Gui/BrowserView.cpp index a281c79f9c..c286ba8cde 100644 --- a/src/Mod/Web/Gui/BrowserView.cpp +++ b/src/Mod/Web/Gui/BrowserView.cpp @@ -544,7 +544,7 @@ void BrowserView::onLinkClicked (const QUrl & url) #if PY_MAJOR_VERSION < 3 Gui::Command::doCommand(Gui::Command::Gui,"exec(open(unicode('%s', 'utf-8')).read())",(const char*) filename.toUtf8()); #else - Gui::Command::doCommand(Gui::Command::Gui,"exec(open('%s').read())",(const char*) filename.toUtf8()); + Gui::Command::doCommand(Gui::Command::Gui,"with open('%s') as file:\n\texec(file.read())",(const char*) filename.toUtf8()); #endif } catch (const Base::Exception& e) {