Fix incorrect use of 'is' operator for comparison in python/lib/gdb/command/prompt.py

Message ID 7c5b3290-fb75-20b0-08e4-c8cb305d9c4c@tambre.ee
State New
Headers show
Series
  • Fix incorrect use of 'is' operator for comparison in python/lib/gdb/command/prompt.py
Related show

Commit Message

Christian Biesinger via gdb-patches May 4, 2019, 10:25 a.m.
Noticed this while searching for similar issues in the Chromium codebase.
Hopefully I managed to format the patch correctly.
Fix incorrect use of 'is' operator for comparison in python/lib/gdb/command/prompt.py

The 'is' operator is not meant to be used for comparisons. It currently working is an implementation detail of CPython.
CPython 3.8 has added a SyntaxWarning for this.

gdb/ChangeLog:

2019-05-04  Raul Tambre <raul@tambre.ee>

	* python/lib/gdb/prompt.py: Fix incorrect use of 'is' operator for
	comparison.

---
 gdb/python/lib/gdb/command/prompt.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Simon Marchi May 4, 2019, 7:56 p.m. | #1
On 2019-05-04 6:25 a.m., Raul Tambre via gdb-patches wrote:
> Noticed this while searching for similar issues in the Chromium codebase.

> Hopefully I managed to format the patch correctly.


Good catch, thanks!  I have pushed the patch, it is small enough not to require
a copyright assignment.

The patch was correctly formatted, I was able to git-apply it as-is.  How did you
generate it?  The most reliable way is to use git-send-email, which sends the patch
directly as an email, or as a second choice git-format-patch, which produces a .patch
file that you can then attach.  The patches produced by these two commands can be
easily applied by the person on the other side using git-am.

Simon

Patch

diff --git a/gdb/python/lib/gdb/command/prompt.py b/gdb/python/lib/gdb/command/prompt.py
index 3d662a7d..04b9e49c 100644
--- a/gdb/python/lib/gdb/command/prompt.py
+++ b/gdb/python/lib/gdb/command/prompt.py
@@ -45,7 +45,7 @@  The currently defined substitutions are:
         self.hook_set = False
 
     def get_show_string (self, pvalue):
-        if self.value is not '':
+        if self.value:
            return "The extended prompt is: " + self.value
         else:
            return "The extended prompt is not set."
@@ -57,7 +57,7 @@  The currently defined substitutions are:
         return ""
 
     def before_prompt_hook(self, current):
-        if self.value is not '':
+        if self.value:
             return gdb.prompt.substitute_prompt(self.value)
         else:
             return None