Use is/is not to check for None in python code.

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.
This commit is contained in:
Lancelot SIX
2021-06-07 23:14:55 +01:00
parent 122373f7f2
commit f9e59d060f
17 changed files with 52 additions and 22 deletions

@ -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> 2021-06-08 Simon Marchi <simon.marchi@polymtl.ca>
* inferior.h (class inferior) <in_initial_library_scan>: New. * inferior.h (class inferior) <in_initial_library_scan>: New.

@ -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> 2021-06-05 Shahab Vahedi <shahab@synopsys.com>
* gdb.texinfo (Source and Machine Code): Document 'set * gdb.texinfo (Source and Machine Code): Document 'set

@ -1661,7 +1661,7 @@ example above might be written.
@smallexample @smallexample
def str_lookup_function(val): def str_lookup_function(val):
lookup_tag = val.type.tag lookup_tag = val.type.tag
if lookup_tag == None: if lookup_tag is None:
return None return None
regex = re.compile("^std::basic_string<char,.*>$") regex = re.compile("^std::basic_string<char,.*>$")
if regex.match(lookup_tag): if regex.match(lookup_tag):

@ -117,7 +117,7 @@ class FrameDecorator(object):
# address. If GDB detects an integer value from this function # address. If GDB detects an integer value from this function
# it will attempt to find the function name from minimal # it will attempt to find the function name from minimal
# symbols via its own internal functions. # symbols via its own internal functions.
if func == None: if func is None:
pc = frame.pc() pc = frame.pc()
return pc return pc
@ -270,7 +270,7 @@ class FrameVars(object):
except RuntimeError: except RuntimeError:
block = None block = None
while block != None: while block is not None:
if block.is_global or block.is_static: if block.is_global or block.is_static:
break break
for sym in block: for sym in block:
@ -295,12 +295,12 @@ class FrameVars(object):
except RuntimeError: except RuntimeError:
block = None block = None
while block != None: while block is not None:
if block.function != None: if block.function is not None:
break break
block = block.superblock block = block.superblock
if block != None: if block is not None:
for sym in block: for sym in block:
if not sym.is_argument: if not sym.is_argument:
continue continue

@ -372,7 +372,7 @@ class SetFrameFilterPriority(gdb.Command):
def invoke(self, arg, from_tty): def invoke(self, arg, from_tty):
command_tuple = self._parse_pri_arg(arg) command_tuple = self._parse_pri_arg(arg)
if command_tuple != None: if command_tuple is not None:
self._set_filter_priority(command_tuple) self._set_filter_priority(command_tuple)
@ -453,7 +453,7 @@ class ShowFrameFilterPriority(gdb.Command):
def invoke(self, arg, from_tty): def invoke(self, arg, from_tty):
command_tuple = self._parse_pri_arg(arg) command_tuple = self._parse_pri_arg(arg)
if command_tuple == None: if command_tuple is None:
return return
filter_name = command_tuple[1] filter_name = command_tuple[1]
list_name = command_tuple[0] list_name = command_tuple[0]

@ -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> 2021-06-08 Tom de Vries <tdevries@suse.de>
* lib/gdb.exp (multi_line): Require more than one argument. * lib/gdb.exp (multi_line): Require more than one argument.

@ -46,10 +46,10 @@ class TestUnwinder(Unwinder):
sp = pending_frame.read_register(sp_desc) sp = pending_frame.read_register(sp_desc)
block = gdb.block_for_pc(int(pc)) block = gdb.block_for_pc(int(pc))
if block == None: if block is None:
return None return None
func = block.function func = block.function
if func == None: if func is None:
return None return None
if str(func) != "break_bt_here": if str(func) != "break_bt_here":
return None return None

@ -53,7 +53,7 @@ def lookup_function(val):
# Get the type name. # Get the type name.
typename = type.tag typename = type.tag
if typename == None: if typename is None:
return None return None
# Iterate over local dictionary of types to determine # Iterate over local dictionary of types to determine

@ -28,7 +28,7 @@ class Reverse_Function(FrameDecorator):
def function(self): def function(self):
fname = str(self.fobj.function()) fname = str(self.fobj.function())
if fname == None or fname == "": if not fname:
return None return None
if fname == "end_func": if fname == "end_func":
extra = self.fobj.inferior_frame().read_var("str").string() extra = self.fobj.inferior_frame().read_var("str").string()

@ -28,7 +28,7 @@ class Reverse_Function(FrameDecorator):
def function(self): def function(self):
fname = str(self.fobj.function()) fname = str(self.fobj.function())
if fname == None or fname == "": if not fname:
return None return None
if fname == "end_func": if fname == "end_func":
extra = self.fobj.inferior_frame().read_var("str").string() extra = self.fobj.inferior_frame().read_var("str").string()

@ -88,7 +88,7 @@ def lookup_function(val):
# Get the type name. # Get the type name.
typename = type.tag typename = type.tag
if typename == None: if typename is None:
return None return None
# Iterate over local dictionary of types to determine # Iterate over local dictionary of types to determine
@ -109,7 +109,7 @@ def lookup_typedefs_function(val):
# Get the type. # Get the type.
type = val.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 return None
# Iterate over local dictionary of typedef types to determine if a # Iterate over local dictionary of typedef types to determine if a

@ -42,7 +42,7 @@ def lookup_function(val):
# Get the type name. # Get the type name.
typename = type.tag typename = type.tag
if typename == None: if typename is None:
return None return None
# Iterate over local dictionary of types to determine # Iterate over local dictionary of types to determine

@ -314,7 +314,7 @@ def lookup_function(val):
# Get the type name. # Get the type name.
typename = type.tag typename = type.tag
if typename == None: if typename is None:
return None return None
# Iterate over local dictionary of types to determine # Iterate over local dictionary of types to determine
@ -344,7 +344,7 @@ def lookup_typedefs_function(val):
# Get the type. # Get the type.
type = val.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 return None
# Iterate over local dictionary of typedef types to determine if a # Iterate over local dictionary of typedef types to determine if a

@ -42,7 +42,7 @@ def lookup_function(val):
# Get the type name. # Get the type name.
typename = type.tag typename = type.tag
if typename == None: if typename is None:
return None return None
# Iterate over local dictionary of types to determine # Iterate over local dictionary of types to determine

@ -45,7 +45,7 @@ class dummy_unwinder(Unwinder):
def get_regs(self, pending_frame): def get_regs(self, pending_frame):
"""Return a list of register names that should be read. Only """Return a list of register names that should be read. Only
gathers the list once, then caches the result.""" gathers the list once, then caches the result."""
if self.regs != None: if self.regs is not None:
return self.regs return self.regs
# Collect the names of all registers to read. # Collect the names of all registers to read.

@ -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 # Test PR 12212, using InfThread.selected_thread() when no inferior is
# loaded. # loaded.
gdb_py_test_silent_cmd "python nothread = gdb.selected_thread()" "Attempt to aquire thread with no inferior" 1 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" \ gdb_test_multiline "register atexit function" \
"python" "" \ "python" "" \

@ -38,7 +38,7 @@ def lookup_function(val):
# Get the type name. # Get the type name.
typename = type.tag typename = type.tag
if typename == None: if typename is None:
return None return None
if typename == "pp::Inner": if typename == "pp::Inner":