Page MenuHomePhabricator

Consider using "in" to compare many values
Closed, ResolvedPublic

Description

Introduction

To check if a variable is equal to one of many values, combine the values into a tuple and check if the variable is contained in it instead of checking for equality against each of the values. This is faster, less verbose, and more readable.

What to do:

Bad code like

if x == 1 or x == 2 or x == 3:
    do_something()

should be replaced to

if x in (1, 2, 3):
    do_something()
  • The PYL-R1714 issues are listed here

Important hints

Event Timeline

Xqt triaged this task as Low priority.May 10 2021, 12:28 PM
maynorc subscribed.

Hi, I'm new to the dev community here and would like to work on this task. Is the correct first step here to just claim the task?

Change 688629 had a related patch set uploaded (by Chris Maynor; author: Chris Maynor):

[pywikibot/core@master] Update many-values comparison with "in"

https://gerrit.wikimedia.org/r/688629

JJMC89 removed a project: Patch-For-Review.
JJMC89 subscribed.

Thank you!

Change 688629 merged by jenkins-bot:

[pywikibot/core@master] Update many-values comparison with "in"

https://gerrit.wikimedia.org/r/688629