jenkins-bot has submitted this change and it was merged.
Change subject: [flake8] Use flake8-comprehensions ......................................................................
[flake8] Use flake8-comprehensions
Change-Id: I77feb4036cb670d19e1bbbd6ea461fa858566901 --- M generate_family_file.py M pywikibot/data/api.py M pywikibot/date.py M pywikibot/page.py M pywikibot/tools/__init__.py M pywikibot/tools/formatter.py M pywikibot/version.py M scripts/casechecker.py M scripts/checkimages.py M scripts/data_ingestion.py M scripts/protect.py M tests/archivebot_tests.py M tox.ini 13 files changed, 55 insertions(+), 57 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 ddfe809..5505b69 100755 --- a/generate_family_file.py +++ b/generate_family_file.py @@ -9,7 +9,7 @@ print_function, unicode_literals) # # (C) Merlijn van Deen, 2010-2013 -# (C) Pywikibot team, 2010-2015 +# (C) Pywikibot team, 2010-2016 # # Distributed under the terms of the MIT license # @@ -81,7 +81,7 @@ print("Determining other languages...", end="") try: self.langs = w.langs - print(u' '.join(sorted([wiki[u'prefix'] for wiki in self.langs]))) + print(' '.join(sorted(wiki['prefix'] for wiki in self.langs))) except Exception as e: self.langs = [] print(e, "; continuing...") diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index 66c9aec..c3d95e8 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Interface to Mediawiki's api.php.""" # -# (C) Pywikibot team, 2007-2015 +# (C) Pywikibot team, 2007-2016 # # Distributed under the terms of the MIT license. # @@ -1049,8 +1049,8 @@ if not self._with_limits: self.fetch(self.submodules('query', True)) self._with_limits = frozenset( - [mod for mod in self.query_modules - if self.parameter('query+' + mod, 'limit')]) + mod for mod in self.query_modules + if self.parameter('query+' + mod, 'limit')) return self._with_limits
@@ -1907,8 +1907,8 @@ modules = set([self.action]) if modules: self.site._paraminfo.fetch(modules) - use_get = all(['mustbeposted' not in self.site._paraminfo[mod] - for mod in modules]) + use_get = all('mustbeposted' not in self.site._paraminfo[mod] + for mod in modules) else: # If modules is empty, just 'meta' was given, which doesn't # require POSTs, and is required for ParamInfo diff --git a/pywikibot/date.py b/pywikibot/date.py index 0592896..c3cb04c 100644 --- a/pywikibot/date.py +++ b/pywikibot/date.py @@ -7,7 +7,7 @@ # (C) Andre Engels, 2004-2005 # (C) Yuri Astrakhan, 2005-2006 (<Firstname><Lastname>@gmail.com) # (years/decades/centuries/millenniums str <=> int conversions) -# (C) Pywikibot team, 2004-2015 +# (C) Pywikibot team, 2004-2016 # # Distributed under the terms of the MIT license. # @@ -263,28 +263,28 @@
# Helper for KN: digits representation _knDigits = u'೦೧೨೩೪೫೬೭೮೯' -_knDigitsToLocal = dict([(ord(unicode(i)), _knDigits[i]) for i in range(10)]) -_knLocalToDigits = dict([(ord(_knDigits[i]), unicode(i)) for i in range(10)]) +_knDigitsToLocal = dict((ord(unicode(i)), _knDigits[i]) for i in range(10)) +_knLocalToDigits = dict((ord(_knDigits[i]), unicode(i)) for i in range(10))
# Helper for Urdu/Persian languages _faDigits = u'۰۱۲۳۴۵۶۷۸۹' -_faDigitsToLocal = dict([(ord(unicode(i)), _faDigits[i]) for i in range(10)]) -_faLocalToDigits = dict([(ord(_faDigits[i]), unicode(i)) for i in range(10)]) +_faDigitsToLocal = dict((ord(unicode(i)), _faDigits[i]) for i in range(10)) +_faLocalToDigits = dict((ord(_faDigits[i]), unicode(i)) for i in range(10))
# Helper for HI:, MR: _hiDigits = u'०१२३४५६७८९' -_hiDigitsToLocal = dict([(ord(unicode(i)), _hiDigits[i]) for i in range(10)]) -_hiLocalToDigits = dict([(ord(_hiDigits[i]), unicode(i)) for i in range(10)]) +_hiDigitsToLocal = dict((ord(unicode(i)), _hiDigits[i]) for i in range(10)) +_hiLocalToDigits = dict((ord(_hiDigits[i]), unicode(i)) for i in range(10))
# Helper for BN: _bnDigits = u'০১২৩৪৫৬৭৮৯' -_bnDigitsToLocal = dict([(ord(unicode(i)), _bnDigits[i]) for i in range(10)]) -_bnLocalToDigits = dict([(ord(_bnDigits[i]), unicode(i)) for i in range(10)]) +_bnDigitsToLocal = dict((ord(unicode(i)), _bnDigits[i]) for i in range(10)) +_bnLocalToDigits = dict((ord(_bnDigits[i]), unicode(i)) for i in range(10))
# Helper for GU: _guDigits = u'૦૧૨૩૪૫૬૭૮૯' -_guDigitsToLocal = dict([(ord(unicode(i)), _guDigits[i]) for i in range(10)]) -_guLocalToDigits = dict([(ord(_guDigits[i]), unicode(i)) for i in range(10)]) +_guDigitsToLocal = dict((ord(unicode(i)), _guDigits[i]) for i in range(10)) +_guLocalToDigits = dict((ord(_guDigits[i]), unicode(i)) for i in range(10))
def intToLocalDigitsStr(value, digitsToLocalDict): diff --git a/pywikibot/page.py b/pywikibot/page.py index 5c5f2e0..4a7f1b9 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -1958,7 +1958,7 @@ warn(u'"unprotect" argument of protect() is deprecated', DeprecationWarning, 2) protections = dict( - [(p_type, "") for p_type in self.applicable_protections()]) + (p_type, "") for p_type in self.applicable_protections()) answer = 'y' if called_using_deprecated_arg and prompt is None: prompt = True @@ -2160,7 +2160,7 @@ """ # WARNING: may not return all templates used in particularly # intricate cases such as template substitution - titles = list(t.title() for t in self.templates()) + titles = [t.title() for t in self.templates()] templates = textlib.extract_templates_and_params(self.text) # backwards-compatibility: convert the dict returned as the second # element into a list in the format used by old scripts diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py index 40f7320..e1642dd 100644 --- a/pywikibot/tools/__init__.py +++ b/pywikibot/tools/__init__.py @@ -560,8 +560,8 @@
def run(self): """Run the generator and store the results on the queue.""" - iterable = any([hasattr(self.generator, key) - for key in ['__iter__', '__getitem__']]) + iterable = any(hasattr(self.generator, key) + for key in ('__iter__', '__getitem__')) if iterable and not self.args and not self.kwargs: self.__gen = self.generator else: diff --git a/pywikibot/tools/formatter.py b/pywikibot/tools/formatter.py index c53d80a..47f6762 100644 --- a/pywikibot/tools/formatter.py +++ b/pywikibot/tools/formatter.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Module containing various formatting related utilities.""" # -# (C) Pywikibot team, 2015 +# (C) Pywikibot team, 2015-2016 # # Distributed under the terms of the MIT license. # @@ -70,7 +70,7 @@ colors = set(colors) # Dot.product of colors to create all possible combinations of foreground # and background colors. - colors |= set(['%s;%s' % (c1, c2) for c1 in colors for c2 in colors]) + colors |= set('%s;%s' % (c1, c2) for c1 in colors for c2 in colors)
def __init__(self): """Create new instance and store the stack depth.""" diff --git a/pywikibot/version.py b/pywikibot/version.py index 93b13af..bd4d841 100644 --- a/pywikibot/version.py +++ b/pywikibot/version.py @@ -483,12 +483,11 @@
std_lib_dir = get_python_lib(standard_lib=True)
- root_packages = set([key.split('.')[0] - for key in modules]) + root_packages = set(key.split('.')[0] for key in modules)
- builtin_packages = set([name.split('.')[0] for name in root_packages - if name in sys.builtin_module_names or - '_' + name in sys.builtin_module_names]) + builtin_packages = set(name.split('.')[0] for name in root_packages + if name in sys.builtin_module_names or + '_' + name in sys.builtin_module_names)
# Improve performance by removing builtins from the list if possible. if builtins is False: diff --git a/scripts/casechecker.py b/scripts/casechecker.py index 1daccca..925e0a9 100755 --- a/scripts/casechecker.py +++ b/scripts/casechecker.py @@ -172,22 +172,20 @@ self.titleList = [self.Page(t) for t in f] self.failedTitles += '.failed'
- self.lclToLatDict = dict([(ord(self.localSuspects[i]), - self.latinSuspects[i]) - for i in xrange(len(self.localSuspects))]) - self.latToLclDict = dict([(ord(self.latinSuspects[i]), - self.localSuspects[i]) - for i in xrange(len(self.localSuspects))]) + self.lclToLatDict = dict( + (ord(self.localSuspects[i]), self.latinSuspects[i]) + for i in xrange(len(self.localSuspects))) + self.latToLclDict = dict( + (ord(self.latinSuspects[i]), self.localSuspects[i]) + for i in xrange(len(self.localSuspects)))
if self.localKeyboard is not None: self.lclToLatKeybDict = dict( - [(ord(self.localKeyboard[i]), - self.latinKeyboard[i]) - for i in xrange(len(self.localKeyboard))]) + (ord(self.localKeyboard[i]), self.latinKeyboard[i]) + for i in xrange(len(self.localKeyboard))) self.latToLclKeybDict = dict( - [(ord(self.latinKeyboard[i]), - self.localKeyboard[i]) - for i in xrange(len(self.localKeyboard))]) + (ord(self.latinKeyboard[i]), self.localKeyboard[i]) + for i in xrange(len(self.localKeyboard))) else: self.lclToLatKeybDict = {} self.latToLclKeybDict = {} @@ -467,9 +465,9 @@ badWords = list(self.FindBadWords(title)) if len(badWords) > 0: # Allow known words, allow any roman numerals with local suffixes - badWords = set([i for i in badWords - if i not in self.knownWords and - self.romanNumSfxPtrn.match(i) is not None]) + badWords = set(i for i in badWords + if i not in self.knownWords and + self.romanNumSfxPtrn.match(i) is not None)
if len(badWords) == 0 or self.Page(title).isImage(): return diff --git a/scripts/checkimages.py b/scripts/checkimages.py index 02e9a0b..e8df222 100755 --- a/scripts/checkimages.py +++ b/scripts/checkimages.py @@ -548,8 +548,8 @@ self.com = i18n.translate(self.site, msg_comm10, fallback=True) hiddentemplatesRaw = i18n.translate(self.site, HiddenTemplate) self.hiddentemplates = set( - [pywikibot.Page(self.site, tmp, ns=self.site.namespaces.TEMPLATE) - for tmp in hiddentemplatesRaw]) + pywikibot.Page(self.site, tmp, ns=self.site.namespaces.TEMPLATE) + for tmp in hiddentemplatesRaw) self.pageHidden = i18n.translate(self.site, PageWithHiddenTemplates) self.pageAllowed = i18n.translate(self.site, PageWithAllowedTemplates) self.comment = i18n.twtranslate(self.site.lang, diff --git a/scripts/data_ingestion.py b/scripts/data_ingestion.py index 40516cf..836d1af 100755 --- a/scripts/data_ingestion.py +++ b/scripts/data_ingestion.py @@ -8,7 +8,7 @@ python pwb.py data_ingestion -csvdir:local_dir/ -page:config_page """ # -# (C) Pywikibot team, 2013 +# (C) Pywikibot team, 2013-2016 # # Distributed under the terms of the MIT license. # @@ -105,9 +105,8 @@ """ hashObject = hashlib.sha1() hashObject.update(self.downloadPhoto().getvalue()) - return list( - page.title(withNamespace=False) for page in - self.site.allimages(sha1=base64.b16encode(hashObject.digest()))) + return [page.title(withNamespace=False) for page in + self.site.allimages(sha1=base64.b16encode(hashObject.digest()))]
def getTitle(self, fmt): """ diff --git a/scripts/protect.py b/scripts/protect.py index 222f19e..4441241 100755 --- a/scripts/protect.py +++ b/scripts/protect.py @@ -235,8 +235,8 @@ protection_levels) # set the default value for all # None (not the string 'none') will be ignored by Site.protect() - combined_protections = dict([ - (p_type, default_level) for p_type in protection_types]) + combined_protections = dict( + (p_type, default_level) for p_type in protection_types) for p_type, level in protections.items(): level = check_protection_level(p_type, level, protection_levels, default_level) diff --git a/tests/archivebot_tests.py b/tests/archivebot_tests.py index 4cf2e43..467c4c1 100644 --- a/tests/archivebot_tests.py +++ b/tests/archivebot_tests.py @@ -40,8 +40,8 @@ """Test archivebot script on 40+ Wikipedia sites."""
family = 'wikipedia' - sites = dict([(code, {'family': 'wikipedia', 'code': code}) - for code in THREADS]) + sites = dict((code, {'family': 'wikipedia', 'code': code}) + for code in THREADS)
cached = True
@@ -107,8 +107,8 @@ """
family = 'wikipedia' - sites = dict([(code, {'family': 'wikipedia', 'code': code}) - for code in THREADS_WITH_UPDATED_FORMAT]) + sites = dict((code, {'family': 'wikipedia', 'code': code}) + for code in THREADS_WITH_UPDATED_FORMAT)
cached = True
diff --git a/tox.ini b/tox.ini index 10956ef..e87318d 100644 --- a/tox.ini +++ b/tox.ini @@ -56,6 +56,7 @@ flake8-docstrings>=0.2.6 flake8-putty>=0.3.2 flake8-coding + flake8-comprehensions flake8-future-import flake8-string-format flake8-import-order @@ -122,12 +123,13 @@ # H301,I100,I101: import order rules; Pywikibot uses rules H306 and I201
# The following are to be fixed +# C401, C402, C405: does not work with py 2.6 # D102: Missing docstring in public method # D103: Missing docstring in public function # E402: module level import not at top of file; see T87409 # H201: Except: format # P102,P103: string does contain unindexed parameters; see I36355923 -ignore = E402,D105,D211,FI10,FI12,FI13,FI15,FI16,FI17,FI5,H101,H201,H236,H301,H404,H405,I100,I101 +ignore = C401,C402,C405,E402,D105,D211,FI10,FI12,FI13,FI15,FI16,FI17,FI5,H101,H201,H236,H301,H404,H405,I100,I101 exclude = .tox,.git,./*.egg,ez_setup.py,build,externals,user-config.py,./scripts/i18n/* min-version = 2.6 max_line_length = 100
pywikibot-commits@lists.wikimedia.org