python: avoid equality check for None

PEP8 says that:
"Comparisons to singletons like None should always be done with is or
is not, never the equality operators."

glib uses a mix of "== None" and "is None". This patch changes all
cases to the latter.
This commit is contained in:
Thomas Hindoe Paaboel Andersen 2018-07-12 23:40:50 +02:00
parent c557c6de81
commit a8b416f9fe
7 changed files with 21 additions and 21 deletions

View File

@ -1068,7 +1068,7 @@ class CodeGenerator:
'\n') '\n')
def generate_annotations(self, prefix, annotations): def generate_annotations(self, prefix, annotations):
if annotations == None: if annotations is None:
return return
n = 0 n = 0

View File

@ -63,38 +63,38 @@ def apply_annotation(iface_list, iface, method, signal, prop, arg, key, value):
iface_obj = i iface_obj = i
break break
if iface_obj == None: if iface_obj is None:
print_error('No interface "{}"'.format(iface)) print_error('No interface "{}"'.format(iface))
target_obj = None target_obj = None
if method: if method:
method_obj = find_method(iface_obj, method) method_obj = find_method(iface_obj, method)
if method_obj == None: if method_obj is None:
print_error('No method "{}" on interface "{}"'.format(method, iface)) print_error('No method "{}" on interface "{}"'.format(method, iface))
if arg: if arg:
arg_obj = find_arg(method_obj.in_args, arg) arg_obj = find_arg(method_obj.in_args, arg)
if (arg_obj == None): if (arg_obj is None):
arg_obj = find_arg(method_obj.out_args, arg) arg_obj = find_arg(method_obj.out_args, arg)
if (arg_obj == None): if (arg_obj is None):
print_error('No arg "{}" on method "{}" on interface "{}"'.format(arg, method, iface)) print_error('No arg "{}" on method "{}" on interface "{}"'.format(arg, method, iface))
target_obj = arg_obj target_obj = arg_obj
else: else:
target_obj = method_obj target_obj = method_obj
elif signal: elif signal:
signal_obj = find_signal(iface_obj, signal) signal_obj = find_signal(iface_obj, signal)
if signal_obj == None: if signal_obj is None:
print_error('No signal "{}" on interface "{}"'.format(signal, iface)) print_error('No signal "{}" on interface "{}"'.format(signal, iface))
if arg: if arg:
arg_obj = find_arg(signal_obj.args, arg) arg_obj = find_arg(signal_obj.args, arg)
if (arg_obj == None): if (arg_obj is None):
print_error('No arg "{}" on signal "{}" on interface "{}"'.format(arg, signal, iface)) print_error('No arg "{}" on signal "{}" on interface "{}"'.format(arg, signal, iface))
target_obj = arg_obj target_obj = arg_obj
else: else:
target_obj = signal_obj target_obj = signal_obj
elif prop: elif prop:
prop_obj = find_prop(iface_obj, prop) prop_obj = find_prop(iface_obj, prop)
if prop_obj == None: if prop_obj is None:
print_error('No property "{}" on interface "{}"'.format(prop, iface)) print_error('No property "{}" on interface "{}"'.format(prop, iface))
target_obj = prop_obj target_obj = prop_obj
else: else:

View File

@ -61,7 +61,7 @@ class Arg:
if len(self.since) == 0: if len(self.since) == 0:
self.since = utils.lookup_since(self.annotations) self.since = utils.lookup_since(self.annotations)
if self.name == None: if self.name is None:
self.name = 'unnamed_arg%d'%arg_number self.name = 'unnamed_arg%d'%arg_number
# default to GVariant # default to GVariant
self.ctype_in_g = 'GVariant *' self.ctype_in_g = 'GVariant *'

View File

@ -116,21 +116,21 @@ def lookup_annotation(annotations, key):
def lookup_docs(annotations): def lookup_docs(annotations):
s = lookup_annotation(annotations, 'org.gtk.GDBus.DocString') s = lookup_annotation(annotations, 'org.gtk.GDBus.DocString')
if s == None: if s is None:
return '' return ''
else: else:
return s return s
def lookup_since(annotations): def lookup_since(annotations):
s = lookup_annotation(annotations, 'org.gtk.GDBus.Since') s = lookup_annotation(annotations, 'org.gtk.GDBus.Since')
if s == None: if s is None:
return '' return ''
else: else:
return s return s
def lookup_brief_docs(annotations): def lookup_brief_docs(annotations):
s = lookup_annotation(annotations, 'org.gtk.GDBus.DocString.Short') s = lookup_annotation(annotations, 'org.gtk.GDBus.DocString.Short')
if s == None: if s is None:
return '' return ''
else: else:
return s return s

View File

@ -9,7 +9,7 @@ def read_global_var (symname):
return gdb.selected_frame().read_var(symname) return gdb.selected_frame().read_var(symname)
def g_quark_to_string (quark): def g_quark_to_string (quark):
if quark == None: if quark is None:
return None return None
quark = long(quark) quark = long(quark)
if quark == 0: if quark == 0:
@ -171,7 +171,7 @@ def pretty_printer_lookup (val):
return None return None
def register (obj): def register (obj):
if obj == None: if obj is None:
obj = gdb obj = gdb
obj.pretty_printers.append(pretty_printer_lookup) obj.pretty_printers.append(pretty_printer_lookup)

View File

@ -104,7 +104,7 @@ class Mapping:
return [self] return [self]
def serialise(self, serialiser): def serialise(self, serialiser):
if self.serialised == None: if self.serialised is None:
self.serialised = serialiser.add_mapping(self.mapping) self.serialised = serialiser.add_mapping(self.mapping)
return self.serialised return self.serialised
@ -193,7 +193,7 @@ class Chain:
return [self] return [self]
def serialise(self, serialiser): def serialise(self, serialiser):
if self.serialised == None: if self.serialised is None:
# Before we serialise, see if we can optimise a bit # Before we serialise, see if we can optimise a bit
self.chain = sum((item.get_flattened() for item in self.chain), []) self.chain = sum((item.get_flattened() for item in self.chain), [])

View File

@ -26,7 +26,7 @@ def g_type_to_typenode (gtype):
if typenode == 0: if typenode == 0:
return None return None
val = read_global_var ("static_fundamental_type_nodes") val = read_global_var ("static_fundamental_type_nodes")
if val == None: if val is None:
return None return None
return val[typenode >> 2].address return val[typenode >> 2].address
@ -132,7 +132,7 @@ def pretty_printer_lookup (val):
return None return None
def get_signal_name (id): def get_signal_name (id):
if id == None: if id is None:
return None return None
id = long(id) id = long(id)
if id == 0: if id == 0:
@ -163,7 +163,7 @@ class SignalFrame(FrameDecorator):
def read_var (self, frame, name, array = None): def read_var (self, frame, name, array = None):
try: try:
v = frame_var (frame, name) v = frame_var (frame, name)
if v == None or v.is_optimized_out: if v is None or v.is_optimized_out:
return None return None
if array != None: if array != None:
array.append (v) array.append (v)
@ -174,7 +174,7 @@ class SignalFrame(FrameDecorator):
def read_object (self, frame, name, array = None): def read_object (self, frame, name, array = None):
try: try:
v = frame_var (frame, name) v = frame_var (frame, name)
if v == None or v.is_optimized_out: if v is None or v.is_optimized_out:
return None return None
v = v.cast (gdb.lookup_type("GObject").pointer()) v = v.cast (gdb.lookup_type("GObject").pointer())
# Ensure this is a somewhat correct object pointer # Ensure this is a somewhat correct object pointer
@ -323,7 +323,7 @@ class GFrameFilter(object):
return GFrameDecorator(iterator) return GFrameDecorator(iterator)
def register (obj): def register (obj):
if obj == None: if obj is None:
obj = gdb obj = gdb
if HAVE_GDB_FRAMEDECORATOR: if HAVE_GDB_FRAMEDECORATOR: