jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[IMPR] editor.py type hints

Bug: T286403
Change-Id: Ife94069f4b65bc14dd19af314205be3661ec15f8
---
M pywikibot/editor.py
1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/pywikibot/editor.py b/pywikibot/editor.py
index dfb6cff..db627e1 100644
--- a/pywikibot/editor.py
+++ b/pywikibot/editor.py
@@ -15,19 +15,22 @@

import pywikibot
from pywikibot import config
+from pywikibot.backports import List, Sequence


try:
- from pywikibot.userinterfaces import gui
+ from pywikibot.userinterfaces import gui # noqa
+ GUI_ERROR = None
except ImportError as e:
- gui = e
+ GUI_ERROR = e


class TextEditor:

"""Text editor."""

- def _command(self, file_name, text, jump_index=None):
+ def _command(self, file_name: str, text: str,
+ jump_index: Optional[int] = None) -> List[str]:
"""Return editor selected in user-config.py."""
if jump_index:
# Some editors make it possible to mark occurrences of substrings,
@@ -40,6 +43,7 @@
line = column = 0
# Linux editors. We use startswith() because some users might use
# parameters.
+ assert config.editor is not None
if config.editor.startswith('kate'):
command = ['-l', str(line + 1), '-c', str(column + 1)]
elif config.editor.startswith('gedit'):
@@ -64,7 +68,7 @@
return command

@staticmethod
- def _concat(command):
+ def _concat(command: Sequence[str]) -> str:
return ' '.join("'{}'".format(part) if ' ' in part else part
for part in command)

@@ -105,13 +109,15 @@
os.close(handle)
os.unlink(tempFilename)

- if isinstance(gui, ImportError):
+ if GUI_ERROR:
raise ImportError(fill(
'Could not load GUI modules: {}. No editor available. '
'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.'.format(gui)) + '\n')
+ 'on your platform.'.format(GUI_ERROR)) + '\n')
+
+ assert pywikibot.ui is not None

return pywikibot.ui.editText(text, jumpIndex=jumpIndex,
highlight=highlight)

To view, visit change 709252. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ife94069f4b65bc14dd19af314205be3661ec15f8
Gerrit-Change-Number: 709252
Gerrit-PatchSet: 3
Gerrit-Owner: Damian <atagar1@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged