jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/595861 )
Change subject: [flake8] Solve some flake8 issues ......................................................................
[flake8] Solve some flake8 issues
A new flake8 release was published today.
Change-Id: Id7d1594f588ce737a8b7798638a34b378743486d --- M pywikibot/data/mysql.py M pywikibot/date.py M pywikibot/diff.py M pywikibot/site_detect.py M pywikibot/textlib.py M scripts/casechecker.py M scripts/imagecopy_self.py M scripts/interwiki.py M scripts/replicate_wiki.py M scripts/solve_disambiguation.py M tests/api_tests.py 11 files changed, 61 insertions(+), 63 deletions(-)
Approvals: Dvorapa: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/mysql.py b/pywikibot/data/mysql.py index 15a6ceb..05186c3 100644 --- a/pywikibot/data/mysql.py +++ b/pywikibot/data/mysql.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Miscellaneous helper functions for mysql queries.""" # -# (C) Pywikibot team, 2016-2019 +# (C) Pywikibot team, 2016-2020 # # Distributed under the terms of the MIT license. # @@ -71,7 +71,8 @@ if not isinstance(_query, UnicodeType): _query = UnicodeType(_query, encoding='utf-8') _query = _query.strip() - _query = '\n'.join(' {0}'.format(l) for l in _query.splitlines()) + _query = '\n'.join(' {0}'.format(line) + for line in _query.splitlines()) pywikibot.output('Executing query:\n' + _query)
cursor.execute(query, params) diff --git a/pywikibot/date.py b/pywikibot/date.py index 6ad13da..c4e0030 100644 --- a/pywikibot/date.py +++ b/pywikibot/date.py @@ -374,7 +374,7 @@ continue if (len(s) in (2, 3) and s[0] == '%' and s[-1] in _digitDecoders - and(len(s) == 2 or s[1] in _decimalDigits)): + and (len(s) == 2 or s[1] in _decimalDigits)): # Must match a "%2d" or "%d" style dec = _digitDecoders[s[-1]] if isinstance(dec, UnicodeType): diff --git a/pywikibot/diff.py b/pywikibot/diff.py index 002df37..1bc9a20 100644 --- a/pywikibot/diff.py +++ b/pywikibot/diff.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Diff module.""" # -# (C) Pywikibot team, 2014-2019 +# (C) Pywikibot team, 2014-2020 # # Distributed under the terms of the MIT license. # @@ -89,10 +89,10 @@ """Generator of diff text for this hunk, without formatting.""" # make sure each line ends with '\n' to prevent # behaviour like http://bugs.python.org/issue2142 - def check_line(l): - if not l.endswith('\n'): - return l + '\n' - return l + def check_line(line): + if not line.endswith('\n'): + line += '\n' + return line
for tag, i1, i2, j1, j2 in self.group: # equal/delete/insert add additional space after the sign as it's diff --git a/pywikibot/site_detect.py b/pywikibot/site_detect.py index bf1d231..ac5908b 100644 --- a/pywikibot/site_detect.py +++ b/pywikibot/site_detect.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Classes for detecting a MediaWiki site.""" # -# (C) Pywikibot team, 2010-2019 +# (C) Pywikibot team, 2010-2020 # # Distributed under the terms of the MIT license. # @@ -154,8 +154,8 @@
self.version = list(filter( lambda x: x.startswith('MediaWiki'), - (l.strip() - for l in d['error']['*'].split('\n'))))[0].split()[1] + (line.strip() + for line in d['error']['*'].split('\n'))))[0].split()[1] except Exception: pass else: diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py index 36a5229..d73510b 100644 --- a/pywikibot/textlib.py +++ b/pywikibot/textlib.py @@ -667,10 +667,10 @@ 'a sequence, a Link or a basestring but ' 'is "{0}"'.format(type(replacement)))
- def title_section(l): - title = l.title - if l.section: - title += '#' + l.section + def title_section(link): + title = link.title + if link.section: + title += '#' + link.section return title
if isinstance(replace, Sequence): diff --git a/scripts/casechecker.py b/scripts/casechecker.py index 7d6273f..f744990 100755 --- a/scripts/casechecker.py +++ b/scripts/casechecker.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- """Bot to find all pages on the wiki with mixed latin and cyrilic alphabets.""" # -# (C) Pywikibot team, 2006-2019 +# (C) Pywikibot team, 2006-2020 # # Distributed under the terms of the MIT license. # @@ -408,8 +408,8 @@ msg = [] foundSuggestions = False
- for l in allLinks: - ltxt = l['title'] + for link in allLinks: + ltxt = link['title'] err = self.ProcessTitle(ltxt) if err: if len(err[1]) > 0: @@ -484,14 +484,14 @@ # See if it would make sense to treat the whole word as either # cyrilic or latin mightBeLat = mightBeLcl = True - for l in badWord: - if l in self.localLtr: - if mightBeLat and l not in self.localSuspects: + for letter in badWord: + if letter in self.localLtr: + if mightBeLat and letter not in self.localSuspects: mightBeLat = False else: - if mightBeLcl and l not in self.latinSuspects: + if mightBeLcl and letter not in self.latinSuspects: mightBeLcl = False - if l not in ascii_letters: + if letter not in ascii_letters: raise ValueError('Assert failed')
# Some words are well known and frequently mixed-typed @@ -645,16 +645,16 @@ res += self.lclClrFnt else: res += self.latClrFnt - for l in word: - if l in self.localLtr: + for letter in word: + if letter in self.localLtr: if not lastIsCyr: res += self.suffixClr + self.lclClrFnt lastIsCyr = True - elif l in ascii_letters: + elif letter in ascii_letters: if lastIsCyr: res += self.suffixClr + self.latClrFnt lastIsCyr = False - res += l + res += letter return res + self.suffixClr + '</b>'
def _ColorCodeWordScreen(self, word): @@ -664,16 +664,16 @@ res += self.colorFormatLocalColor else: res += self.colorFormatLatinColor - for l in word: - if l in self.localLtr: + for letter in word: + if letter in self.localLtr: if not lastIsCyr: res += self.colorFormatLocalColor lastIsCyr = True - elif l in self.latLtr: + elif letter in self.latLtr: if lastIsCyr: res += self.colorFormatLatinColor lastIsCyr = False - res += l + res += letter return formatter.color_format(res + self.colorFormatSuffix)
def AddNoSuggestionTitle(self, title): diff --git a/scripts/imagecopy_self.py b/scripts/imagecopy_self.py index 885fc1c..4195a26 100644 --- a/scripts/imagecopy_self.py +++ b/scripts/imagecopy_self.py @@ -315,8 +315,8 @@ informationTemplate, informationFields, ] - for l in lists: - if not l.get(lang): + for item in lists: + if not item.get(lang): return False return True
diff --git a/scripts/interwiki.py b/scripts/interwiki.py index aceae76..9fd6a7d 100755 --- a/scripts/interwiki.py +++ b/scripts/interwiki.py @@ -1629,7 +1629,7 @@ # clone original newPages dictionary, so that we can modify it to the # local page's needs new = newPages.copy() - interwikis = [pywikibot.Page(l) for l in page.iterlanglinks()] + interwikis = [pywikibot.Page(link) for link in page.iterlanglinks()]
# remove interwiki links to ignore for iw in re.finditer(r'<!-- *\[\[(.*?:.*?)\]\] *-->', pagetext): @@ -1852,8 +1852,8 @@ page = new[site] if not page.section(): try: - linkedPages = {pywikibot.Page(l) - for l in page.iterlanglinks()} + linkedPages = {pywikibot.Page(link) + for link in page.iterlanglinks()} except pywikibot.NoPage: pywikibot.warning( 'Page {} does no longer exist?!'.format(page)) diff --git a/scripts/replicate_wiki.py b/scripts/replicate_wiki.py index a7cc7cd..9dc870f 100755 --- a/scripts/replicate_wiki.py +++ b/scripts/replicate_wiki.py @@ -39,7 +39,7 @@ destination_wiki destination wiki(s) """ # -# (C) Pywikibot team, 2012-2019 +# (C) Pywikibot team, 2012-2020 # # Distributed under the terms of the MIT license. # @@ -169,16 +169,16 @@ .format(site.user())) output = '== Pages that differ from original ==\n\n' if self.differences[site]: - output += ''.join('* [[:%s]]\n' % l for l in - self.differences[site]) + output += ''.join('* [[:{}]]\n'.format(page_title) + for page_title in self.differences[site]) else: output += 'All important pages are the same'
output += ( '\n\n== Admins from original that are missing here ==\n\n') if self.user_diff[site]: - output += ''.join('* %s\n' % l.replace('_', ' ') for l in - self.user_diff[site]) + output += ''.join('* {}\n'.format(user_name.replace('_', ' ')) + for user_name in self.user_diff[site]) else: output += ( 'All users from original are also present on this wiki') diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py index e40b9cf..be0c757 100755 --- a/scripts/solve_disambiguation.py +++ b/scripts/solve_disambiguation.py @@ -721,9 +721,9 @@ """ titles = {firstcap(t) for t in self.firstlinks(page)} links = list(links) - for l in links[:]: # uses a copy because of remove! - if l.title() not in titles: - links.remove(l) + for link in links[:]: # uses a copy because of remove! + if link.title() not in titles: + links.remove(link) return links
def treat_links(self, refPage, disambPage): @@ -1058,13 +1058,15 @@ links = disambPage2.linkedPages() if self.first_only: links = self.firstize(disambPage2, links) - links = [correctcap(l, disambPage2.get()) for l in links] + links = [correctcap(link, disambPage2.get()) + for link in links] except pywikibot.NoPage: pywikibot.output('No page at {0}, using redirect target.' .format(disambTitle)) links = disambPage.linkedPages()[:1] - links = [correctcap(l, disambPage.get(get_redirect=True)) - for l in links] + links = [correctcap(link, + disambPage.get(get_redirect=True)) + for link in links] self.alternatives += links else: try: @@ -1096,22 +1098,22 @@ links = disambPage2.linkedPages() if self.first_only: links = self.firstize(disambPage2, links) - links = [correctcap(l, disambPage2.get()) - for l in links] + links = [correctcap(link, disambPage2.get()) + for link in links] except pywikibot.NoPage: pywikibot.output( 'Page does not exist; using first ' 'link in page {0}.'.format(disambPage.title())) links = disambPage.linkedPages()[:1] - links = [correctcap(l, disambPage.get()) - for l in links] + links = [correctcap(link, disambPage.get()) + for link in links] else: try: links = disambPage.linkedPages() if self.first_only: links = self.firstize(disambPage, links) - links = [correctcap(l, disambPage.get()) - for l in links] + links = [correctcap(link, disambPage.get()) + for link in links] except pywikibot.NoPage: pywikibot.output('Page does not exist, skipping.') return False diff --git a/tests/api_tests.py b/tests/api_tests.py index 1f7bd33..851eb1c 100644 --- a/tests/api_tests.py +++ b/tests/api_tests.py @@ -689,8 +689,7 @@ """Test PropertyGenerator with prop 'info'.""" mainpage = self.get_mainpage() links = list(self.site.pagelinks(mainpage, total=10)) - titles = [l.title(with_section=False) - for l in links] + titles = [link.title(with_section=False) for link in links] gen = api.PropertyGenerator(site=self.site, prop='info', parameters={'titles': '|'.join(titles)}) @@ -707,8 +706,7 @@ """Test PropertyGenerator with prop 'revisions'.""" mainpage = self.get_mainpage() links = list(self.site.pagelinks(mainpage, total=10)) - titles = [l.title(with_section=False) - for l in links] + titles = [link.title(with_section=False) for link in links] gen = api.PropertyGenerator(site=self.site, prop='revisions', parameters={'titles': '|'.join(titles)}) @@ -727,8 +725,7 @@ """Test PropertyGenerator with prop 'revisions' and 'coordinates'.""" mainpage = self.get_mainpage() links = list(self.site.pagelinks(mainpage, total=10)) - titles = [l.title(with_section=False) - for l in links] + titles = [link.title(with_section=False) for link in links] gen = api.PropertyGenerator(site=self.site, prop='revisions|coordinates', parameters={'titles': '|'.join(titles)}) @@ -747,8 +744,7 @@ """Test PropertyGenerator with many limited props.""" mainpage = self.get_mainpage() links = list(self.site.pagelinks(mainpage, total=30)) - titles = [l.title(with_section=False) - for l in links] + titles = [link.title(with_section=False) for link in links] params = { 'rvprop': 'ids|flags|timestamp|user|comment|content', 'titles': '|'.join(titles)} @@ -775,8 +771,7 @@ """Test PropertyGenerator with many limited props and continuations.""" mainpage = self.get_mainpage() links = list(self.site.pagelinks(mainpage, total=30)) - titles = [l.title(with_section=False) - for l in links] + titles = [link.title(with_section=False) for link in links] gen = api.PropertyGenerator( site=self.site, prop='info|categoryinfo|langlinks|templates', parameters={'titles': '|'.join(titles)})
pywikibot-commits@lists.wikimedia.org