From 6677995090938903317f410c164bbf0cdb8d05ea Mon Sep 17 00:00:00 2001
From: Taras Drozdovskyi <t.drozdovsky@samsung.com>
Date: Thu, 4 Nov 2021 16:17:38 +0200
Subject: [PATCH] Fix some alerts from the LGTM system (#11143)

Signed-off-by: Taras Drozdovskyi <t.drozdovsky@samsung.com>
---
 scripts/tools/memory/memdf/df.py                         | 3 ++-
 scripts/tools/memory/report_summary.py                   | 2 --
 src/controller/python/chip/ChipBleUtility.py             | 2 +-
 src/controller/python/chip/ChipBluezMgr.py               | 2 +-
 src/controller/python/chip/ChipCommissionableNodeCtrl.py | 2 +-
 src/controller/python/chip/ChipCoreBluetoothMgr.py       | 2 +-
 src/controller/python/chip/ChipDeviceCtrl.py             | 6 +++---
 src/controller/python/chip/ChipStack.py                  | 2 +-
 src/controller/python/chip/ChipUtility.py                | 2 +-
 src/controller/python/chip/ble/library_handle.py         | 2 +-
 src/controller/python/chip/clusters/Command.py           | 4 ++--
 src/controller/python/chip/clusters/__init__.py          | 2 +-
 src/controller/python/chip/interaction_model/__init__.py | 2 +-
 src/controller/python/chip/interaction_model/delegate.py | 2 +-
 14 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/scripts/tools/memory/memdf/df.py b/scripts/tools/memory/memdf/df.py
index a91e44c669d94b..7345f41e0163a6 100644
--- a/scripts/tools/memory/memdf/df.py
+++ b/scripts/tools/memory/memdf/df.py
@@ -32,7 +32,8 @@ def __init__(self, *args, **kwargs):
                 self[c] = pd.Series()
         types = {c: self.dtype[c] for c in self.columns if c in self.dtype}
         typed_columns = list(types.keys())
-        self[typed_columns] = self.astype(types, copy=False)[typed_columns]
+        self[typed_columns] = self.astype(types, copy=False)[
+            typed_columns]  # lgtm [py/hash-unhashable-value]
         self.attrs['name'] = self.name
 
 
diff --git a/scripts/tools/memory/report_summary.py b/scripts/tools/memory/report_summary.py
index 3b21f6a88bb8ea..5a3d0cd4ded8d0 100755
--- a/scripts/tools/memory/report_summary.py
+++ b/scripts/tools/memory/report_summary.py
@@ -28,8 +28,6 @@
 
 import sys
 
-import numpy  # type: ignore
-
 import memdf.collect
 import memdf.report
 import memdf.select
diff --git a/src/controller/python/chip/ChipBleUtility.py b/src/controller/python/chip/ChipBleUtility.py
index 95abc3b7c8be76..db0f1a4b01245b 100644
--- a/src/controller/python/chip/ChipBleUtility.py
+++ b/src/controller/python/chip/ChipBleUtility.py
@@ -24,7 +24,7 @@
 
 from __future__ import absolute_import
 from __future__ import print_function
-from ctypes import *
+from ctypes import *  # lgtm [py/polluting-import]
 from .ChipUtility import ChipUtility
 
 
diff --git a/src/controller/python/chip/ChipBluezMgr.py b/src/controller/python/chip/ChipBluezMgr.py
index 13b8b28cdb9452..9e703360c81116 100644
--- a/src/controller/python/chip/ChipBluezMgr.py
+++ b/src/controller/python/chip/ChipBluezMgr.py
@@ -35,7 +35,7 @@
 import uuid
 import queue
 
-from ctypes import *
+from ctypes import CFUNCTYPE, PYFUNCTYPE, c_void_p, c_int
 
 try:
     from gi.repository import GObject
diff --git a/src/controller/python/chip/ChipCommissionableNodeCtrl.py b/src/controller/python/chip/ChipCommissionableNodeCtrl.py
index 87b9f5ca9dd737..c13aa828f51d8a 100644
--- a/src/controller/python/chip/ChipCommissionableNodeCtrl.py
+++ b/src/controller/python/chip/ChipCommissionableNodeCtrl.py
@@ -25,7 +25,7 @@
 
 from __future__ import absolute_import
 from __future__ import print_function
-from ctypes import *
+from ctypes import c_void_p, c_uint32
 from .ChipStack import *
 from .exceptions import *
 
diff --git a/src/controller/python/chip/ChipCoreBluetoothMgr.py b/src/controller/python/chip/ChipCoreBluetoothMgr.py
index b10a2156af453e..e24955260f480c 100644
--- a/src/controller/python/chip/ChipCoreBluetoothMgr.py
+++ b/src/controller/python/chip/ChipCoreBluetoothMgr.py
@@ -24,7 +24,7 @@
 
 from __future__ import absolute_import
 from __future__ import print_function
-from ctypes import *
+from ctypes import *  # lgtm [py/polluting-import]
 from Foundation import *
 
 import logging
diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py
index 3eee5650981f72..535a10482b6f33 100644
--- a/src/controller/python/chip/ChipDeviceCtrl.py
+++ b/src/controller/python/chip/ChipDeviceCtrl.py
@@ -28,7 +28,7 @@
 from __future__ import absolute_import
 from __future__ import print_function
 import asyncio
-from ctypes import *
+from ctypes import *  # lgtm [py/polluting-import]
 from .ChipStack import *
 from .interaction_model import delegate as im
 from .exceptions import *
@@ -334,11 +334,11 @@ def DeviceAvailableCallback(device, err):
 
         # The callback might have been received synchronously (during self._ChipStack.Call()).
         # Check if the device is already set before waiting for the callback.
-        if returnDevice.value == None:
+        if returnDevice.value is None:
             with deviceAvailableCV:
                 deviceAvailableCV.wait()
 
-        if returnDevice.value == None:
+        if returnDevice.value is None:
             raise self._ChipStack.ErrorToException(CHIP_ERROR_INTERNAL)
         return returnDevice
 
diff --git a/src/controller/python/chip/ChipStack.py b/src/controller/python/chip/ChipStack.py
index dc3930cf046ad5..6a488871b340cf 100644
--- a/src/controller/python/chip/ChipStack.py
+++ b/src/controller/python/chip/ChipStack.py
@@ -33,7 +33,7 @@
 import platform
 import logging
 from threading import Lock, Event, Condition
-from ctypes import *
+from ctypes import *  # lgtm [py/polluting-import]
 from .ChipUtility import ChipUtility
 from .exceptions import *
 
diff --git a/src/controller/python/chip/ChipUtility.py b/src/controller/python/chip/ChipUtility.py
index 5f34984f904a0f..26df956e93786d 100644
--- a/src/controller/python/chip/ChipUtility.py
+++ b/src/controller/python/chip/ChipUtility.py
@@ -24,7 +24,7 @@
 from __future__ import absolute_import
 from __future__ import print_function
 import binascii
-from ctypes import *
+from ctypes import c_void_p, c_byte
 
 
 class ChipUtility(object):
diff --git a/src/controller/python/chip/ble/library_handle.py b/src/controller/python/chip/ble/library_handle.py
index d2469716adb3b5..591fdb5a07428a 100644
--- a/src/controller/python/chip/ble/library_handle.py
+++ b/src/controller/python/chip/ble/library_handle.py
@@ -15,7 +15,7 @@
 #
 
 import chip.native
-import ctypes
+import ctypes  # lgtm [py/import-and-import-from]
 from ctypes import c_bool, c_void_p, c_char_p, c_uint32, py_object
 from chip.ble.types import DeviceScannedCallback, ScanDoneCallback
 
diff --git a/src/controller/python/chip/clusters/Command.py b/src/controller/python/chip/clusters/Command.py
index 179c4ed9959da1..8e1c2d037923bd 100644
--- a/src/controller/python/chip/clusters/Command.py
+++ b/src/controller/python/chip/clusters/Command.py
@@ -16,7 +16,7 @@
 #
 
 from asyncio.futures import Future
-import ctypes
+import ctypes  # lgtm [py/import-and-import-from]
 from dataclasses import dataclass
 from typing import Type
 from ctypes import CFUNCTYPE, c_char_p, c_size_t, c_void_p, c_uint32, c_uint16, c_uint8, py_object
@@ -74,7 +74,7 @@ def _handleResponse(self, path: CommandPath, status: Status, response: bytes):
             self._future.set_result(None)
         else:
             # If a type hasn't been assigned, let's auto-deduce it.
-            if (self._expect_type == None):
+            if (self._expect_type is None):
                 self._expect_type = FindCommandClusterObject(False, path)
 
             if self._expect_type:
diff --git a/src/controller/python/chip/clusters/__init__.py b/src/controller/python/chip/clusters/__init__.py
index dee5aa9d605a23..09daf6fc758d32 100644
--- a/src/controller/python/chip/clusters/__init__.py
+++ b/src/controller/python/chip/clusters/__init__.py
@@ -23,5 +23,5 @@
 """Provides Python APIs for CHIP."""
 from . import Command
 from . import Attribute
-from .Objects import *
+from .Objects import *  # lgtm [py/polluting-import]
 from . import CHIPClusters
diff --git a/src/controller/python/chip/interaction_model/__init__.py b/src/controller/python/chip/interaction_model/__init__.py
index 60d63c2c8654d2..171c4bde89ef6d 100644
--- a/src/controller/python/chip/interaction_model/__init__.py
+++ b/src/controller/python/chip/interaction_model/__init__.py
@@ -26,7 +26,7 @@
 
 from chip.exceptions import ChipStackException
 
-__all__ = ["IMDelegate", "Status", "InteractionModelError"]
+__all__ = ["Status", "InteractionModelError"]
 
 
 class Status(enum.IntEnum):
diff --git a/src/controller/python/chip/interaction_model/delegate.py b/src/controller/python/chip/interaction_model/delegate.py
index f8205dd0e7cde6..ea30d38625d9dd 100644
--- a/src/controller/python/chip/interaction_model/delegate.py
+++ b/src/controller/python/chip/interaction_model/delegate.py
@@ -17,7 +17,7 @@
 from abc import abstractmethod
 from construct import Struct, Int64ul, Int32ul, Int16ul, Int8ul
 from ctypes import CFUNCTYPE, c_void_p, c_uint32, c_uint64, c_uint8, c_uint16, c_ssize_t
-import ctypes
+import ctypes  # lgtm [py/import-and-import-from]
 import chip.native
 import threading
 import chip.tlv