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

Avoid problematic uses of 'is' #112

Merged
merged 1 commit into from
Feb 13, 2020
Merged

Conversation

smcv
Copy link
Contributor

@smcv smcv commented Feb 12, 2020

The 'is' operator compares by object identity, which is not usually
what you want unless comparing with singleton objects like None.
Python 3.8 warns about suspicious uses of 'is' during byte-compilation.

As an implementation detail, CPython interns small integers, so
"1 + 1 is 2" is likely to be true, although this is not an API guarantee.

However, "field is 'comment'" is unlikely to be true, because CPython
allocates separate string objects for each instance of the same long
string.

The 'is' operator compares by object identity, which is not usually
what you want unless comparing with singleton objects like None.
Python 3.8 warns about suspicious uses of 'is' during byte-compilation.

As an implementation detail, CPython interns small integers, so
"1 + 1 is 2" is likely to be true, although this is not an API guarantee.

However, "field is 'comment'" is unlikely to be true, because CPython
allocates separate string objects for each instance of the same long
string.

Signed-off-by: Simon McVittie <[email protected]>
@multani multani merged commit f3ac68f into multani:master Feb 13, 2020
multani added a commit that referenced this pull request Feb 13, 2020
Merge remote-tracking branches 'smcv/explicit-gir-versions', 'smcv/pympd2-110', 'smcv/pygobject-args', 'smcv/no-deprecated-popup', 'smcv/desktop-keywords' and 'smcv/is-is-suspicious' into master
@multani
Copy link
Owner

multani commented Feb 13, 2020

Once more: thanks for the patch!

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