This is an archive of the discontinued LLVM Phabricator instance.

Fix use of 'is' operator for comparison
AbandonedPublic

Authored by tambre on May 4 2019, 2:02 AM.

Details

Reviewers
rsmith
Summary

The 'is' operator can't be used for comparisons except in specific cases. Currently the if is always False.
CPython 3.8 added a SyntaxWarning for cases where the usage is definitely wrong.

Diff Detail

Repository
rC Clang

Event Timeline

tambre created this revision.May 4 2019, 2:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2019, 2:02 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
j-carl added a subscriber: j-carl.Nov 15 2019, 9:36 AM

Gentle ping ... ArchLinux update to Python 3.8 and it's not possible to use clang-format.py from vim anymore.
Thanks

Jim added a subscriber: Jim.Dec 16 2019, 12:07 AM

@j-carl Could you give a Python 3.8 syntax reference for this change.

tambre edited the summary of this revision. (Show Details)Dec 16 2019, 7:15 AM
In D61549#1785369, @Jim wrote:

@j-carl Could you give a Python 3.8 syntax reference for this change.

This is not a language change in Python 3.8. AFAICT, the behaviour of is has been the same as long as Python has been in use.
CPython 3.8 only added the warning for incorrect usages where the result is always False, as in this case.

It's unclear to me why @j-carl thinks this change might resolve this. This behaviour should be consistent across at least Python 2.7–3.8.

I'm also unsure why this has yet to be reviewed and how might I get someone to do that.

In D61549#1785369, @Jim wrote:

@j-carl Could you give a Python 3.8 syntax reference for this change.

As @tambre mentioned it's not a language change, but information about the change can be found here https://bugs.python.org/issue34850.

The problem I face with the vim integration is that vim stops the execution of the script and shows a warning:

/usr/share/clang/clang-format.py:123: SyntaxWarning: "is not" with a literal. Did you mean "!="?                                                      
  if op[0] is not 'equal':
Press ENTER or type command to continue

Now I have to press ENTER to get the script running. This adds another key stroke to my workflow.

tambre abandoned this revision.Apr 3 2020, 2:24 AM