Skip to content

Conversation

@rzhao271
Copy link
Contributor

@rzhao271 rzhao271 commented Jul 29, 2023

% ruff rule PLR1714

repeated-equality-comparison-target (PLR1714)

Derived from the Pylint linter.

What it does

Checks for repeated equality comparisons that can be rewritten as a membership test.

Why is this bad?

To check if a variable is equal to one of many values, it is common to write a series of equality comparisons (e.g., foo == "bar" or foo == "baz").

Instead, prefer to combine the values into a collection and use the in operator to check for membership, which is more performant and succinct.
If the items are hashable, use a set for efficiency; otherwise, use a tuple.

Example

foo == "bar" or foo == "baz" or foo == "qux"

Use instead:

foo in {"bar", "baz", "qux"}

References

@cclauss
Copy link
Contributor

cclauss commented Jul 30, 2023

Please adjust https://github.com/nodejs/gyp-next/blob/main/pyproject.toml#L38 to make these changes permanent.

@cclauss
Copy link
Contributor

cclauss commented Jul 31, 2023

@rzhao271 The ruff rule PLR1714 above makes it simple to make the commit message self-documenting for those who do not have not yet memorized all rules. Especially helpful for project maintainers is the Why is this bad? section.

@rzhao271 rzhao271 requested a review from cclauss August 11, 2023 18:29
@rzhao271
Copy link
Contributor Author

@cclauss can the CI be restarted? The integration tests had an issue with finding the tarballs.

@rzhao271 rzhao271 closed this Aug 25, 2023
@rzhao271 rzhao271 reopened this Aug 25, 2023
@cclauss cclauss merged commit f6af11a into nodejs:main Aug 26, 2023
@rzhao271 rzhao271 deleted the rzhao271/lint-1714 branch August 26, 2023 00:12
@rzhao271 rzhao271 changed the title Fix PLR1714 lint errors fix: fix PLR1714 lint errors Aug 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants