From 2481a12529fd56dea3eafcd0d39bbaa95b331baa Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Mon, 2 Sep 2019 12:23:33 +0200 Subject: [PATCH] samples: intel_s1000: Simplify code and fix pylint warning Empty sequences in Python are falsy, so if len(config_file) != 0: can be simplified to if config_file: pylint warning: C1801: Do not use `len(SEQUENCE)` to determine if a sequence is empty (len-as-condition) Simplify the code a bit with os.path.join(), which indirectly gets rid of the warning. os.path.join('', 'foo') returns 'foo', so things work out when os.path.basename() returns '' (no directory) as well. I'm getting rid of pylint warnings for a CI check. Also replace a '== None' with 'is None', which is more common. Signed-off-by: Ulf Magnusson --- samples/boards/intel_s1000_crb/audio/audio.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/samples/boards/intel_s1000_crb/audio/audio.py b/samples/boards/intel_s1000_crb/audio/audio.py index 40ac352f30e..27d6d746cee 100644 --- a/samples/boards/intel_s1000_crb/audio/audio.py +++ b/samples/boards/intel_s1000_crb/audio/audio.py @@ -25,17 +25,14 @@ class Device: When the script is run using sudo permission, the manufacturer and product strings are printed """ - config_file = os.path.dirname(__file__) - if len(config_file) != 0: - config_file += '/' - config_file += 'config.yml' + config_file = os.path.join(os.path.dirname(__file__), 'config.yml') with open(config_file, 'r') as ymlfile: config = yaml.safe_load(ymlfile) self.name = config['general']['name'] self.usb_vid = config['usb']['vid'] self.usb_pid = config['usb']['pid'] self.hid_dev = hid.device() - if self.hid_dev == None: + if self.hid_dev is None: print('Device not found') else: self.hid_dev.open(self.usb_vid, self.usb_pid)