From 1752cc12a4d1fd25347a324aaec508427500f290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Michalak-Szmaci=C5=84ski?= Date: Tue, 11 Jul 2023 08:44:05 +0000 Subject: [PATCH] Flake8 fix errors in the other Python files --- .flake8 | 18 ------------------ build/chip/linux/gen_gdbus_wrapper.py | 4 ++-- build/config/linux/pkg-config.py | 4 ++-- credentials/fetch-paa-certs-from-dcl.py | 1 - docs/_extensions/external_content.py | 2 +- .../pigweed/rpc_console/py/chip_rpc/console.py | 4 ++-- examples/lighting-app/python/lighting.py | 8 +++----- src/app/zap_cluster_list.py | 2 +- src/controller/python/chip/yaml/runner.py | 2 +- .../matter_yamltest_repl_adapter/runner.py | 6 +++--- .../python/generate_setup_payload.py | 1 - src/tools/chip-cert/dacs.py | 2 +- 12 files changed, 16 insertions(+), 38 deletions(-) diff --git a/.flake8 b/.flake8 index c53238a9262656..e8d2f58a0c0997 100644 --- a/.flake8 +++ b/.flake8 @@ -3,18 +3,9 @@ max-line-length = 132 exclude = third_party .* out/* - scripts/idl/* ./examples/common/QRCode/* # temporarily scan only directories with fixed files # TODO: Remove the paths below when all bugs are fixed - src/tools/chip-cert/* - build/chip/java/tests/* - build/chip/linux/* - build/config/linux/* - credentials/fetch-paa-certs-from-dcl.py - docs/_extensions/external_content.py - examples/common/pigweed/rpc_console/py/chip_rpc/console.py - examples/lighting-app/python/lighting.py scripts/build/build/target.py scripts/build/build/targets.py scripts/build/builders/android.py @@ -46,12 +37,3 @@ exclude = third_party scripts/tools/zap/zap_download.py scripts/tools/zap_convert_all.py src/app/ota_image_tool.py - src/app/zap_cluster_list.py - src/controller/python/chip/yaml/__init__.py - src/controller/python/chip/yaml/format_converter.py - src/controller/python/chip/yaml/runner.py - src/controller/python/py_matter_yamltest_repl_adapter/matter_yamltest_repl_adapter/runner.py - src/lib/asn1/gen_asn1oid.py - src/pybindings/pycontroller/build-chip-wheel.py - src/pybindings/pycontroller/pychip/__init__.py - src/setup_payload/python/generate_setup_payload.py diff --git a/build/chip/linux/gen_gdbus_wrapper.py b/build/chip/linux/gen_gdbus_wrapper.py index 8657d06693d222..2391655fdecddf 100755 --- a/build/chip/linux/gen_gdbus_wrapper.py +++ b/build/chip/linux/gen_gdbus_wrapper.py @@ -65,10 +65,10 @@ def main(argv): ] + extra_args + [options.input_file] subprocess.check_call(gdbus_args) sed_args = ["sed", "-i", - "s/config\.h/BuildConfig.h/g", options.output_c] + r"s/config\.h/BuildConfig.h/g", options.output_c] if sys.platform == "darwin": sed_args = ["sed", "-i", "", - "s/config\.h/BuildConfig.h/g", options.output_c] + r"s/config\.h/BuildConfig.h/g", options.output_c] subprocess.check_call(sed_args) if options.output_h: diff --git a/build/config/linux/pkg-config.py b/build/config/linux/pkg-config.py index 664deb766597c1..ded24789504596 100755 --- a/build/config/linux/pkg-config.py +++ b/build/config/linux/pkg-config.py @@ -108,7 +108,7 @@ def MatchesAnyRegexp(flag, list_of_regexps): """Returns true if the first argument matches any regular expression in the given list.""" for regexp in list_of_regexps: - if regexp.search(flag) != None: + if regexp.search(flag) is not None: return True return False @@ -145,7 +145,7 @@ def main(): # Make a list of regular expressions to strip out. strip_out = [] - if options.strip_out != None: + if options.strip_out is not None: for regexp in options.strip_out: strip_out.append(re.compile(regexp)) diff --git a/credentials/fetch-paa-certs-from-dcl.py b/credentials/fetch-paa-certs-from-dcl.py index 56950a8c86e239..d440398c472be7 100644 --- a/credentials/fetch-paa-certs-from-dcl.py +++ b/credentials/fetch-paa-certs-from-dcl.py @@ -26,7 +26,6 @@ import re import subprocess import sys -from contextlib import nullcontext import click import requests diff --git a/docs/_extensions/external_content.py b/docs/_extensions/external_content.py index 99340cab259d02..9a8e5effcfaf39 100644 --- a/docs/_extensions/external_content.py +++ b/docs/_extensions/external_content.py @@ -81,7 +81,7 @@ def adjust_includes( def _adjust_path(path): # ignore absolute paths, section links, hyperlinks and same folder - if path.startswith(("/", "#", "http", "www")) or not "/" in path: + if path.startswith(("/", "#", "http", "www")) or "/" not in path: return path # for files that are being copied modify reference to and out of /docs diff --git a/examples/common/pigweed/rpc_console/py/chip_rpc/console.py b/examples/common/pigweed/rpc_console/py/chip_rpc/console.py index 7b95b8a502673e..fe9a5255876f6a 100644 --- a/examples/common/pigweed/rpc_console/py/chip_rpc/console.py +++ b/examples/common/pigweed/rpc_console/py/chip_rpc/console.py @@ -304,11 +304,11 @@ def write_to_output(data: bytes, def _read_raw_serial(read: Callable[[], bytes], output): """Continuously read and pass to output.""" - with ThreadPoolExecutor() as executor: + with ThreadPoolExecutor() as _: while True: try: data = read() - except Exception as exc: # pylint: disable=broad-except + except Exception: # pylint: disable=broad-except continue if data: output(data) diff --git a/examples/lighting-app/python/lighting.py b/examples/lighting-app/python/lighting.py index 148f2296c9848f..43317c1dc6158a 100644 --- a/examples/lighting-app/python/lighting.py +++ b/examples/lighting-app/python/lighting.py @@ -21,11 +21,9 @@ import textwrap import threading from cmd import Cmd -from ctypes import CFUNCTYPE, c_char_p, c_int32, c_uint8 -from chip.exceptions import ChipStackError -from chip.server import GetLibraryHandle, NativeLibraryHandleMethodArguments, PostAttributeChangeCallback -from dali.address import Broadcast, Short +from chip.server import GetLibraryHandle, PostAttributeChangeCallback +from dali.address import Broadcast from dali.driver.hid import tridonic from dali.gear.general import DAPC, Off, RecallMaxLevel @@ -206,7 +204,7 @@ def __init__(self): if __name__ == "__main__": - l = Lighting() + lighting = Lighting() lightMgrCmd = LightingMgrCmd() print("Chip Lighting Device Shell") diff --git a/src/app/zap_cluster_list.py b/src/app/zap_cluster_list.py index 5cdd78216c8921..12ad7743610d97 100755 --- a/src/app/zap_cluster_list.py +++ b/src/app/zap_cluster_list.py @@ -21,7 +21,7 @@ def get_cluster_sources(clusters: typing.Set[str], cluster_sources: typing.Set[str] = set() for cluster in clusters: - if not cluster in source_map: + if cluster not in source_map: raise ValueError("Unhandled %s cluster: %s" " (hint: add to src/app/zap_cluster_list.py)" % (side, cluster)) diff --git a/src/controller/python/chip/yaml/runner.py b/src/controller/python/chip/yaml/runner.py index 8553af31eeb6e1..b6be43fcc46083 100644 --- a/src/controller/python/chip/yaml/runner.py +++ b/src/controller/python/chip/yaml/runner.py @@ -129,7 +129,7 @@ def __init__(self, test_step): raise ActionCreationError(f'Default cluster {test_step.cluster} {test_step.command}, not supported') async def run_action(self, dev_ctrl: ChipDeviceController) -> _ActionResult: - resp = await _PSEUDO_CLUSTERS.execute(self._test_step) + _ = await _PSEUDO_CLUSTERS.execute(self._test_step) return _ActionResult(status=_ActionStatus.SUCCESS, response=None) diff --git a/src/controller/python/py_matter_yamltest_repl_adapter/matter_yamltest_repl_adapter/runner.py b/src/controller/python/py_matter_yamltest_repl_adapter/matter_yamltest_repl_adapter/runner.py index 83974aa09ab1e0..40f19221358f68 100644 --- a/src/controller/python/py_matter_yamltest_repl_adapter/matter_yamltest_repl_adapter/runner.py +++ b/src/controller/python/py_matter_yamltest_repl_adapter/matter_yamltest_repl_adapter/runner.py @@ -14,7 +14,7 @@ # isort: off -from chip import ChipDeviceCtrl # Needed before chip.FabricAdmin +from chip import ChipDeviceCtrl # Needed before chip.FabricAdmin # noqa: F401 import chip.FabricAdmin # Needed before chip.CertificateAuthority # isort: on @@ -22,7 +22,7 @@ import chip.CertificateAuthority import chip.logging import chip.native -from chip.ChipStack import * +from chip.ChipStack import ChipStack from chip.yaml.runner import ReplTestRunner from matter_yamltests.runner import TestRunner @@ -45,7 +45,7 @@ async def start(self): commission_device = False if len(certificate_authority_manager.activeCaList) == 0: - if self._commission_on_network_dut == False: + if self._commission_on_network_dut is False: raise Exception( 'Provided repl storage does not contain certificate. Without commission_on_network_dut, there is no reachable DUT') certificate_authority_manager.NewCertificateAuthority() diff --git a/src/setup_payload/python/generate_setup_payload.py b/src/setup_payload/python/generate_setup_payload.py index 967cc778d2550b..28a834651214b1 100755 --- a/src/setup_payload/python/generate_setup_payload.py +++ b/src/setup_payload/python/generate_setup_payload.py @@ -21,7 +21,6 @@ import Base38 from bitarray import bitarray -from bitarray.util import ba2int from stdnum.verhoeff import calc_check_digit # See section 5.1.4.1 Manual Pairing Code in the Matter specification v1.0 diff --git a/src/tools/chip-cert/dacs.py b/src/tools/chip-cert/dacs.py index 76705162fd741c..96722b3aca9746 100755 --- a/src/tools/chip-cert/dacs.py +++ b/src/tools/chip-cert/dacs.py @@ -5,7 +5,7 @@ import subprocess import sys import typing -from binascii import hexlify, unhexlify +from binascii import unhexlify from enum import Enum copyrightNotice = """/*