jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/753038 )
Change subject: [W0074] refactor loop by any() call ......................................................................
[W0074] refactor loop by any() call
Change-Id: I006a30786c22bd8f15b37d085c068760d3ca50f5 --- M pywikibot/page/__init__.py M scripts/replace.py 2 files changed, 6 insertions(+), 10 deletions(-)
Approvals: JJMC89: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py index 69df5ea..cf96533 100644 --- a/pywikibot/page/__init__.py +++ b/pywikibot/page/__init__.py @@ -734,9 +734,7 @@ static_keys = self.site.getmagicwords('staticredirect') text = self.get(get_redirect=True, force=force) if static_keys: - for key in static_keys: - if key in text: - return True + return any(key in text for key in static_keys) return False
def isCategoryRedirect(self) -> bool: diff --git a/scripts/replace.py b/scripts/replace.py index 4d7f372..12cf5fe 100755 --- a/scripts/replace.py +++ b/scripts/replace.py @@ -138,7 +138,7 @@ the top of the help. """ # -# (C) Pywikibot team, 2004-2021 +# (C) Pywikibot team, 2004-2022 # # Distributed under the terms of the MIT license. # @@ -467,9 +467,8 @@ :rtype: bool """ if 'text-contains' in self.exceptions: - for exc in self.exceptions['text-contains']: - if exc.search(text): - return True + return any(exc.search(text) + for exc in self.exceptions['text-contains']) return False
@@ -565,9 +564,8 @@ def isTextExcepted(self, original_text) -> bool: """Return True iff one of the exceptions applies for the given text.""" if 'text-contains' in self.exceptions: - for exc in self.exceptions['text-contains']: - if exc.search(original_text): - return True + return any(exc.search(original_text) + for exc in self.exceptions['text-contains']) return False
def apply_replacements(self, original_text, applied, page=None):
pywikibot-commits@lists.wikimedia.org