jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/634344 )
Change subject: [IMPR] Replaced basestring by str
......................................................................
[IMPR] Replaced basestring by str
Bug: T265128
Change-Id: I5f365ca1e9c1e55398d7012a323afe908bbed845
---
M pywikibot/userinterfaces/gui.py
M pywikibot/userinterfaces/terminal_interface_base.py
M pywikibot/userinterfaces/transliteration.py
M scripts/add_text.py
M scripts/archivebot.py
M scripts/basic.py
6 files changed, 29 insertions(+), 54 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/userinterfaces/gui.py b/pywikibot/userinterfaces/gui.py
index 6eebc62..98b7a88 100644
--- a/pywikibot/userinterfaces/gui.py
+++ b/pywikibot/userinterfaces/gui.py
@@ -12,6 +12,7 @@
import tkinter
from tkinter.scrolledtext import ScrolledText
from tkinter import simpledialog as tkSimpleDialog
+from typing import Optional, Tuple
import pywikibot
from pywikibot import __url__
@@ -370,15 +371,14 @@
self.parent.config(menu=menubar)
self.pack()
- def edit(self, text: str, jumpIndex=None, highlight=None):
+ def edit(self, text: str, jumpIndex: Optional[int] = None,
+ highlight: Optional[str] = None):
"""
Provide user with editor to modify text.
@param text: the text to be edited
@param jumpIndex: position at which to put the caret
- @type jumpIndex: int
@param highlight: each occurrence of this substring will be highlighted
- @type highlight: str
@return: the modified text, or None if the user didn't save the text
file in his text editor
@rtype: str or None
@@ -583,11 +583,10 @@
self.skip = True
self.root.destroy()
- def show_dialog(self):
+ def show_dialog(self) -> Tuple[str, str, bool]:
"""Activate the dialog.
@return: new description, name, and if the image is skipped
- @rtype: tuple of (str, str, bool)
"""
self.root.mainloop()
return self.photo_description, self.filename, self.skip
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py
b/pywikibot/userinterfaces/terminal_interface_base.py
index 4c29233..9aebd99 100755
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -12,6 +12,8 @@
import sys
import threading
+from typing import Optional
+
import pywikibot
from pywikibot import config2 as config
from pywikibot.bot import VERBOSE, INFO, STDOUT, INPUT, WARNING
@@ -238,7 +240,8 @@
# May be overridden by subclass
return input()
- def input(self, question, password=False, default='', force=False):
+ def input(self, question: str, password: bool = False,
+ default: str = '', force: bool = False) -> str:
"""
Ask the user a question and return the answer.
@@ -249,15 +252,10 @@
a trailing question mark.
@param question: The question, without trailing whitespace.
- @type question: basestring
@param password: if True, hides the user's input (for password entry).
- @type password: bool
@param default: The default answer if none was entered. None to require
an answer.
- @type default: basestring
@param force: Automatically use the default
- @type force: bool
- @rtype: str
"""
assert(not password or not default)
end_marker = ':'
@@ -300,8 +298,9 @@
raise QuitKeyboardInterrupt()
return text
- def input_choice(self, question, options, default=None,
- return_shortcut=True, automatic_quit=True, force=False):
+ def input_choice(self, question: str, options, default: str = None,
+ return_shortcut: bool = True,
+ automatic_quit: bool = True, force: bool = False):
"""
Ask the user and returns a value from the options.
@@ -310,7 +309,6 @@
ambiguous index.
@param question: The question, without trailing whitespace.
- @type question: basestring
@param options: Iterable of all available options. Each entry contains
the full length answer and a shortcut of only one character.
Alternatively they may be Option (or subclass) instances or
@@ -321,19 +319,15 @@
Singletons of Option and its subclasses are also accepted.
@param default: The default answer if no was entered. None to require
an answer.
- @type default: basestring
@param return_shortcut: Whether the shortcut or the index in the option
should be returned.
- @type return_shortcut: bool
@param automatic_quit: Adds the option 'Quit' ('q') if True and throws
a L{QuitKeyboardInterrupt} if selected.
- @type automatic_quit: bool
@param force: Automatically use the default
- @type force: bool
@return: If return_shortcut the shortcut of options or the value of
default (if it's not None). Otherwise the index of the answer in
options. If default is not a shortcut, it'll return -1.
- @rtype: int (if not return_shortcut), lowercased basestring (otherwise)
+ @rtype: int (if not return_shortcut), lowercased str (otherwise)
"""
if force and default is None:
raise ValueError('With no default option it cannot be forced')
@@ -406,17 +400,15 @@
else:
pywikibot.error('Invalid response')
- def editText(self, text, jumpIndex=None, highlight=None):
+ def editText(self, text: str, jumpIndex: Optional[int] = None,
+ highlight: Optional[str] = None):
"""Return the text as edited by the user.
Uses a Tkinter edit box because we don't have a console editor
@param text: the text to be edited
- @type text: str
@param jumpIndex: position at which to put the caret
- @type jumpIndex: int
@param highlight: each occurrence of this substring will be highlighted
- @type highlight: str
@return: the modified text, or None if the user didn't save the text
file in his text editor
@rtype: str or None
diff --git a/pywikibot/userinterfaces/transliteration.py
b/pywikibot/userinterfaces/transliteration.py
index 7a8b445..c7b6abb 100644
--- a/pywikibot/userinterfaces/transliteration.py
+++ b/pywikibot/userinterfaces/transliteration.py
@@ -1110,17 +1110,15 @@
trans[char] = value
self.trans = trans
- def transliterate(self, char: str, default='?', prev='-', next='-') -> str:
+ def transliterate(self, char: str, default: str = '?',
+ prev: str = '-', next: str = '-') -> str:
"""
Transliterate the character.
@param char: The character to transliterate.
@param default: The character used when there is no transliteration.
- @type default: str
@param prev: The previous character
- @type prev: str
@param next: The next character
- @type next: str
@return: The transliterated character which may be an empty string
"""
if char in self.trans:
diff --git a/scripts/add_text.py b/scripts/add_text.py
index 53709d2..c7fff8f 100755
--- a/scripts/add_text.py
+++ b/scripts/add_text.py
@@ -74,7 +74,7 @@
docuReplacements = {'¶ms;': pagegenerators.parameterHelp} # noqa: N816
-def get_text(page, old, create) -> str:
+def get_text(page, old: str, create: bool) -> str:
"""
Get text on page. If old is not None, return old.
@@ -82,9 +82,7 @@
@type page: pywikibot.page.BasePage
@param old: If not None, this parameter is returned instead
of fetching text from the page
- @type old: str
@param create: Create the page if it doesn't exist
- @type create: bool
@return: The page's text or old parameter if not None
"""
if old is None:
@@ -107,20 +105,17 @@
return text
-def put_text(page, new, summary, count, asynchronous=False) -> Optional[bool]:
+def put_text(page, new: str, summary: str, count: int,
+ asynchronous: bool = False) -> Optional[bool]:
"""
Save the new text.
@param page: The page to update and save
@type page: pywikibot.page.BasePage
@param new: The new text for the page
- @type new: str
@param summary: Summary of page changes.
- @type summary: str
@param count: Maximum num attempts to reach the server
- @type count: int
@param asynchronous: Save the page asynchronously
- @type asynchronous: bool
@return: True if successful, False if unsuccessful, None if
waiting for server
"""
@@ -151,9 +146,12 @@
return False
-def add_text(page, addText, summary=None, regexSkip=None,
- regexSkipUrl=None, always=False, up=False, putText=True,
- oldTextGiven=None, reorderEnabled=True, create=False
+def add_text(page, addText: str, summary: Optional[str] = None,
+ regexSkip: Optional[str] = None,
+ regexSkipUrl: Optional[str] = None,
+ always: bool = False, up: bool = False,
+ putText: bool = True, oldTextGiven: Optional[str] = None,
+ reorderEnabled: bool = True, create: bool = False
) -> Union[Tuple[bool, bool, bool], Tuple[str, str, bool]]:
"""
Add text to a page.
@@ -161,27 +159,17 @@
@param page: The page to add text to
@type page: pywikibot.page.BasePage
@param addText: Text to add
- @type addText: str
@param summary: Summary of changes. If None, beginning of addText is used.
- @type summary: str
@param regexSkip: Abort if text on page matches
- @type regexSkip: str
@param regexSkipUrl: Abort if full url matches
- @type regexSkipUrl: str
@param always: Always add text without user confirmation
- @type always: bool
@param up: If True, add text to top of page, else add at bottom.
- @type up: bool
@param putText: If True, save changes to the page, else return
(text, newtext, always)
- @type putText: bool
@param oldTextGiven: If None fetch page text, else use this text
- @type oldTextGiven: str
@param reorderEnabled: If True place text above categories and
interwiki, else place at page bottom. No effect if up = False.
- @type reorderEnabled: bool
@param create: Create page if it does not exist
- @type create: bool
@return: If putText=True: (success, success, always)
else: (text, newtext, always)
"""
@@ -282,14 +270,13 @@
error_count += 1
-def main(*args) -> None:
+def main(*args: Tuple[str, ...]) -> None:
"""
Process command line arguments and invoke bot.
If args is an empty list, sys.argv is used.
@param args: command line arguments
- @type args: str
"""
# If none, the var is set only for check purpose.
summary = None
diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 8b15bd0..efe4802 100755
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -191,7 +191,6 @@
7d - 7 days
2w - 2 weeks (14 days)
1y - 1 year
- @type string: str
@param timestamp: a timestamp to calculate a more accurate duration offset
used by years
@type timestamp: datetime.datetime
@@ -231,7 +230,6 @@
7d - 7 days
2w - 2 weeks (14 days)
1y - 1 year
- @type string: str
@return: key and duration extracted form the string
"""
if string.isdigit():
diff --git a/scripts/basic.py b/scripts/basic.py
index 8d14573..3f859ef 100755
--- a/scripts/basic.py
+++ b/scripts/basic.py
@@ -33,6 +33,8 @@
#
# Distributed under the terms of the MIT license.
#
+from typing import Tuple
+
import pywikibot
from pywikibot import pagegenerators
@@ -121,14 +123,13 @@
self.put_current(text, summary=self.opt.summary)
-def main(*args) -> None:
+def main(*args: Tuple[str, ...]) -> None:
"""
Process command line arguments and invoke bot.
If args is an empty list, sys.argv is used.
@param args: command line arguments
- @type args: str
"""
options = {}
# Process global arguments to determine desired site
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/634344
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I5f365ca1e9c1e55398d7012a323afe908bbed845
Gerrit-Change-Number: 634344
Gerrit-PatchSet: 3
Gerrit-Owner: Udoka <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: Dr0ptp4kt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits