dosisod / refurb

A tool for refurbishing and modernizing Python codebases
GNU General Public License v3.0
2.49k stars 54 forks source link

[Bug]: operator.contains has reversed operator. #316

Closed Skylion007 closed 11 months ago

Skylion007 commented 11 months ago

Has your issue already been fixed?

The Bug

I am upstreaming this issue from ruff (https://github.com/astral-sh/ruff/issues/9191), because I did not see any special handling for the operator.contains operand and the test case in this repo is also wrong.

f = lambda a, b: a in b

should be replaced by operator.contains according to rule 118

However, according to the documentation contains is actually equivalent to b in a!

This code snippet will show you that the operands are indeed reversed.

import functools
import operator
f = lambda a, b: a in b
print(functools.reduce(f, ["str", {"str"}]))
print(functools.reduce(operator.contains, ["str", {"str"}]))

Version Info

Technically from RUFF, but it's present on master.

Python Version

3.10

Config File

# N/A

Extra Info

None

dosisod commented 11 months ago

Thank you @Skylion007 for upstreaming this issue! I didn't catch this one, this is definitely a bug.

Let me know if you find any other Refurb-related issues in Ruff!