jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/586072 )
Change subject: [cleanup] Replace range objects with comparisons ......................................................................
[cleanup] Replace range objects with comparisons
This avoids creating a new object in memory when it can be replaced by integer comparisons.
Moreover, lookups run in constant time only in Python 3.
Also chain some comparisons in plural.py.
Change-Id: I85f883b485a926bbd4dd2c3c2e77c5d4f4582f10 --- M pywikibot/date.py M pywikibot/diff.py M pywikibot/plural.py M scripts/imagetransfer.py M scripts/weblinkchecker.py 5 files changed, 15 insertions(+), 15 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/date.py b/pywikibot/date.py index 578c213..fa0d800 100644 --- a/pywikibot/date.py +++ b/pywikibot/date.py @@ -2159,7 +2159,7 @@
def _format_limit_dom(days): """Return day of month format limit.""" - assert days in range(29, 32) + assert 29 <= days <= 31 return lambda v: 1 <= v <= days, 1, days + 1
diff --git a/pywikibot/diff.py b/pywikibot/diff.py index ad9cda7..002df37 100644 --- a/pywikibot/diff.py +++ b/pywikibot/diff.py @@ -472,7 +472,7 @@ hunk_list = [] rng_width = 18 for index, super_hunk in enumerate(super_hunks, start=1): - assert super_hunk.reviewed in range(-1, 2), \ + assert -1 <= super_hunk.reviewed <= 1, \ "The super hunk's review status is unknown." status = ' +-'[super_hunk.reviewed]
diff --git a/pywikibot/plural.py b/pywikibot/plural.py index 6c87a8a..dcca8f1 100644 --- a/pywikibot/plural.py +++ b/pywikibot/plural.py @@ -15,12 +15,12 @@ 0 if (n == 0) else 1 if (n == 1) else 2 if (n == 2) else - 3 if (n % 100 >= 3 and n % 100 <= 10) else - 4 if (n % 100 >= 11 and n % 100 <= 99) else + 3 if (3 <= (n % 100) <= 10) else + 4 if (11 <= (n % 100) <= 99) else 5}, 'cs': {'nplurals': 3, 'plural': lambda n: 0 if (n == 1) else - 1 if (n >= 2 and n <= 4) else + 1 if (2 <= n <= 4) else 2}, 'cy': {'nplurals': 4, 'plural': lambda n: 0 if (n == 1) else @@ -36,7 +36,7 @@ 'gd': {'nplurals': 4, 'plural': lambda n: 0 if (n == 1 or n == 11) else 1 if (n == 2 or n == 12) else - 2 if (n > 2 and n < 20) else + 2 if (2 < n < 20) else 3}, 'is': {'nplurals': 2, 'plural': lambda n: (n % 10 != 1 or n % 100 == 11)}, 'kw': {'nplurals': 4, 'plural': lambda n: @@ -53,7 +53,7 @@ 1 if (n != 0) else 2}, 'mk': {'nplurals': 2, 'plural': lambda n: - 0 if n == 1 or n % 10 == 1 else + 0 if n % 10 == 1 else 1}, 'mnk': {'nplurals': 3, 'plural': lambda n: 0 if (n == 0) else @@ -61,20 +61,20 @@ 2}, 'mt': {'nplurals': 4, 'plural': lambda n: 0 if (n == 1) else - 1 if (n == 0 or (n % 100 > 1 and n % 100 < 11)) else - 2 if (n % 100 > 10 and n % 100 < 20) else + 1 if (n == 0 or (1 < (n % 100) < 11)) else + 2 if (10 < (n % 100) < 20) else 3}, 'pl': {'nplurals': 3, 'plural': lambda n: 0 if (n == 1) else - 1 if (n % 10 in range(2, 5) and (n % 100 < 10 or n % 100 >= 20)) + 1 if (2 <= (n % 10) <= 4) and (n % 100 < 10 or n % 100 >= 20) else 2}, 'ro': {'nplurals': 3, 'plural': lambda n: 0 if (n == 1) else - 1 if (n == 0 or (n % 100 > 0 and n % 100 < 20)) else + 1 if (n == 0 or (0 < (n % 100) < 20)) else 2}, 'sk': {'nplurals': 3, 'plural': lambda n: 0 if (n == 1) else - 1 if (n >= 2 and n <= 4) else + 1 if (2 <= n <= 4) else 2}, 'sl': {'nplurals': 4, 'plural': lambda n: 0 if (n % 100 == 1) else @@ -101,5 +101,5 @@ ['be', 'bs', 'csb', 'hr', 'ru', 'sr', 'uk'], {'nplurals': 3, 'plural': lambda n: 0 if n % 10 == 1 and n % 100 != 11 else - 1 if n % 10 in range(2, 5) and (n % 100 < 10 or n % 100 >= 20) + 1 if (2 <= (n % 10) <= 4) and (n % 100 < 10 or n % 100 >= 20) else 2})) diff --git a/scripts/imagetransfer.py b/scripts/imagetransfer.py index ac72587..6c0b369 100755 --- a/scripts/imagetransfer.py +++ b/scripts/imagetransfer.py @@ -274,7 +274,7 @@ if not todo: break todo = int(todo) - if todo in range(len(imagelist)): + if 0 <= todo < len(imagelist): if (imagelist[todo].fileIsShared() and imagelist[todo].site.image_repository() == self.targetSite.image_repository()): diff --git a/scripts/weblinkchecker.py b/scripts/weblinkchecker.py index 93d3285..755e54a 100755 --- a/scripts/weblinkchecker.py +++ b/scripts/weblinkchecker.py @@ -559,7 +559,7 @@ # read the server's encoding, in case we need it later self.readEncodingFromResponse(self.response) # site down if the server status is between 400 and 499 - alive = self.response.status not in range(400, 500) + alive = not (400 <= self.response.status < 500) if self.response.status in self.HTTPignore: alive = False return alive, '{0} {1}'.format(self.response.status,
pywikibot-commits@lists.wikimedia.org