jenkins-bot merged this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[cleanup] Avoid creating objects passed to str.join

A tip from https://deepsource.io/blog/8-new-python-antipatterns/

Change-Id: Ibe594bd53f93b964f8a7c9edf09558bfcd24a23c
---
M pywikibot/comms/http.py
M pywikibot/site/__init__.py
M scripts/casechecker.py
M scripts/followlive.py
M scripts/interwiki.py
M scripts/replace.py
6 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index e09f880..2051afd 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -130,7 +130,7 @@
atexit.register(_flush)

USER_AGENT_PRODUCTS = {
- 'python': 'Python/' + '.'.join([str(i) for i in sys.version_info]),
+ 'python': 'Python/' + '.'.join(str(i) for i in sys.version_info),
'http_backend': 'requests/' + requests.__version__,
'pwb': 'Pywikibot/' + __version__,
}
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index f7b8471..fc016c2 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -372,9 +372,8 @@
if key not in standard_attr]

if extra:
- kwargs = ', ' + ', '.join([key + '=' + repr(value)
- for (key, value) in
- extra])
+ kwargs = ', ' + ', '.join(
+ key + '=' + repr(value) for key, value in extra)
else:
kwargs = ''

@@ -628,8 +627,8 @@
if None in result:
raise KeyError(
'Namespace identifier(s) not recognised: %s'
- % ','.join([str(identifier) for identifier, ns in zip(
- identifiers, result) if ns is None]))
+ % ','.join(str(identifier) for identifier, ns in zip(
+ identifiers, result) if ns is None))

return result

diff --git a/scripts/casechecker.py b/scripts/casechecker.py
index c666f10..7d6273f 100755
--- a/scripts/casechecker.py
+++ b/scripts/casechecker.py
@@ -229,8 +229,8 @@
% len(self.knownWords))
if len(self.knownWords) > 0:
pywikibot.log('Whitelist: '
- + ', '.join([self.MakeLink(i, False)
- for i in self.knownWords]))
+ + ', '.join(self.MakeLink(i, False)
+ for i in self.knownWords))
else:
pywikibot.output('Whitelist is not known for language %s'
% self.site.code)
@@ -541,7 +541,7 @@
suggestions = list(mapLcl.values()) + list(mapLat.values())
if len(suggestions) > 0:
infoText += ', word suggestions: ' + ', '.join(
- [self.ColorCodeWord(t) for t in suggestions])
+ self.ColorCodeWord(t) for t in suggestions)
else:
infoText += ', no suggestions'
else:
@@ -572,7 +572,7 @@

if len(possibleAlternatives) > 0:
infoText += ', can be converted to ' + ', '.join(
- [self.MakeLink(t) for t in possibleAlternatives])
+ self.MakeLink(t) for t in possibleAlternatives)
else:
infoText += ', no suggestions'
return (infoText, possibleAlternatives)
@@ -712,7 +712,7 @@
def PutNewPage(self, pageObj, pageTxt, msg):
"""Save new page."""
title = pageObj.title(as_link=True, textlink=True)
- coloredMsg = ', '.join([self.ColorCodeWord(m) for m in msg])
+ coloredMsg = ', '.join(self.ColorCodeWord(m) for m in msg)
if pageObj.text == pageTxt:
self.WikiLog('* Error: Text replacement failed in %s (%s)'
% (self.MakeLink(title, False), coloredMsg))
diff --git a/scripts/followlive.py b/scripts/followlive.py
index eb54db9..3c1ecad 100644
--- a/scripts/followlive.py
+++ b/scripts/followlive.py
@@ -539,8 +539,8 @@
"""Setup bot before running."""
self.questionlist = {
i: t for i, t in enumerate(templates[self.site.code], start=1)}
- questions = '\n'.join(('{}) {}'.format(k, v)
- for k, v in self.questionlist.items()))
+ questions = '\n'.join('{}) {}'.format(k, v)
+ for k, v in self.questionlist.items())
self.question = questions + self.question


diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index d4e5e76..8f9fd66 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -1860,7 +1860,7 @@
# Allow for special case of a self-pointing interwiki link
if removing and removing != [page.site]:
self.problem('Found incorrect link to {} in {}'
- .format(', '.join([x.code for x in removing]), page),
+ .format(', '.join(x.code for x in removing), page),
createneed=False)
ask = True
if self.conf.force or self.conf.cleanup:
@@ -1944,7 +1944,7 @@
raise GiveUpOnPage('User asked us to give up')
else:
raise LinkMustBeRemoved('Found incorrect link to {} in {}'.format(
- ', '.join([x.code for x in removing]), page))
+ ', '.join(x.code for x in removing), page))

def reportBacklinks(self, new, updatedSites):
"""
diff --git a/scripts/replace.py b/scripts/replace.py
index b2343dd..3a9d5a4 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -1171,13 +1171,13 @@
elif useSql:
if not sql_query:
whereClause = 'WHERE (%s)' % ' OR '.join(
- ["old_text RLIKE '%s'" % prepareRegexForMySQL(
- old_regexp.pattern) for (old_regexp, new_text)
- in replacements])
+ "old_text RLIKE '%s'"
+ % prepareRegexForMySQL(old_regexp.pattern)
+ for (old_regexp, new_text) in replacements)
if exceptions:
exceptClause = 'AND NOT (%s)' % ' OR '.join(
- ["old_text RLIKE '%s'" % prepareRegexForMySQL(exc.pattern)
- for exc in exceptions])
+ "old_text RLIKE '%s'" % prepareRegexForMySQL(exc.pattern)
+ for exc in exceptions)
else:
exceptClause = ''
query = sql_query or """

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibe594bd53f93b964f8a7c9edf09558bfcd24a23c
Gerrit-Change-Number: 586066
Gerrit-PatchSet: 3
Gerrit-Owner: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot (75)
Gerrit-CC: Dvorapa <dvorapa@seznam.cz>