From fa5524890e86d353ee7d2194ccdd6c84e9bd2d31 Mon Sep 17 00:00:00 2001 From: Frazer Clews Date: Thu, 16 Jan 2020 17:11:19 +0000 Subject: bitbake: lib: amend code to use proper singleton comparisons where possible amend the code to handle singleton comparisons properly so it only checks if they only refer to the same object or not, and not bother comparing the values. (Bitbake rev: b809a6812aa15a8a9af97bc382cc4b19571e6bfc) Signed-off-by: Frazer Clews Signed-off-by: Richard Purdie --- bitbake/lib/bb/command.py | 2 +- bitbake/lib/bb/cooker.py | 8 ++++---- bitbake/lib/bb/data.py | 2 +- bitbake/lib/bb/event.py | 2 +- bitbake/lib/bb/fetch2/__init__.py | 4 ++-- bitbake/lib/bb/fetch2/git.py | 2 +- bitbake/lib/bb/fetch2/osc.py | 2 +- bitbake/lib/bb/fetch2/perforce.py | 2 +- bitbake/lib/bb/fetch2/ssh.py | 2 +- bitbake/lib/bb/parse/ast.py | 20 ++++++++++---------- bitbake/lib/bb/providers.py | 6 +++--- bitbake/lib/bb/taskdata.py | 2 +- bitbake/lib/bb/ui/buildinfohelper.py | 8 ++++---- bitbake/lib/bb/ui/knotty.py | 2 +- bitbake/lib/bb/ui/ncurses.py | 2 +- bitbake/lib/bb/ui/taskexp.py | 2 +- bitbake/lib/bb/ui/toasterui.py | 2 +- bitbake/lib/bb/ui/uievent.py | 2 +- 18 files changed, 36 insertions(+), 36 deletions(-) (limited to 'bitbake/lib/bb') diff --git a/bitbake/lib/bb/command.py b/bitbake/lib/bb/command.py index 378f389b3a..c8e1352865 100644 --- a/bitbake/lib/bb/command.py +++ b/bitbake/lib/bb/command.py @@ -65,7 +65,7 @@ class Command: # Can run synchronous commands straight away command_method = getattr(self.cmds_sync, command) if ro_only: - if not hasattr(command_method, 'readonly') or False == getattr(command_method, 'readonly'): + if not hasattr(command_method, 'readonly') or not getattr(command_method, 'readonly'): return None, "Not able to execute not readonly commands in readonly mode" try: self.cooker.process_inotify_updates() diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py index 3d65b0cb74..8407db8b00 100644 --- a/bitbake/lib/bb/cooker.py +++ b/bitbake/lib/bb/cooker.py @@ -1204,7 +1204,7 @@ class BBCooker: for c in collection_list: calc_layer_priority(c) regex = self.data.getVar("BBFILE_PATTERN_%s" % c) - if regex == None: + if regex is None: parselog.error("BBFILE_PATTERN_%s not defined" % c) errors = True continue @@ -1310,7 +1310,7 @@ class BBCooker: self.parseConfiguration() # If we are told to do the None task then query the default task - if (task == None): + if task is None: task = self.configuration.cmd if not task.startswith("do_"): task = "do_%s" % task @@ -1454,7 +1454,7 @@ class BBCooker: self.buildSetVars() # If we are told to do the None task then query the default task - if (task == None): + if task is None: task = self.configuration.cmd if not task.startswith("do_"): @@ -1687,7 +1687,7 @@ class CookerCollectFiles(object): def calc_bbfile_priority( self, filename, matched = None ): for _, _, regex, pri in self.bbfile_config_priorities: if regex.match(filename): - if matched != None: + if matched is not None: if not regex in matched: matched.add(regex) return pri diff --git a/bitbake/lib/bb/data.py b/bitbake/lib/bb/data.py index 0d75d0c1a9..6dc02172cb 100644 --- a/bitbake/lib/bb/data.py +++ b/bitbake/lib/bb/data.py @@ -79,7 +79,7 @@ def expand(s, d, varname = None): return d.expand(s, varname) def expandKeys(alterdata, readdata = None): - if readdata == None: + if readdata is None: readdata = alterdata todolist = {} diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py index 42143e7407..5cfbf36126 100644 --- a/bitbake/lib/bb/event.py +++ b/bitbake/lib/bb/event.py @@ -346,7 +346,7 @@ def set_UIHmask(handlerNum, level, debug_domains, mask): def getName(e): """Returns the name of a class or class instance""" - if getattr(e, "__name__", None) == None: + if getattr(e, "__name__", None) is None: return e.__class__.__name__ else: return e.__name__ diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py index 731c160892..18a6819d5d 100644 --- a/bitbake/lib/bb/fetch2/__init__.py +++ b/bitbake/lib/bb/fetch2/__init__.py @@ -1081,7 +1081,7 @@ def try_mirrors(fetch, d, origud, mirrors, check = False): for index, uri in enumerate(uris): ret = try_mirror_url(fetch, origud, uds[index], ld, check) - if ret != False: + if ret: return ret return None @@ -1351,7 +1351,7 @@ class FetchMethod(object): """ # We cannot compute checksums for directories - if os.path.isdir(urldata.localpath) == True: + if os.path.isdir(urldata.localpath): return False if urldata.localpath.find("*") != -1: return False diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py index fa41b078f1..fe0a384af2 100644 --- a/bitbake/lib/bb/fetch2/git.py +++ b/bitbake/lib/bb/fetch2/git.py @@ -671,7 +671,7 @@ class Git(FetchMethod): # search for version in the line tag = tagregex.search(tag_head) - if tag == None: + if tag is None: continue tag = tag.group('pver') diff --git a/bitbake/lib/bb/fetch2/osc.py b/bitbake/lib/bb/fetch2/osc.py index f55db6f791..8f091efd02 100644 --- a/bitbake/lib/bb/fetch2/osc.py +++ b/bitbake/lib/bb/fetch2/osc.py @@ -41,7 +41,7 @@ class Osc(FetchMethod): else: pv = d.getVar("PV", False) rev = bb.fetch2.srcrev_internal_helper(ud, d) - if rev and rev != True: + if rev: ud.revision = rev else: ud.revision = "" diff --git a/bitbake/lib/bb/fetch2/perforce.py b/bitbake/lib/bb/fetch2/perforce.py index b2ac11ecab..f57c2a4f52 100644 --- a/bitbake/lib/bb/fetch2/perforce.py +++ b/bitbake/lib/bb/fetch2/perforce.py @@ -104,7 +104,7 @@ class Perforce(FetchMethod): if command == 'changes': p4cmd = '%s%s changes -m 1 //%s' % (ud.basecmd, p4opt, pathnrev) elif command == 'print': - if depot_filename != None: + if depot_filename is not None: p4cmd = '%s%s print -o "p4/%s" "%s"' % (ud.basecmd, p4opt, filename, depot_filename) else: raise FetchError('No depot file name provided to p4 %s' % command, ud.url) diff --git a/bitbake/lib/bb/fetch2/ssh.py b/bitbake/lib/bb/fetch2/ssh.py index 34debe399b..5e982ecf38 100644 --- a/bitbake/lib/bb/fetch2/ssh.py +++ b/bitbake/lib/bb/fetch2/ssh.py @@ -58,7 +58,7 @@ class SSH(FetchMethod): '''Class to fetch a module or modules via Secure Shell''' def supports(self, urldata, d): - return __pattern__.match(urldata.url) != None + return __pattern__.match(urldata.url) is not None def supports_checksum(self, urldata): return False diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py index 362c1a39ce..eb8cfa21b8 100644 --- a/bitbake/lib/bb/parse/ast.py +++ b/bitbake/lib/bb/parse/ast.py @@ -89,7 +89,7 @@ class DataNode(AstNode): self.groupd = groupd def getFunc(self, key, data): - if 'flag' in self.groupd and self.groupd['flag'] != None: + if 'flag' in self.groupd and self.groupd['flag'] is not None: return data.getVarFlag(key, self.groupd['flag'], expand=False, noweakdefault=True) else: return data.getVar(key, False, noweakdefault=True, parsing=True) @@ -102,36 +102,36 @@ class DataNode(AstNode): 'file': self.filename, 'line': self.lineno, } - if "exp" in groupd and groupd["exp"] != None: + if "exp" in groupd and groupd["exp"] is not None: data.setVarFlag(key, "export", 1, op = 'exported', **loginfo) op = "set" - if "ques" in groupd and groupd["ques"] != None: + if "ques" in groupd and groupd["ques"] is not None: val = self.getFunc(key, data) op = "set?" - if val == None: + if val is None: val = groupd["value"] - elif "colon" in groupd and groupd["colon"] != None: + elif "colon" in groupd and groupd["colon"] is not None: e = data.createCopy() op = "immediate" val = e.expand(groupd["value"], key + "[:=]") - elif "append" in groupd and groupd["append"] != None: + elif "append" in groupd and groupd["append"] is not None: op = "append" val = "%s %s" % ((self.getFunc(key, data) or ""), groupd["value"]) - elif "prepend" in groupd and groupd["prepend"] != None: + elif "prepend" in groupd and groupd["prepend"] is not None: op = "prepend" val = "%s %s" % (groupd["value"], (self.getFunc(key, data) or "")) - elif "postdot" in groupd and groupd["postdot"] != None: + elif "postdot" in groupd and groupd["postdot"] is not None: op = "postdot" val = "%s%s" % ((self.getFunc(key, data) or ""), groupd["value"]) - elif "predot" in groupd and groupd["predot"] != None: + elif "predot" in groupd and groupd["predot"] is not None: op = "predot" val = "%s%s" % (groupd["value"], (self.getFunc(key, data) or "")) else: val = groupd["value"] flag = None - if 'flag' in groupd and groupd['flag'] != None: + if 'flag' in groupd and groupd['flag'] is not None: flag = groupd['flag'] elif groupd["lazyques"]: flag = "_defaultval" diff --git a/bitbake/lib/bb/providers.py b/bitbake/lib/bb/providers.py index f80963cb40..81459c36d5 100644 --- a/bitbake/lib/bb/providers.py +++ b/bitbake/lib/bb/providers.py @@ -92,11 +92,11 @@ def preferredVersionMatch(pe, pv, pr, preferred_e, preferred_v, preferred_r): Check if the version pe,pv,pr is the preferred one. If there is preferred version defined and ends with '%', then pv has to start with that version after removing the '%' """ - if (pr == preferred_r or preferred_r == None): - if (pe == preferred_e or preferred_e == None): + if pr == preferred_r or preferred_r is None: + if pe == preferred_e or preferred_e is None: if preferred_v == pv: return True - if preferred_v != None and preferred_v.endswith('%') and pv.startswith(preferred_v[:len(preferred_v)-1]): + if preferred_v is not None and preferred_v.endswith('%') and pv.startswith(preferred_v[:len(preferred_v)-1]): return True return False diff --git a/bitbake/lib/bb/taskdata.py b/bitbake/lib/bb/taskdata.py index 8c25e09e8a..d13a124983 100644 --- a/bitbake/lib/bb/taskdata.py +++ b/bitbake/lib/bb/taskdata.py @@ -362,7 +362,7 @@ class TaskData: bb.event.fire(bb.event.NoProvider(item, dependees=self.get_dependees(item), reasons=["No eligible PROVIDERs exist for '%s'" % item]), cfgData) raise bb.providers.NoProvider(item) - if len(eligible) > 1 and foundUnique == False: + if len(eligible) > 1 and not foundUnique: if item not in self.consider_msgs_cache: providers_list = [] for fn in eligible: diff --git a/bitbake/lib/bb/ui/buildinfohelper.py b/bitbake/lib/bb/ui/buildinfohelper.py index 5cbca97f3f..82c62e3324 100644 --- a/bitbake/lib/bb/ui/buildinfohelper.py +++ b/bitbake/lib/bb/ui/buildinfohelper.py @@ -935,7 +935,7 @@ class BuildInfoHelper(object): # only reset the build name if the one on the server is actually # a valid value for the build_name field - if build_name != None: + if build_name is not None: build_info['build_name'] = build_name changed = True @@ -1194,7 +1194,7 @@ class BuildInfoHelper(object): evdata = BuildInfoHelper._get_data_from_event(event) for t in self.internal_state['targets']: - if t.is_image == True: + if t.is_image: output_files = list(evdata.keys()) for output in output_files: if t.target in output and 'rootfs' in output and not output.endswith(".manifest"): @@ -1236,7 +1236,7 @@ class BuildInfoHelper(object): task_information['outcome'] = Task.OUTCOME_PREBUILT else: task_information['task_executed'] = True - if 'noexec' in vars(event) and event.noexec == True: + if 'noexec' in vars(event) and event.noexec: task_information['task_executed'] = False task_information['outcome'] = Task.OUTCOME_EMPTY task_information['script_type'] = Task.CODING_NA @@ -1776,7 +1776,7 @@ class BuildInfoHelper(object): image_file_extensions_unique = {} image_fstypes = self.server.runCommand( ['getVariable', 'IMAGE_FSTYPES'])[0] - if image_fstypes != None: + if image_fstypes is not None: image_types_str = image_fstypes.strip() image_file_extensions = re.sub(r' {2,}', ' ', image_types_str) image_file_extensions_unique = set(image_file_extensions.split(' ')) diff --git a/bitbake/lib/bb/ui/knotty.py b/bitbake/lib/bb/ui/knotty.py index 19008a4ead..a0340dfc20 100644 --- a/bitbake/lib/bb/ui/knotty.py +++ b/bitbake/lib/bb/ui/knotty.py @@ -447,7 +447,7 @@ def main(server, eventHandler, params, tf = TerminalFilter): if error: logger.error("Command '%s' failed: %s" % (cmdline, error)) return 1 - elif ret != True: + elif not ret: logger.error("Command '%s' failed: returned %s" % (cmdline, ret)) return 1 diff --git a/bitbake/lib/bb/ui/ncurses.py b/bitbake/lib/bb/ui/ncurses.py index 49569e375b..da4fbeabb6 100644 --- a/bitbake/lib/bb/ui/ncurses.py +++ b/bitbake/lib/bb/ui/ncurses.py @@ -238,7 +238,7 @@ class NCursesUI: if error: print("Error running command '%s': %s" % (cmdline, error)) return - elif ret != True: + elif not ret: print("Couldn't get default commandlind! %s" % ret) return except xmlrpc.client.Fault as x: diff --git a/bitbake/lib/bb/ui/taskexp.py b/bitbake/lib/bb/ui/taskexp.py index 7895102b95..8fff244235 100644 --- a/bitbake/lib/bb/ui/taskexp.py +++ b/bitbake/lib/bb/ui/taskexp.py @@ -200,7 +200,7 @@ def main(server, eventHandler, params): if error: print("Error running command '%s': %s" % (cmdline, error)) return 1 - elif ret != True: + elif not ret: print("Error running command '%s': returned %s" % (cmdline, ret)) return 1 except client.Fault as x: diff --git a/bitbake/lib/bb/ui/toasterui.py b/bitbake/lib/bb/ui/toasterui.py index 51892c9a09..9260f5d9d7 100644 --- a/bitbake/lib/bb/ui/toasterui.py +++ b/bitbake/lib/bb/ui/toasterui.py @@ -176,7 +176,7 @@ def main(server, eventHandler, params): if error: logger.error("Command '%s' failed: %s" % (cmdline, error)) return 1 - elif ret != True: + elif not ret: logger.error("Command '%s' failed: returned %s" % (cmdline, ret)) return 1 diff --git a/bitbake/lib/bb/ui/uievent.py b/bitbake/lib/bb/ui/uievent.py index fedb05064d..13d0d4a04c 100644 --- a/bitbake/lib/bb/ui/uievent.py +++ b/bitbake/lib/bb/ui/uievent.py @@ -46,7 +46,7 @@ class BBUIEventQueue: self.EventHandle = ret error = "" - if self.EventHandle != None: + if self.EventHandle is not None: break errmsg = "Could not register UI event handler. Error: %s, host %s, "\ -- cgit v1.2.3-54-g00ecf