jenkins-bot has submitted this change and it was merged.
Change subject: Move import of 'gui' to top of file
......................................................................
Move import of 'gui' to top of file
Using 'import foo.bar.x' in the middle of function defines 'foo'
in that context, and if the import fails 'foo' is no longer bound.
Bug: T89485
Change-Id: Ic43af9d08dd5c4e006ebfb12f03dd90ae7ec5423
---
M pywikibot/editor.py
1 file changed, 8 insertions(+), 4 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/editor.py b/pywikibot/editor.py
index 32afdc6..7d1687d 100644
--- a/pywikibot/editor.py
+++ b/pywikibot/editor.py
@@ -17,8 +17,14 @@
import tempfile
import pywikibot
+
from pywikibot import config
from pywikibot.tools import deprecated
+
+try:
+ from pywikibot.userinterfaces import gui # noqa
+except ImportError as e:
+ gui = e
class TextEditor(object):
@@ -107,14 +113,12 @@
finally:
os.unlink(tempFilename)
- try:
- import pywikibot.userinterfaces.gui # noqa
- except ImportError as e:
+ if isinstance(gui, ImportError):
raise pywikibot.Error(
'Could not load GUI modules: %s\nNo editor available.\n'
'Set your favourite editor in user-config.py "editor",
'
'or install python packages tkinter and idlelib, which '
'are typically part of Python but may be packaged separately '
- 'on your platform.\n' % e)
+ 'on your platform.\n' % gui)
return pywikibot.ui.editText(text, jumpIndex=jumpIndex, highlight=highlight)
--
To view, visit
https://gerrit.wikimedia.org/r/190561
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic43af9d08dd5c4e006ebfb12f03dd90ae7ec5423
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>