From 623e8387795ba79618e20697f412dbd95135dcc0 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 26 Apr 2024 10:38:32 +0000 Subject: [PATCH] refactor: use identity check for comparison to a singleton Comparisons to the singleton objects, like `True`, `False`, and `None`, should be done with identity, not equality. Use `is` or `is not`. --- pywisp_emibcn/pywisp.py | 2 +- pywisp_emibcn/sshdevice.py | 4 ++-- tests/test_pywisp.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pywisp_emibcn/pywisp.py b/pywisp_emibcn/pywisp.py index 6b0833a..9966fcc 100755 --- a/pywisp_emibcn/pywisp.py +++ b/pywisp_emibcn/pywisp.py @@ -276,7 +276,7 @@ def main(): # Get devices devices = pywisp.wisp.get_host( pywisp.args.host, deep=pywisp.args.deep, from_br=pywisp.args.from_br) - if devices == None or len(devices) == 0: + if devices is None or len(devices) == 0: pywisp.log.error("No devices found: '%s'" % (pywisp.args.host)) return 1 diff --git a/pywisp_emibcn/sshdevice.py b/pywisp_emibcn/sshdevice.py index 53aa598..a849aa3 100644 --- a/pywisp_emibcn/sshdevice.py +++ b/pywisp_emibcn/sshdevice.py @@ -81,7 +81,7 @@ def setBackupName(self, backup_file=""): def login(self): '''Open SSH connection only if it is not already opened''' - if self.client == False: + if self.client is False: # Start SSH connection self.client = paramiko.SSHClient() @@ -99,7 +99,7 @@ def login(self): def logout(self): '''Close SSH connection only if it is opened''' - if self.client != False: + if self.client is not False: self.client.close() # Higiene del self.client diff --git a/tests/test_pywisp.py b/tests/test_pywisp.py index d0f9b0a..7295d19 100644 --- a/tests/test_pywisp.py +++ b/tests/test_pywisp.py @@ -29,7 +29,7 @@ def get_host(self, name, deep=False, from_br=None): # Get devices device = pywisp.wisp.get_host(pywisp.args.host) -assert device != None, 'get_host should have returned a list or a device' +assert device is not None, 'get_host should have returned a list or a device' if not len(device): raise AssertionError( 'get_host should have returned a list with at least one device')