Skip to content

Avoid "is" and "is not" for literal comparisons#101

Merged
adriank merged 1 commit intoadriank:masterfrom
turettn:is_literal_warnings
Aug 12, 2020
Merged

Avoid "is" and "is not" for literal comparisons#101
adriank merged 1 commit intoadriank:masterfrom
turettn:is_literal_warnings

Conversation

@turettn
Copy link
Copy Markdown
Contributor

@turettn turettn commented Aug 12, 2020

Starting with python 3.8, using is or is not to compare with a literal throws a SyntaxWarning.

All the details can be found here:

https://adamj.eu/tech/2020/01/21/why-does-python-3-8-syntaxwarning-for-is-literal/

This commit replaces the identity check with an equality check.

Starting with python 3.8, using `is` or `is not` to compare with a
literal throws a SyntaxWarning.

All the details can be found here:

https://adamj.eu/tech/2020/01/21/why-does-python-3-8-syntaxwarning-for-is-literal/

This commit replaces the identity check with an equality check.
@coveralls
Copy link
Copy Markdown

coveralls commented Aug 12, 2020

Coverage Status

Coverage remained the same at 89.557% when pulling 0230180 on turettn:is_literal_warnings into 445744a on adriank:master.

@adriank
Copy link
Copy Markdown
Owner

adriank commented Aug 12, 2020 via email

@turettn
Copy link
Copy Markdown
Contributor Author

turettn commented Aug 12, 2020

This seems to go back to at least Python 2.0:

 The operators is and is not test for object identity: x is y is true if and only if x and y are the same object. x is not y yields the inverse truth value. 

Depending on your implementation of python, is may behave like a value + type check, but it's not guaranteed to.

@adriank adriank merged commit 2595895 into adriank:master Aug 12, 2020
@turettn turettn deleted the is_literal_warnings branch August 12, 2020 20:45
@niksite
Copy link
Copy Markdown

niksite commented Apr 9, 2021

@adriank Any chance to have this fix as a new version?

@adriank
Copy link
Copy Markdown
Owner

adriank commented Apr 11, 2021

This PR was merged almost a year ago. Have you found other occurrences of is/is not in the code?

@niksite
Copy link
Copy Markdown

niksite commented Apr 12, 2021

This PR was merged almost a year ago. Have you found other occurrences of is/is not in the code?

I am using 0.6.1 version of the objectpath which is the latest one available on pypi and it seems this fix is not included.

@cgurnik
Copy link
Copy Markdown

cgurnik commented Nov 1, 2022

@adriank Could you release a new version on PyPI that contains this change?

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.

5 participants