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)
pywikibot-commits@lists.wikimedia.org