jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/612152 )

Change subject: [cleanup] Drop unnecessary calls to list
......................................................................

[cleanup] Drop unnecessary calls to list

- avoid loading whole views in memory when O(1) lookup
  is possible
- use sorted, reversed and list.extend
- use list comprehension and set in translateMagicWords

Change-Id: I5deb2a32918b39d3f382ed33ab738781c9ff7cd9
---
M pywikibot/config2.py
M pywikibot/cosmetic_changes.py
M pywikibot/i18n.py
M pywikibot/page/__init__.py
M pywikibot/pagegenerators.py
M pywikibot/site/__init__.py
M pywikibot/textlib.py
7 files changed, 13 insertions(+), 15 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index d74c505..fe01116 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -1169,9 +1169,7 @@
             _all = False
         else:
             warning('Unknown arg {0} ignored'.format(_arg))
-    _k = list(globals().keys())
-    _k.sort()
-    for _name in _k:
+    for _name in sorted(globals().keys()):
         if _name[0] != '_':
             if not type(globals()[_name]) in [types.FunctionType,
                                               types.ModuleType]:
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index e8dc359..b0abb56 100755
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -451,13 +451,13 @@
                                   'img_right', 'img_none', 'img_framed',
                                   'img_frameless', 'img_border', 'img_upright',
                                   ]:
-                    aliases = list(self.site.getmagicwords(magicword))
-                    preferred = aliases.pop(0)
+                    aliases = self.site.getmagicwords(magicword)
+                    preferred = aliases[0]
+                    aliases = set(aliases[1:])
                     if not aliases:
                         continue
-                    split[1:] = list(map(
-                        lambda x: preferred if x.strip() in aliases else x,
-                        split[1:]))
+                    split[1:] = [preferred if x.strip() in aliases else x
+                                 for x in split[1:]]
                 return '|'.join(split) + ']]'

             exceptions = ['nowiki', 'comment', 'math', 'pre', 'source']
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 99f5d40..cff155a 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -608,7 +608,7 @@
         if fallback is True:
             codes += _altlang(code) + ['_default', 'en']
         elif fallback is not False:
-            codes += list(fallback)
+            codes.extend(fallback)
         for code in codes:
             if code in xdict:
                 trans = xdict[code]
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 54695ec..a45192b 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -1337,12 +1337,12 @@
         if config.cosmetic_changes_mylang_only:
             cc = ((family == config.family
                    and self.site.lang == config.mylang)
-                  or family in list(config.cosmetic_changes_enable.keys())
+                  or family in config.cosmetic_changes_enable
                   and self.site.lang in config.cosmetic_changes_enable[family])
         else:
             cc = True
         cc = (cc and not
-              (family in list(config.cosmetic_changes_disable.keys())
+              (family in config.cosmetic_changes_disable
                and self.site.lang in config.cosmetic_changes_disable[family]))
         if not cc:
             return summary
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index a37e88b..b15f73b 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -2180,7 +2180,7 @@
                     break
             pywikibot.sleep(sleep_duration)

-        yield from list(filtered_generator())[::-1]
+        yield from reversed(filtered_generator())


 @deprecated_args(pageNumber='groupsize', step='groupsize', lookahead=None)
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index 0beb08d..ea208a0 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -759,7 +759,7 @@
                 pywikibot.log('Site %s instantiated and marked "obsolete" '
                               'to prevent access' % self)
         elif self.__code not in self.languages():
-            if self.__family.name in list(self.__family.langs.keys()) and \
+            if self.__family.name in self.__family.langs and \
                len(self.__family.langs) == 1:
                 self.__code = self.__family.name
                 if self.__family == pywikibot.config.family \
@@ -3686,7 +3686,7 @@
                         namespaces=namespaces,
                         content=content
                     )
-            return itertools.chain(*list(genlist.values()))
+            return itertools.chain(*genlist.values())
         return blgen

     @deprecated_args(step=None, filterRedirects='filter_redirects')
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index f233926..9c74eb2 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -998,7 +998,7 @@
         # language, or if it's e.g. a category tag or an internal link
         if lang in fam.obsolete:
             lang = fam.obsolete[lang]
-        if lang in list(fam.langs.keys()):
+        if lang in fam.langs:
             if '|' in pagetitle:
                 # ignore text after the pipe
                 pagetitle = pagetitle[:pagetitle.index('|')]

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/612152
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I5deb2a32918b39d3f382ed33ab738781c9ff7cd9
Gerrit-Change-Number: 612152
Gerrit-PatchSet: 2
Gerrit-Owner: Matěj Suchánek <[email protected]>
Gerrit-Reviewer: Isaacandy <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to