jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1096390?usp=email )
Change subject: IMPR: avoid using join statements with literal constants
......................................................................
IMPR: avoid using join statements with literal constants
Change-Id: Icc546daed6c0f9b928b7ef6f34cd30604f0c1974
---
M pywikibot/textlib.py
M pywikibot/userinterfaces/terminal_interface_base.py
M scripts/archivebot.py
M scripts/revertbot.py
M tests/category_bot_tests.py
M tests/cosmetic_changes_tests.py
M tests/site_detect_tests.py
7 files changed, 31 insertions(+), 43 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index b6966c8..0089047 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -1112,10 +1112,8 @@
cat_regex, interwiki_regex = get_regexes(['category', 'interwiki'], site)
langlink_pattern = interwiki_regex.pattern.replace(':?', '')
last_section_content = sections[-1].content if sections else header
- footer = re.search(
- r'({})*\Z'.format(r'|'.join((langlink_pattern,
- cat_regex.pattern, r'\s'))),
- last_section_content).group().lstrip()
+ footer = re.search(fr'({langlink_pattern}|{cat_regex.pattern}|\s)*\Z',
+ last_section_content).group().lstrip()
if footer:
if sections:
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py
b/pywikibot/userinterfaces/terminal_interface_base.py
index b123ff8..c32a113 100644
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -317,10 +317,10 @@
# transliteration was successful. The replacement
# could consist of multiple letters.
# mark the transliterated letters in yellow.
- transliteratedText = ''.join((transliteratedText,
- '<<lightyellow>>',
- transliterated,
- '<<previous>>'))
+ transliteratedText = (
+ f'{transliteratedText}'
+ f'<<lightyellow>>{transliterated}<<previous>>'
+ )
# memorize if we replaced a single letter by multiple
# letters.
if transliterated:
diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 7d9b883..732b362 100755
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -422,7 +422,7 @@
header, threads, footer = extract_sections(text, self.site)
header = header.replace(marker, '')
if header and footer:
- self.header = '\n\n'.join((header.rstrip(), footer, ''))
+ self.header = f'{header.rstrip()}\n\n{footer}\n\n'
else:
self.header = header + footer
diff --git a/scripts/revertbot.py b/scripts/revertbot.py
index bf2f442..53bcaad 100755
--- a/scripts/revertbot.py
+++ b/scripts/revertbot.py
@@ -103,7 +103,7 @@
year = formatYear(self.site.lang, ts.year)
date = format_date(ts.month, ts.day, self.site)
*_, time = str(ts).strip('Z').partition('T')
- return ' '.join((date, year, time))
+ return f'{date} {year} {time}'
def revert(self, item) -> str | bool:
"""Revert a single item."""
diff --git a/tests/category_bot_tests.py b/tests/category_bot_tests.py
index efc28ce..13ba895 100755
--- a/tests/category_bot_tests.py
+++ b/tests/category_bot_tests.py
@@ -47,22 +47,13 @@
def _runtest_strip_cfd_templates(self, template_start, template_end):
"""Run a CFD template stripping test, given CFD start/end templates."""
bot = CategoryMoveRobot(oldcat='Old', newcat='New')
- bot.newcat.text = '\n'.join((
- 'Preamble',
- template_start,
- 'Random text inside template',
- 'Even another template: {{cfr-speedy}}',
- template_end,
- 'Footer stuff afterwards',
- '',
- '[[Category:Should remain]]'
- ))
- expected = '\n'.join((
- 'Preamble',
- 'Footer stuff afterwards',
- '',
- '[[Category:Should remain]]'
- ))
+ bot.newcat.text = (
+ f'Preamble\n{template_start}\nRandom text inside template\n'
+ f'Even another template: {{{{cfr-speedy}}}}\n{template_end}\n'
+ f'Footer stuff afterwards\n\n[[Category:Should remain]]'
+ )
+ expected = ('Preamble\nFooter stuff afterwards\n\n'
+ '[[Category:Should remain]]')
bot._strip_cfd_templates(commit=False)
self.assertEqual(bot.newcat.text, expected)
diff --git a/tests/cosmetic_changes_tests.py b/tests/cosmetic_changes_tests.py
index 8714183..538cda2 100755
--- a/tests/cosmetic_changes_tests.py
+++ b/tests/cosmetic_changes_tests.py
@@ -581,31 +581,31 @@
# Invalid characters
with self.assertRaisesRegex(
ValidationError,
- '|'.join((self.ISBN_DIGITERROR_RE,
- self.ISBN_INVALIDERROR_RE,
- self.ISBN_INVALIDLENGTHERROR_RE))):
+ f'{self.ISBN_DIGITERROR_RE}|{self.ISBN_INVALIDERROR_RE}|'
+ f'{self.ISBN_INVALIDLENGTHERROR_RE}'
+ ):
self.cct.fix_ISBN('ISBN 0975229LOL')
# Invalid checksum
with self.assertRaisesRegex(
ValidationError,
- '|'.join((self.ISBN_CHECKSUMERROR_RE,
- self.ISBN_INVALIDERROR_RE,
- self.ISBN_INVALIDLENGTHERROR_RE,
- self.ISBN_INVALIDCHECKERROR_RE))):
+ f'{self.ISBN_CHECKSUMERROR_RE}|{self.ISBN_INVALIDERROR_RE}|'
+ f'{self.ISBN_INVALIDLENGTHERROR_RE}|'
+ f'{self.ISBN_INVALIDCHECKERROR_RE}'
+ ):
self.cct.fix_ISBN('ISBN 0975229801')
# Invalid length
with self.assertRaisesRegex(
ValidationError,
- '|'.join((self.ISBN_DIGITERROR_RE,
- self.ISBN_INVALIDERROR_RE,
- self.ISBN_INVALIDLENGTHERROR_RE))):
+ f'{self.ISBN_DIGITERROR_RE}|{self.ISBN_INVALIDERROR_RE}|'
+ f'{self.ISBN_INVALIDLENGTHERROR_RE}'
+ ):
self.cct.fix_ISBN('ISBN 09752298')
# X in the middle
with self.assertRaisesRegex(
ValidationError,
- '|'.join((self.ISBN_INVALIDCHARERROR_RE,
- self.ISBN_INVALIDERROR_RE,
- self.ISBN_INVALIDLENGTHERROR_RE))):
+ f'{self.ISBN_INVALIDCHARERROR_RE}|{self.ISBN_INVALIDERROR_RE}|'
+ f'{self.ISBN_INVALIDLENGTHERROR_RE}'
+ ):
self.cct.fix_ISBN('ISBN 09752X9801')
def test_ignore_invalid_isbn(self):
diff --git a/tests/site_detect_tests.py b/tests/site_detect_tests.py
index 715fb24..3c18a1a 100755
--- a/tests/site_detect_tests.py
+++ b/tests/site_detect_tests.py
@@ -170,10 +170,9 @@
# the user-supplied URL. We need to return enough data for
# site_detect.WikiHTMLPageParser to determine the server
# version and the API URL.
- WEBPATH: ''.join((
- '<meta name="generator" content="', _generator,
- '"/>\n<link rel="EditURI" type="application/rsd+xml" '
- 'href="', _apiurl, '?action=rsd"/>')),
+ WEBPATH: f'<meta name="generator" content="{_generator}"/>\n'
+ f'<link rel="EditURI" type="application/rsd+xml" '
+ f'href="{_apiurl}?action=rsd"/>',
APIPATH: '{"error":{"code":"readapidenied"}}',
}
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1096390?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: Icc546daed6c0f9b928b7ef6f34cd30604f0c1974
Gerrit-Change-Number: 1096390
Gerrit-PatchSet: 7
Gerrit-Owner: Xqt <[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]