Skip to content

Commit

Permalink
Update metadata for literal-or-new-object-identity
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Feb 2, 2024
1 parent 964780f commit 12dee0a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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.
The `is` and `is not` operators only evaluate to `True` when the expressions on each side have the same `id`. In other words, `a is b` is equivalent to `id(a) == id(b)`. With few exceptions, objects and literals have unique identities and thus shouldn't generally be compared by using the `is` or `is not` operators.

Our changes look something like this:

Expand Down
5 changes: 2 additions & 3 deletions src/core_codemods/literal_or_new_object_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
class LiteralOrNewObjectIdentityTransformer(
LibcstResultTransformer, NameAndAncestorResolutionMixin
):

change_description = "Replaces is operator with =="
change_description = "Replace `is` operator with `==`"

def _is_object_creation_or_literal(self, node: cst.BaseExpression):
match node:
Expand Down Expand Up @@ -80,7 +79,7 @@ def leave_Comparison(
LiteralOrNewObjectIdentity = CoreCodemod(
metadata=Metadata(
name="literal-or-new-object-identity",
summary="Replaces is operator with == for literal or new object comparisons",
summary="Replace `is` with `==` for literal or new object comparisons",
review_guidance=ReviewGuidance.MERGE_WITHOUT_REVIEW,
references=[
Reference(
Expand Down

0 comments on commit 12dee0a

Please sign in to comment.