]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use is/is not to check for None in python code.
authorLancelot SIX <lsix@lancelotsix.com>
Mon, 7 Jun 2021 22:14:55 +0000 (23:14 +0100)
committerLancelot SIX <lsix@lancelotsix.com>
Tue, 8 Jun 2021 22:49:05 +0000 (23:49 +0100)
While reviewing a patch sent to the mailing list, I noticed there are few
places where python code checks if a variable is 'None' or not by using the
comparison operators '==' and '!='.  PEP8[1], which is used as coding standard
in GDB coding standards, recommends using 'is' / 'is not' when comparing to a
singleton such as 'None'.

This patch proposes to change the instances of '== None' by 'is None' and
'!= None' by 'is not None'.

[1] https://www.python.org/dev/peps/pep-0008/

gdb/doc/ChangeLog:

* python.texi (Writing a Pretty-Printer): Use 'is None' instead of
'== None'.

gdb/ChangeLog:

* python/lib/gdb/FrameDecorator.py (FrameDecorator): Use 'is None' instead of
'== None'.
(FrameVars): Use 'is not None' instead of '!= None'.
* python/lib/gdb/command/frame_filters.py (SetFrameFilterPriority): Use 'is None'
instead of '== None' and 'is not None' instead of '!= None'.

gdb/testsuite/ChangeLog:

* gdb.base/premature-dummy-frame-removal.py (TestUnwinder): Use
'is None' instead of '== None' and 'is not None' instead of
'!= None'.
* gdb.python/py-frame-args.py (lookup_function): Same.
* gdb.python/py-framefilter-invalidarg.py (Reverse_Function): Same.
* gdb.python/py-framefilter.py (Reverse_Function): Same.
* gdb.python/py-nested-maps.py (lookup_function): Same.
* gdb.python/py-objfile-script-gdb.py (lookup_function): Same.
* gdb.python/py-prettyprint.py (lookup_function): Same.
* gdb.python/py-section-script.py (lookup_function): Same.
* gdb.python/py-unwind-inline.py (dummy_unwinder): Same.
* gdb.python/python.exp: Same.
* gdb.rust/pp.py (lookup_function): Same.

17 files changed:
gdb/ChangeLog
gdb/doc/ChangeLog
gdb/doc/python.texi
gdb/python/lib/gdb/FrameDecorator.py
gdb/python/lib/gdb/command/frame_filters.py
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/premature-dummy-frame-removal.py
gdb/testsuite/gdb.python/py-frame-args.py
gdb/testsuite/gdb.python/py-framefilter-invalidarg.py
gdb/testsuite/gdb.python/py-framefilter.py
gdb/testsuite/gdb.python/py-nested-maps.py
gdb/testsuite/gdb.python/py-objfile-script-gdb.py
gdb/testsuite/gdb.python/py-prettyprint.py
gdb/testsuite/gdb.python/py-section-script.py
gdb/testsuite/gdb.python/py-unwind-inline.py
gdb/testsuite/gdb.python/python.exp
gdb/testsuite/gdb.rust/pp.py

index 05c307bd303882fa7b8390d66a8db1d728c330b7..36cb4c9e7e9ed6e7ad05c22fab64c59a8c96db81 100644 (file)
@@ -1,3 +1,12 @@
+2021-06-08  Lancelot Six  <lsix@lancelotsix.com>
+
+       * python/lib/gdb/FrameDecorator.py (FrameDecorator): Use 'is None'
+       instead of '== None'.
+       (FrameVars): Use 'is not None' instead of '!= None'.
+       * python/lib/gdb/command/frame_filters.py (SetFrameFilterPriority):
+       Use 'is None' instead of '== None' and 'is not None' instead of '!=
+       None'.
+
 2021-06-08  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * inferior.h (class inferior) <in_initial_library_scan>: New.
index 61d40b92e639f044f8edbe291871ad40f30ace80..80b9f44ad3c6f357d665a274ea9aebe071f0b813 100644 (file)
@@ -1,3 +1,8 @@
+2021-06-08  Lancelot Six  <lsix@lancelotsix.com>
+
+       * python.texi (Writing a Pretty-Printer): Use 'is None' instead of
+       '== None'.
+
 2021-06-05  Shahab Vahedi  <shahab@synopsys.com>
 
        * gdb.texinfo (Source and Machine Code): Document 'set
index 7b7f0692b3a5fff160b6959d84c81fed8c2079de..ab934a8c0127c38ad1aca387d589c35eccd2a550 100644 (file)
@@ -1661,7 +1661,7 @@ example above might be written.
 @smallexample
 def str_lookup_function(val):
     lookup_tag = val.type.tag
-    if lookup_tag == None:
+    if lookup_tag is None:
         return None
     regex = re.compile("^std::basic_string<char,.*>$")
     if regex.match(lookup_tag):
index 1f4b2cab6eccac80433d77924c2545b34b467303..69a0a9a4d7fa2d51e9048f38aa8abd11ebc3797f 100644 (file)
@@ -117,7 +117,7 @@ class FrameDecorator(object):
         # address.  If GDB detects an integer value from this function
         # it will attempt to find the function name from minimal
         # symbols via its own internal functions.
-        if func == None:
+        if func is None:
             pc = frame.pc()
             return pc
 
@@ -270,7 +270,7 @@ class FrameVars(object):
         except RuntimeError:
             block = None
 
-        while block != None:
+        while block is not None:
             if block.is_global or block.is_static:
                 break
             for sym in block:
@@ -295,12 +295,12 @@ class FrameVars(object):
         except RuntimeError:
             block = None
 
-        while block != None:
-            if block.function != None:
+        while block is not None:
+            if block.function is not None:
                 break
             block = block.superblock
 
-        if block != None:
+        if block is not None:
             for sym in block:
                 if not sym.is_argument:
                     continue
index 91e8ca2d43c9674a0bf7c2aacffe407f592a7567..97488ca2c3dd2b29de20b4b2dc731b035191a25e 100644 (file)
@@ -372,7 +372,7 @@ class SetFrameFilterPriority(gdb.Command):
 
     def invoke(self, arg, from_tty):
         command_tuple = self._parse_pri_arg(arg)
-        if command_tuple != None:
+        if command_tuple is not None:
             self._set_filter_priority(command_tuple)
 
 
@@ -453,7 +453,7 @@ class ShowFrameFilterPriority(gdb.Command):
 
     def invoke(self, arg, from_tty):
         command_tuple = self._parse_pri_arg(arg)
-        if command_tuple == None:
+        if command_tuple is None:
             return
         filter_name = command_tuple[1]
         list_name = command_tuple[0]
index 51abd0e0cffc4ccce3fc98269376aa38c0f66a3f..92894d6efab418abfd0fe8c7c45e75ce5cb32a5f 100644 (file)
@@ -1,3 +1,19 @@
+2021-06-08  Lancelot Six  <lsix@lancelotsix.com>
+
+       * gdb.base/premature-dummy-frame-removal.py (TestUnwinder): Use
+       'is None' instead of '== None' and 'is not None' instead of
+       '!= None'.
+       * gdb.python/py-frame-args.py (lookup_function): Same.
+       * gdb.python/py-framefilter-invalidarg.py (Reverse_Function): Same.
+       * gdb.python/py-framefilter.py (Reverse_Function): Same.
+       * gdb.python/py-nested-maps.py (lookup_function): Same.
+       * gdb.python/py-objfile-script-gdb.py (lookup_function): Same.
+       * gdb.python/py-prettyprint.py (lookup_function): Same.
+       * gdb.python/py-section-script.py (lookup_function): Same.
+       * gdb.python/py-unwind-inline.py (dummy_unwinder): Same.
+       * gdb.python/python.exp: Same.
+       * gdb.rust/pp.py (lookup_function): Same.
+
 2021-06-08  Tom de Vries  <tdevries@suse.de>
 
        * lib/gdb.exp (multi_line): Require more than one argument.
index 31936658788abe6cc3b9617ce2cdad3dcf671ca2..fbad6d447d3733aab2684474f2a02a5c45aa00a4 100644 (file)
@@ -46,10 +46,10 @@ class TestUnwinder(Unwinder):
         sp = pending_frame.read_register(sp_desc)
 
         block = gdb.block_for_pc(int(pc))
-        if block == None:
+        if block is None:
             return None
         func = block.function
-        if func == None:
+        if func is None:
             return None
         if str(func) != "break_bt_here":
             return None
index 32d7204a5bd5ad999106ab3918b789e68de52bc1..59dd14d0b56540e3361ae64032512518097a3591 100644 (file)
@@ -53,7 +53,7 @@ def lookup_function(val):
 
     # Get the type name.
     typename = type.tag
-    if typename == None:
+    if typename is None:
         return None
 
     # Iterate over local dictionary of types to determine
index 609ff80a88f5d52a29bda23c8a7b121a16906193..20af5169525e4eed2a6590efbfdd6c6592813a78 100644 (file)
@@ -28,7 +28,7 @@ class Reverse_Function(FrameDecorator):
 
     def function(self):
         fname = str(self.fobj.function())
-        if fname == None or fname == "":
+        if not fname:
             return None
         if fname == "end_func":
             extra = self.fobj.inferior_frame().read_var("str").string()
index ce5a35d17a98645fc96d75f02c9a4898d49fc1c7..8058f6186c54f914c2f608b4cd5bbfec9e550da4 100644 (file)
@@ -28,7 +28,7 @@ class Reverse_Function(FrameDecorator):
 
     def function(self):
         fname = str(self.fobj.function())
-        if fname == None or fname == "":
+        if not fname:
             return None
         if fname == "end_func":
             extra = self.fobj.inferior_frame().read_var("str").string()
index 163fc865866c603c0de8ea08330dbbe2b84bd6c4..2848347c56aed3952091fb35bffa11ed58ebff23 100644 (file)
@@ -88,7 +88,7 @@ def lookup_function(val):
     # Get the type name.
     typename = type.tag
 
-    if typename == None:
+    if typename is None:
         return None
 
     # Iterate over local dictionary of types to determine
@@ -109,7 +109,7 @@ def lookup_typedefs_function(val):
     # Get the type.
     type = val.type
 
-    if type == None or type.name == None or type.code != gdb.TYPE_CODE_TYPEDEF:
+    if type is None or type.name is None or type.code != gdb.TYPE_CODE_TYPEDEF:
         return None
 
     # Iterate over local dictionary of typedef types to determine if a
index 88372e41a19278d4f39a2e76773d021325bf676e..45d036ccf0b74bf4e964772ae4ab43e55a5a3b21 100644 (file)
@@ -42,7 +42,7 @@ def lookup_function(val):
     # Get the type name.
     typename = type.tag
 
-    if typename == None:
+    if typename is None:
         return None
 
     # Iterate over local dictionary of types to determine
index 84dbc3ba3a4e666f52bed78fc54bef51a0f5f52c..89ffc0f8d1878feef19f0c48eec5db18f75156d7 100644 (file)
@@ -314,7 +314,7 @@ def lookup_function(val):
     # Get the type name.
     typename = type.tag
 
-    if typename == None:
+    if typename is None:
         return None
 
     # Iterate over local dictionary of types to determine
@@ -344,7 +344,7 @@ def lookup_typedefs_function(val):
     # Get the type.
     type = val.type
 
-    if type == None or type.name == None or type.code != gdb.TYPE_CODE_TYPEDEF:
+    if type is None or type.name is None or type.code != gdb.TYPE_CODE_TYPEDEF:
         return None
 
     # Iterate over local dictionary of typedef types to determine if a
index aac70a0a8f5e2d5686a65078a0bc4470cca363a4..8562e52a5c39c9d4d64784de4c1a796c69994bf3 100644 (file)
@@ -42,7 +42,7 @@ def lookup_function(val):
     # Get the type name.
     typename = type.tag
 
-    if typename == None:
+    if typename is None:
         return None
 
     # Iterate over local dictionary of types to determine
index 3042472bff55a681be531c30cdc9a51490eebc81..2892f41f27e15f26dac35a744e257bdd56820d16 100644 (file)
@@ -45,7 +45,7 @@ class dummy_unwinder(Unwinder):
     def get_regs(self, pending_frame):
         """Return a list of register names that should be read.  Only
         gathers the list once, then caches the result."""
-        if self.regs != None:
+        if self.regs is not None:
             return self.regs
 
         # Collect the names of all registers to read.
index c7d879efe634c4d97edb21a71ba4f86fe733bcab..d9fd60f3dd4f7aa85fdd38a95ecf404c8be8f7b9 100644 (file)
@@ -192,7 +192,7 @@ gdb_test "python print (a)" ".*aliases -- User-defined aliases of other commands
 # Test PR 12212, using InfThread.selected_thread() when no inferior is
 # loaded.
 gdb_py_test_silent_cmd "python nothread = gdb.selected_thread()" "Attempt to aquire thread with no inferior" 1
-gdb_test "python print (nothread == None)" "True" "ensure that no threads are returned"
+gdb_test "python print (nothread is None)" "True" "ensure that no threads are returned"
 
 gdb_test_multiline "register atexit function" \
     "python" "" \
index 57c8cc3fbf3fccd92a0ee54ca9148a06d2dd7989..a78e30065ba6cf3101de1b6db684fbf9a842ad9c 100644 (file)
@@ -38,7 +38,7 @@ def lookup_function(val):
     # Get the type name.
     typename = type.tag
 
-    if typename == None:
+    if typename is None:
         return None
 
     if typename == "pp::Inner":