Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaces is operator with == for literal or new object comparisons #9

Conversation

pixeebot[bot]
Copy link
Contributor

@pixeebot pixeebot bot commented Feb 1, 2024

The is and is not operator will only return True when the expression have the same id. In other words, a is b is equivalent to id(a) == id(b). New objects and literals have their own identities and thus shouldn't be compared with using the is or is not operators.

Our changes look something like this:

def foo(l):
-    return l is [1,2,3]
+    return l == [1,2,3]
More reading

I have additional improvements ready for this repo! If you want to see them, leave the comment:

@pixeebot next

... and I will open a new PR right away!

Powered by: pixeebot (codemod ID: pixee:python/literal-or-new-object-identity)

@pixeebot pixeebot bot mentioned this pull request Feb 1, 2024
@JLLeitschuh JLLeitschuh merged commit a9ad037 into master Feb 1, 2024
1 of 2 checks passed
@JLLeitschuh JLLeitschuh deleted the pixeebot/drip-2024-02-01-pixee-python/literal-or-new-object-identity branch February 1, 2024 04:00
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