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

View 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

View 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()

View 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()

View 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

View 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

View 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

View 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

View 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.

View 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" "" \