Repository navigation
fix: Comparison using is when operands support __eq__ - #17864
Conversation
Comparison using 'is' when equivalence is not the same as identity When you compare two values using the is or is not operator, it is the object identities of the two values that is tested rather than their equality. If the class of either of the values in the comparison redefines equality then the is operator may return False even though the objects compare as equal. Equality is defined by the __eq__ or, in Python2, __cmp__ method. To compare two objects for equality, use the == or != operator instead. Recommendation When you want to compare the value of two literals, use the comparison operator == or != in place of is or is not. If the uniqueness property or performance are important then use an object that does not redefine equality.
|
💖 Thanks for opening this pull request! 💖 We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix. Examples of commit messages with semantic prefixes:
Things that will help get your PR across the finish line:
We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can. |
There was a problem hiding this comment.
@MatheusRV please update your PR to conform to our expected PR format; it's missing 1) semantic commit prefix and 2) a release notes description section which would have been found in our PR template (in this case you can just add Notes: none at the bottom)
Comparison using 'is' when equivalence is not the same as identity When you compare two values using the is or is not operator, it is the object identities of the two values that is tested rather than their equality. If the class of either of the values in the comparison redefines equality then the is operator may return False even though the objects compare as equal. Equality is defined by the __eq__ or, in Python2, __cmp__ method. To compare two objects for equality, use the == or != operator instead. Recommendation When you want to compare the value of two literals, use the comparison operator == or != in place of is or is not. If the uniqueness property or performance are important then use an object that does not redefine equality.
|
Done, sorry. |
Python deduplicates small integers (<= 256) so |
|
No Release Notes |
|
Congrats on merging your first pull request! 🎉🎉🎉 |
Comparison using 'is' when equivalence is not the same as identity
When you compare two values using the is or is not operator, it is the object identities of the two values that is tested rather than their equality. If the class of either of the values in the comparison redefines equality then the is operator may return False even though the objects compare as equal. Equality is defined by the eq or, in Python2, cmp method. To compare two objects for equality, use the == or != operator instead.
Recommendation
When you want to compare the value of two literals, use the comparison operator == or != in place of is or is not.
If the uniqueness property or performance are important then use an object that does not redefine equality.
Notes: none