jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] W503 errors ......................................................................
[FIX] W503 errors
With a recent version of PEP8 (and thus flake8) binary operators (like and) are not allowed at the start of a line and instead at the end of the previous one. Double quotes in the affected lines too were changed.
Change-Id: I5d89afa1d7bd4711a80d8b6c831ee63afe440ef5 --- M generate_family_file.py M pywikibot/data/api.py M pywikibot/data/wikidataquery.py M pywikibot/page.py M pywikibot/pagegenerators.py M pywikibot/site.py M pywikibot/userinterfaces/win32_unicode.py M scripts/archivebot.py M scripts/category_redirect.py M scripts/commonscat.py M scripts/interwiki.py M scripts/solve_disambiguation.py M scripts/transferbot.py M scripts/unlink.py M tests/__init__.py M tests/aspects.py M tests/script_tests.py M tests/site_tests.py 18 files changed, 93 insertions(+), 100 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/generate_family_file.py b/generate_family_file.py index 28af939..fa4619b 100644 --- a/generate_family_file.py +++ b/generate_family_file.py @@ -143,8 +143,8 @@ print(wiki['prefix'], wiki['url']) do_langs = raw_input("Which languages do you want: ") self.langs = [wiki for wiki in self.langs - if wiki['prefix'] in do_langs - or wiki['url'] == w.iwpath] + if wiki['prefix'] in do_langs or + wiki['url'] == w.iwpath] else: self.langs = [wiki for wiki in self.langs if wiki[u'url'] == w.iwpath] diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index a84b08c..4433982 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -332,8 +332,8 @@ for mod in module_batch] else: params['modules'] = [mod for mod in module_batch - if mod not in self._query_modules - and mod not in self.root_modules] + if mod not in self._query_modules and + mod not in self.root_modules] params['querymodules'] = [mod for mod in module_batch if mod in self._query_modules]
@@ -818,8 +818,8 @@ self["assert"] = 'user' # make sure user is logged in
if (self.site.protocol() == 'http' and (config.use_SSL_always or ( - self.action == 'login' and config.use_SSL_onlogin)) - and self.site.family.name in config.available_ssl_project): + self.action == 'login' and config.use_SSL_onlogin)) and + self.site.family.name in config.available_ssl_project): self.site = EnableSSLSiteWrapper(self.site)
@classmethod @@ -1031,9 +1031,9 @@
def __str__(self): """Return a string representation.""" - return unquote(self.site.scriptpath() - + "/api.php?" - + self._http_param_string()) + return unquote(self.site.scriptpath() + + '/api.php?' + + self._http_param_string())
def __repr__(self): """Return internal representation.""" @@ -1267,10 +1267,10 @@ else: self.site._userinfo = result['query']['userinfo'] status = self.site._loginstatus # save previous login status - if (("error" in result - and result["error"]["code"].endswith("limit")) - or (status >= 0 - and self.site._userinfo['name'] != self.site._username[status])): + if (('error' in result and + result['error']['code'].endswith('limit')) or + (status >= 0 and + self.site._userinfo['name'] != self.site._username[status])): # user is no longer logged in (session expired?) # reset userinfo, then make user log in again del self.site._userinfo diff --git a/pywikibot/data/wikidataquery.py b/pywikibot/data/wikidataquery.py index 5ad6bed..b9fe073 100644 --- a/pywikibot/data/wikidataquery.py +++ b/pywikibot/data/wikidataquery.py @@ -316,8 +316,8 @@ if not self.isOrContainsOnlyTypes(item, [int, ItemPage]): raise TypeError("The item paramter must contain or be integer IDs " "or page.ItemPages") - elif (not self.isOrContainsOnlyTypes(forward, [int, PropertyPage]) - or not self.isOrContainsOnlyTypes(reverse, [int, PropertyPage])): + elif (not self.isOrContainsOnlyTypes(forward, [int, PropertyPage]) or + not self.isOrContainsOnlyTypes(reverse, [int, PropertyPage])): raise TypeError("The forward and reverse parameters must contain " "or be integer IDs or page.PropertyPages")
diff --git a/pywikibot/page.py b/pywikibot/page.py index 1befe68..1741107 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -218,8 +218,8 @@ target_family = config.family if forceInterwiki or \ (allowInterwiki and - (self.site.family.name != target_family - or self.site.code != target_code)): + (self.site.family.name != target_family or + self.site.code != target_code)): if self.site.family.name != target_family \ and self.site.family.name != self.site.code: title = u'%s:%s:%s' % (self.site.family.name, @@ -1559,8 +1559,8 @@ """ if hasattr(self, "_deletedRevs"): if timestamp in self._deletedRevs and ( - (not retrieveText) - or "content" in self._deletedRevs[timestamp]): + (not retrieveText) or + 'content' in self._deletedRevs[timestamp]): return self._deletedRevs[timestamp] for item in self.site.deletedrevs(self, start=timestamp, get_text=retrieveText, total=1): @@ -4521,13 +4521,13 @@ # * with 'relative' URLs. Forbid them explicitly.
if u'.' in t and ( - t == u'.' or t == u'..' - or t.startswith(u"./") - or t.startswith(u"../") - or u"/./" in t - or u"/../" in t - or t.endswith(u"/.") - or t.endswith(u"/..") + t == u'.' or t == u'..' or + t.startswith(u'./') or + t.startswith(u'../') or + u'/./' in t or + u'/../' in t or + t.endswith(u'/.') or + t.endswith(u'/..') ): raise pywikibot.InvalidTitle( u"(contains . / combinations): '%s'" diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py index 9a66176..a87a05a 100644 --- a/pywikibot/pagegenerators.py +++ b/pywikibot/pagegenerators.py @@ -469,8 +469,7 @@ if not fileLinksPageTitle: fileLinksPageTitle = i18n.input( 'pywikibot-enter-file-links-processing') - if fileLinksPageTitle.startswith(self.site.namespace(6) - + ":"): + if fileLinksPageTitle.startswith(self.site.namespace(6) + ':'): fileLinksPage = pywikibot.FilePage(self.site, fileLinksPageTitle) else: diff --git a/pywikibot/site.py b/pywikibot/site.py index 80c627c..ffedbaf 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -455,8 +455,8 @@ # int(None) raises TypeError; however, bool needs special handling. result = [NotImplemented if isinstance(ns, bool) else Namespace.lookup_name(ns, namespaces) - if isinstance(ns, basestring) - and not ns.lstrip('-').isdigit() else + if isinstance(ns, basestring) and + not ns.lstrip('-').isdigit() else namespaces[int(ns)] if int(ns) in namespaces else None for ns in identifiers] @@ -1702,10 +1702,9 @@ - blockinfo: present if user is blocked (dict)
""" - if (not hasattr(self, "_userinfo") - or "rights" not in self._userinfo - or self._userinfo['name'] - != self._username["sysop" in self._userinfo["groups"]]): + if (not hasattr(self, '_userinfo') or + 'rights' not in self._userinfo or + self._userinfo['name'] != self._username['sysop' in self._userinfo['groups']]): uirequest = api.Request( site=self, action="query", @@ -1788,8 +1787,8 @@ @rtype: C{set} of L{Namespace} """ # TODO: Integrate into _userinfo - if (force or not hasattr(self, "_useroptions") - or self.user() != self._useroptions['_name']): + if (force or not hasattr(self, '_useroptions') or + self.user() != self._useroptions['_name']): uirequest = api.Request( site=self, action="query", @@ -1806,8 +1805,8 @@ self._useroptions['_name'] = ( None if 'anon' in uidata['query']['userinfo'] else uidata['query']['userinfo']['name']) - return set(ns for ns in self.namespaces().values() if ns.id >= 0 - and self._useroptions['searchNs{0}'.format(ns.id)] in ['1', True]) + return set(ns for ns in self.namespaces().values() if ns.id >= 0 and + self._useroptions['searchNs{0}'.format(ns.id)] in ['1', True])
def assert_valid_iter_params(self, msg_prefix, start, end, reverse): """Validate iterating API parameters.""" @@ -3337,13 +3336,12 @@ if prefix: apgen.request["gapprefix"] = prefix if filterredir is not None: - apgen.request["gapfilterredir"] = (filterredir - and "redirects" - or "nonredirects") + apgen.request['gapfilterredir'] = ('redirects' if filterredir else + 'nonredirects') if filterlanglinks is not None: - apgen.request["gapfilterlanglinks"] = (filterlanglinks - and "withlanglinks" - or "withoutlanglinks") + apgen.request['gapfilterlanglinks'] = ('withlanglinks' + if filterlanglinks else + 'withoutlanglinks') if isinstance(minsize, int): apgen.request["gapminsize"] = str(minsize) if isinstance(maxsize, int): @@ -3602,8 +3600,8 @@ """ iuargs = dict(giutitle=image.title(withSection=False)) if filterredir is not None: - iuargs["giufilterredir"] = (filterredir and "redirects" - or "nonredirects") + iuargs['giufilterredir'] = ('redirects' if filterredir else + 'nonredirects') iugen = self._generator(api.PageGenerator, type_arg="imageusage", namespaces=namespaces, step=step, total=total, g_content=content, **iuargs) @@ -4893,8 +4891,8 @@ break else: # not chunked upload file_contents = f.read() - filetype = (mimetypes.guess_type(source_filename)[0] - or 'application/octet-stream') + filetype = (mimetypes.guess_type(source_filename)[0] or + 'application/octet-stream') additional_parameters = { 'mime_params': { 'file': (file_contents, diff --git a/pywikibot/userinterfaces/win32_unicode.py b/pywikibot/userinterfaces/win32_unicode.py index 64016f7..3e77812 100755 --- a/pywikibot/userinterfaces/win32_unicode.py +++ b/pywikibot/userinterfaces/win32_unicode.py @@ -83,8 +83,8 @@ def not_a_console(handle): if handle == INVALID_HANDLE_VALUE or handle is None: return True - return ((GetFileType(handle) & ~FILE_TYPE_REMOTE) != FILE_TYPE_CHAR - or GetConsoleMode(handle, byref(DWORD())) == 0) + return ((GetFileType(handle) & ~FILE_TYPE_REMOTE) != FILE_TYPE_CHAR or + GetConsoleMode(handle, byref(DWORD())) == 0)
old_stdin_fileno = None old_stdout_fileno = None diff --git a/scripts/archivebot.py b/scripts/archivebot.py index 993c454..e2508da 100644 --- a/scripts/archivebot.py +++ b/scripts/archivebot.py @@ -422,8 +422,8 @@ self.attributes[attr] = [value, out]
def saveables(self): - return [a for a in self.attributes if self.attributes[a][1] - and a != 'maxage'] + return [a for a in self.attributes if self.attributes[a][1] and + a != 'maxage']
def attr2text(self): return '{{%s\n%s\n}}' \ diff --git a/scripts/category_redirect.py b/scripts/category_redirect.py index af0aca3..c68c8c7 100755 --- a/scripts/category_redirect.py +++ b/scripts/category_redirect.py @@ -437,12 +437,12 @@ newredirs.sort() comment = i18n.twtranslate(self.site.code, self.maint_comment) self.log_page.text = (u"\n== %i-%02i-%02iT%02i:%02i:%02iZ ==\n" - % time.gmtime()[:6] - + u"\n".join(self.log_text) - + u"\n* New redirects since last report:\n" - + u"\n".join(newredirs) - + u"\n" + u"\n".join(self.problems) - + u"\n" + self.get_log_text()) + % time.gmtime()[:6] + + u'\n'.join(self.log_text) + + u'\n* New redirects since last report:\n' + + u'\n'.join(newredirs) + + u'\n' + u'\n'.join(self.problems) + + u'\n' + self.get_log_text()) self.log_page.save(comment) if self.edit_requests: edit_request_page.text = (self.edit_request_text diff --git a/scripts/commonscat.py b/scripts/commonscat.py index b078987..957983c 100755 --- a/scripts/commonscat.py +++ b/scripts/commonscat.py @@ -387,8 +387,8 @@ ipage = pywikibot.page.Page(ipageLink) pywikibot.log("Looking for template on %s" % (ipage.title())) try: - if(not ipage.exists() or ipage.isRedirectPage() - or ipage.isDisambig()): + if (not ipage.exists() or ipage.isRedirectPage() or + ipage.isDisambig()): continue commonscatLink = self.getCommonscatLink(ipage) if not commonscatLink: diff --git a/scripts/interwiki.py b/scripts/interwiki.py index f17bc0c..becd5de 100755 --- a/scripts/interwiki.py +++ b/scripts/interwiki.py @@ -1726,8 +1726,8 @@ for (site, page) in new.items(): # edit restriction for some templates on zh-wiki where # interlanguage keys are included by /doc subpage - smallWikiAllowed = not (page.site.sitename() == 'wikipedia:zh' - and page.namespace() == 10 and + smallWikiAllowed = not (page.site.sitename() == 'wikipedia:zh' and + page.namespace() == 10 and u'Country data' in page.title(withNamespace=False)) # edit restriction on is-wiki # https://is.wikipedia.org/wiki/Wikipediaspjall:V%C3%A9lmenni diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py index ed1c814..fad491e 100644 --- a/scripts/solve_disambiguation.py +++ b/scripts/solve_disambiguation.py @@ -660,12 +660,10 @@ if not self.always: # at the beginning of the link, start red color. # at the end of the link, reset the color to default - pywikibot.output(text[max(0, m.start() - context): - m.start()] - + '\03{lightred}' - + text[m.start():m.end()] - + '\03{default}' - + text[m.end():m.end() + context]) + pywikibot.output( + text[max(0, m.start() - context):m.start()] + + '\03{lightred}' + text[m.start():m.end()] + + '\03{default}' + text[m.end():m.end() + context]) options = ['#', 'r#', '[s]kip link', '[e]dit page', '[n]ext page', '[u]nlink', '[q]uit'] if self.dn_template_str: @@ -804,8 +802,8 @@ new_page_title = self.alternatives[choice] repPl = pywikibot.Page(pywikibot.Link(new_page_title, disambPage.site)) - if (new_page_title[0].isupper() - or link_text[0].isupper()): + if (new_page_title[0].isupper() or + link_text[0].isupper()): new_page_title = repPl.title() else: new_page_title = repPl.title() @@ -817,8 +815,8 @@ newlink = "[[%s%s]]%s" % (new_page_title, section, trailing_chars) - elif replaceit or (new_page_title == link_text - and not section): + elif replaceit or (new_page_title == link_text and + not section): newlink = "[[%s]]" % new_page_title # check if we can create a link with trailing characters # instead of a pipelink @@ -856,8 +854,8 @@
def findAlternatives(self, disambPage): if disambPage.isRedirectPage() and not self.primary: - if (disambPage.site.lang in self.primary_redir_template - and self.primary_redir_template[disambPage.site.lang] + if (disambPage.site.lang in self.primary_redir_template and + self.primary_redir_template[disambPage.site.lang] in disambPage.templates(get_redirect=True)): baseTerm = disambPage.title() for template in disambPage.templatesWithParams( diff --git a/scripts/transferbot.py b/scripts/transferbot.py index 599bc91..8b9cbcf 100644 --- a/scripts/transferbot.py +++ b/scripts/transferbot.py @@ -134,8 +134,7 @@ for page in gen: summary = "Moved page from %s" % page.title(asLink=True) targetpage = pywikibot.Page(tosite, prefix + page.title()) - edithistpage = pywikibot.Page(tosite, prefix + page.title() - + "/edithistory") + edithistpage = pywikibot.Page(tosite, prefix + page.title() + '/edithistory')
if targetpage.exists() and not overwrite: pywikibot.output( diff --git a/scripts/unlink.py b/scripts/unlink.py index de05fdd..403d626 100755 --- a/scripts/unlink.py +++ b/scripts/unlink.py @@ -99,9 +99,9 @@ choice = 'a' else: pywikibot.output( - text[max(0, match.start() - context):match.start()] - + '\03{lightred}' + text[match.start():match.end()] - + '\03{default}' + text[match.end():match.end() + context]) + text[max(0, match.start() - context):match.start()] + + '\03{lightred}' + text[match.start():match.end()] + + '\03{default}' + text[match.end():match.end() + context]) choice = pywikibot.input_choice( u'\nWhat shall be done with this link?\n', [('unlink', 'u'), ('skip', 's'), ('edit', 'e'), diff --git a/tests/__init__.py b/tests/__init__.py index 0f8012a..556162f 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -102,13 +102,13 @@ """List tests which are to be executed.""" dir_list = os.listdir(_tests_dir) all_test_list = [name[0:-9] for name in dir_list # strip '_tests.py' - if name.endswith('_tests.py') - and not name.startswith('_')] # skip __init__.py and _* + if name.endswith('_tests.py') and + not name.startswith('_')] # skip __init__.py and _*
unknown_test_modules = [name for name in all_test_list - if name not in library_test_modules - and name not in script_test_modules] + if name not in library_test_modules and + name not in script_test_modules]
return unknown_test_modules
diff --git a/tests/aspects.py b/tests/aspects.py index 8147a70..250ffb2 100644 --- a/tests/aspects.py +++ b/tests/aspects.py @@ -687,9 +687,9 @@ if 'family' in dct or 'code' in dct: dct['site'] = True
- if (('sites' not in dct or not len(dct['sites'])) - and 'family' in dct - and 'code' in dct and dct['code'] != '*'): + if (('sites' not in dct or not len(dct['sites'])) and + 'family' in dct and + 'code' in dct and dct['code'] != '*'): # Add entry to self.sites dct['sites'] = { str(dct['family'] + ':' + dct['code']): { diff --git a/tests/script_tests.py b/tests/script_tests.py index 6810a00..aea9dcc 100644 --- a/tests/script_tests.py +++ b/tests/script_tests.py @@ -68,9 +68,9 @@
script_list = (['login'] + [name[0:-3] for name in os.listdir(scripts_path) # strip '.py' - if name.endswith('.py') - and not name.startswith('_') # skip __init__.py and _* - and name != 'login.py' # this is moved to be first + if name.endswith('.py') and + not name.startswith('_') and # skip __init__.py and _* + name != 'login.py' # this is moved to be first ] )
@@ -181,17 +181,17 @@ tests = (['test__login_help'] + ['test_' + name + '_help' for name in sorted(script_list) - if name != 'login' - and name not in deadlock_script_list] + + if name != 'login' and + name not in deadlock_script_list] + ['test__login_simulate'])
tests += ['test_' + name + '_simulate' for name in sorted(script_list) - if name != 'login' - and name not in deadlock_script_list - and name not in failed_dep_script_list - and name not in unrunnable_script_list - and (enable_autorun_tests or name not in auto_run_script_list)] + if name != 'login' and + name not in deadlock_script_list and + name not in failed_dep_script_list and + name not in unrunnable_script_list and + (enable_autorun_tests or name not in auto_run_script_list)]
test_list = ['tests.script_tests.TestScript.' + name for name in tests] @@ -285,8 +285,8 @@ # But also complain if there is any stdout # but ignore shell.py emiting its '>>> ' prompt. if ((script_name == 'shell' and - set(result['stdout']).issubset(set('> \n'))) - or result['stdout'] == ''): + set(result['stdout']).issubset(set('> \n'))) or + result['stdout'] == ''): result['stdout'] = None self.assertIsNone(result['stdout'])
diff --git a/tests/site_tests.py b/tests/site_tests.py index b62bba7..b3ac597 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -971,8 +971,7 @@ self.assertLessEqual(len(uc), 10) self.assertTrue(all(isinstance(contrib, dict) for contrib in uc)) - self.assertTrue(all("user" in contrib - and contrib["user"] == mysite.user() + self.assertTrue(all('user' in contrib and contrib['user'] == mysite.user() for contrib in uc)) for contrib in mysite.usercontribs(userprefix="John", total=5): self.assertIsInstance(contrib, dict)