jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1346433?usp=email )
Change subject: Use built-in methods for exact prefix and suffix removal
......................................................................
Use built-in methods for exact prefix and suffix removal
Replace guarded leading-dash slices in script option parsers with
removeprefix(). Use removesuffix() for extracted textlib footers and
the trailing dot in abbreviated month names.
Retain validation branches and slicing that depends on case-insensitive
matching, parsed positions or overlapping delimiters.
Change-Id: I3f77967b332e165ce1db0839341ac5cf95a36765
---
M pywikibot/textlib.py
M scripts/archivebot.py
M scripts/clean_sandbox.py
M scripts/download_dump.py
M scripts/interwikidata.py
M scripts/misspelling.py
M scripts/movepages.py
M scripts/newitem.py
M scripts/nowcommons.py
M scripts/parser_function_count.py
M scripts/protect.py
M scripts/revertbot.py
12 files changed, 16 insertions(+), 18 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 7da87fc..71c05b2 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -1381,9 +1381,9 @@
if footer:
if sections:
sections[-1] = Section(
- sections[-1].title, last_section_content[:-len(footer)])
+ sections[-1].title, last_section_content.removesuffix(footer))
else:
- header = header[:-len(footer)]
+ header = header.removesuffix(footer)
return Content(header, sections, footer)
@@ -2295,7 +2295,7 @@
# in some cases month in ~~~~ might end without dot even if
# site.months_names do not.
if short.endswith('.'):
- self.origNames2monthNum[func(short[:-1])] = n
+ self.origNames2monthNum[func(short.removesuffix('.'))] = n
timeR = (r'(?P<time>(?P<hour>([0-1]\d|2[0-3]))[:\.h]'
r'(?P<minute>[0-5]\d))')
diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 979ea68..c584d9c 100755
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -1060,7 +1060,7 @@
if not option.startswith('-'):
templates.append(arg)
continue
- option = option[1:]
+ option = option.removeprefix('-')
if option in ('file', 'filename'):
filename = value
elif option == 'locale':
diff --git a/scripts/clean_sandbox.py b/scripts/clean_sandbox.py
index 5581314..d49b035 100755
--- a/scripts/clean_sandbox.py
+++ b/scripts/clean_sandbox.py
@@ -319,7 +319,7 @@
if not opt.startswith('-'):
continue
- opt = opt[1:]
+ opt = opt.removeprefix('-')
if opt == 'hours':
opts[opt] = float(value)
elif opt == 'delay':
diff --git a/scripts/download_dump.py b/scripts/download_dump.py
index bce2ac0..b49a3d8 100755
--- a/scripts/download_dump.py
+++ b/scripts/download_dump.py
@@ -202,7 +202,7 @@
for arg in local_args:
option, _, value = arg.partition(':')
if option.startswith('-'):
- option = option[1:]
+ option = option.removeprefix('-')
if option == 'filename':
opts[option] = value or pywikibot.input('Enter the filename: ')
diff --git a/scripts/interwikidata.py b/scripts/interwikidata.py
index 1e8c66c..6b1aa53 100755
--- a/scripts/interwikidata.py
+++ b/scripts/interwikidata.py
@@ -246,7 +246,7 @@
for arg in local_args:
option, _, value = arg.partition(':')
if option.startswith('-'):
- option = option[1:]
+ option = option.removeprefix('-')
else:
continue
diff --git a/scripts/misspelling.py b/scripts/misspelling.py
index 0756619..999c141 100755
--- a/scripts/misspelling.py
+++ b/scripts/misspelling.py
@@ -171,7 +171,7 @@
opt, _, value = arg.partition(':')
if not opt.startswith('-'):
continue
- opt = opt[1:]
+ opt = opt.removeprefix('-')
if opt == 'always':
# the option that's always selected when the bot wonders
# what to do with a link. If it's None, the user is prompted
diff --git a/scripts/movepages.py b/scripts/movepages.py
index 2676324..f86c914 100755
--- a/scripts/movepages.py
+++ b/scripts/movepages.py
@@ -231,7 +231,7 @@
opt, _, value = arg.partition(':')
if not opt.startswith('-'):
continue
- opt = opt[1:]
+ opt = opt.removeprefix('-')
if opt == 'pairsfile':
filename = value or pywikibot.input(
'Enter the name of the file containing pairs:')
diff --git a/scripts/newitem.py b/scripts/newitem.py
index 0d32c4d..e2578da 100755
--- a/scripts/newitem.py
+++ b/scripts/newitem.py
@@ -193,7 +193,7 @@
for arg in local_args:
if arg.startswith(('-pageage:', '-lastedit:')):
key, val = arg.split(':', 1)
- options[key[1:]] = int(val)
+ options[key.removeprefix('-')] = int(val)
elif gen.handle_arg(arg):
pass
else:
diff --git a/scripts/nowcommons.py b/scripts/nowcommons.py
index d62938a..940d2c7 100755
--- a/scripts/nowcommons.py
+++ b/scripts/nowcommons.py
@@ -406,11 +406,9 @@
if arg == '-replacealways':
options['replace'] = True
options['replacealways'] = True
- elif arg.startswith('-') and arg[1:] in ('always',
- 'replace',
- 'replaceloose',
- 'replaceonly'):
- options[arg[1:]] = True
+ elif arg.startswith('-') and (option := arg.removeprefix('-')) in (
+ 'always', 'replace', 'replaceloose', 'replaceonly'):
+ options[option] = True
bot = NowCommonsDeleteBot(**options)
bot.run()
diff --git a/scripts/parser_function_count.py b/scripts/parser_function_count.py
index f7cc5ac..01a2b7a 100755
--- a/scripts/parser_function_count.py
+++ b/scripts/parser_function_count.py
@@ -175,7 +175,7 @@
opt, _, value = arg.partition(':')
if not opt.startswith('-'):
continue
- opt = opt[1:]
+ opt = opt.removeprefix('-')
if opt == 'start':
options[opt] = value or pywikibot.input(
'From which title do you want to continue?')
diff --git a/scripts/protect.py b/scripts/protect.py
index c1c6414..f6d744f 100755
--- a/scripts/protect.py
+++ b/scripts/protect.py
@@ -184,7 +184,7 @@
if not option.startswith('-'):
continue
- option = option[1:]
+ option = option.removeprefix('-')
if option == 'always':
options[option] = True
elif option == 'summary':
diff --git a/scripts/revertbot.py b/scripts/revertbot.py
index debe6d9..d919f7a 100755
--- a/scripts/revertbot.py
+++ b/scripts/revertbot.py
@@ -256,7 +256,7 @@
opt, _, value = arg.partition(':')
if not opt.startswith('-'):
continue
- opt = opt[1:]
+ opt = opt.removeprefix('-')
if opt == 'username':
options['user'] = value or pywikibot.input(
'Please enter username of the person you want to revert:')
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1346433?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I3f77967b332e165ce1db0839341ac5cf95a36765
Gerrit-Change-Number: 1346433
Gerrit-PatchSet: 3
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]