From 4e6053df476d659d8bfb4d33aaa69308a533f9ff Mon Sep 17 00:00:00 2001 From: gruebel Date: Fri, 13 Oct 2023 00:31:04 +0200 Subject: [PATCH] fix test and typing --- .pre-commit-config.yaml | 4 ++-- .../common/bridgecrew/vulnerability_scanning/report.py | 2 +- .../common/graph/graph_builder/graph_components/blocks.py | 4 ++-- checkov/common/parsers/json/decoder.py | 2 +- checkov/common/sca/commons.py | 8 ++++---- checkov/kubernetes/image_referencer/base_provider.py | 4 ++-- checkov/terraform/plan_parser.py | 2 +- tests/common/output/test_spdx.py | 6 +++--- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2b6c6047dfe..018a96e65ee 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: debug-statements - repo: https://github.com/PyCQA/flake8 @@ -33,7 +33,7 @@ repos: additional_dependencies: - vistir<0.7.0 # can be removed, when v4.0.0 of pipenv-setup comes out - repo: https://github.com/seddonym/import-linter # checks the import dependencies between each other - rev: v1.11.1 + rev: v1.12.0 hooks: - id: import-linter language_version: python3.9 diff --git a/checkov/common/bridgecrew/vulnerability_scanning/report.py b/checkov/common/bridgecrew/vulnerability_scanning/report.py index 5324801168b..32fe7908f62 100644 --- a/checkov/common/bridgecrew/vulnerability_scanning/report.py +++ b/checkov/common/bridgecrew/vulnerability_scanning/report.py @@ -7,7 +7,7 @@ from pathlib import Path from typing import Any, TYPE_CHECKING -from aiomultiprocess import Pool # type:ignore[import] +from aiomultiprocess import Pool # type:ignore[import-untyped] from checkov.common.bridgecrew.vulnerability_scanning.integrations.package_scanning import PackageScanningIntegration diff --git a/checkov/common/graph/graph_builder/graph_components/blocks.py b/checkov/common/graph/graph_builder/graph_components/blocks.py index ad7f8472538..18e580b1a86 100644 --- a/checkov/common/graph/graph_builder/graph_components/blocks.py +++ b/checkov/common/graph/graph_builder/graph_components/blocks.py @@ -1,7 +1,7 @@ from __future__ import annotations from collections.abc import Collection -from typing import Union, Dict, Any, List +from typing import Union, Dict, Any, List, cast from checkov.common.graph.graph_builder.graph_components.attribute_names import CustomAttributes from checkov.common.graph.graph_builder.utils import calculate_hash, join_trimmed_strings @@ -119,7 +119,7 @@ def get_origin_attributes(self, base_attributes: Dict[str, Any]) -> None: def get_hash(self) -> str: attributes_dict = self.get_attribute_dict() - return attributes_dict.get(CustomAttributes.HASH, "") + return cast("str", attributes_dict.get(CustomAttributes.HASH, "")) def update_attribute( self, diff --git a/checkov/common/parsers/json/decoder.py b/checkov/common/parsers/json/decoder.py index a47bd1c4a86..bf0da79e0af 100644 --- a/checkov/common/parsers/json/decoder.py +++ b/checkov/common/parsers/json/decoder.py @@ -6,7 +6,7 @@ from json.decoder import WHITESPACE, WHITESPACE_STR, BACKSLASH, STRINGCHUNK, JSONArray # type:ignore[attr-defined] # they are not explicitly exported from typing import Any, Callable, Pattern, Match -from json.scanner import NUMBER_RE # type:ignore[import] # is not explicitly exported +from json.scanner import NUMBER_RE # type:ignore[import-not-found] # is not explicitly exported from checkov.common.parsers.node import StrNode, DictNode, ListNode from checkov.common.parsers.json.errors import NullError, DuplicateError, DecodeError diff --git a/checkov/common/sca/commons.py b/checkov/common/sca/commons.py index 0d8661d04b7..e7a72731b62 100644 --- a/checkov/common/sca/commons.py +++ b/checkov/common/sca/commons.py @@ -1,7 +1,7 @@ from __future__ import annotations import logging -from typing import List, Optional, Any +from typing import List, Optional, Any, cast from checkov.common.output.common import SCADetails @@ -39,8 +39,8 @@ def get_package_type(package_name: str, package_version: str, sca_details: SCADe def get_registry_url(package: dict[str, Any]) -> str: if "registry" in package: - return package.get("registry", "") - return package.get("registryUrl", "") + return cast("str", package.get("registry", "")) + return cast("str", package.get("registryUrl", "")) def normalize_twistcli_language(language: str) -> str: @@ -52,7 +52,7 @@ def normalize_twistcli_language(language: str) -> str: def get_package_lines(package: dict[str, Any]) -> list[int] | None: - return package.get("linesNumbers", package.get("lines")) + return cast("list[int] | None", package.get("linesNumbers", package.get("lines"))) def get_record_file_line_range(package: dict[str, Any], file_line_range: list[int] | None) -> list[int]: diff --git a/checkov/kubernetes/image_referencer/base_provider.py b/checkov/kubernetes/image_referencer/base_provider.py index d7f4b1d09a9..2b9e19b9f60 100644 --- a/checkov/kubernetes/image_referencer/base_provider.py +++ b/checkov/kubernetes/image_referencer/base_provider.py @@ -1,7 +1,7 @@ from __future__ import annotations import os -from typing import Any +from typing import Any, cast from checkov.common.graph.graph_builder import CustomAttributes from checkov.common.images.graph.image_referencer_provider import GraphImageReferencerProvider @@ -37,4 +37,4 @@ def extract_images_from_resources(self) -> list[Image]: return images def _get_resource_path(self, resource: dict[str, Any]) -> str: - return resource.get(CustomAttributes.FILE_PATH, "") + return cast("str", resource.get(CustomAttributes.FILE_PATH, "")) diff --git a/checkov/terraform/plan_parser.py b/checkov/terraform/plan_parser.py index 576a651d358..2161ca68a42 100644 --- a/checkov/terraform/plan_parser.py +++ b/checkov/terraform/plan_parser.py @@ -234,7 +234,7 @@ def _get_module_call_resources(module_address: str, root_module_conf: dict[str, continue root_module_conf = root_module_conf.get("module_calls", {}).get(module_name, {}).get("module", {}) - return root_module_conf.get("resources", []) + return cast("list[dict[str, Any]]", root_module_conf.get("resources", [])) def _get_resource_changes(template: dict[str, Any]) -> dict[str, dict[str, Any]]: diff --git a/tests/common/output/test_spdx.py b/tests/common/output/test_spdx.py index ea22b94929a..e3720bc013f 100644 --- a/tests/common/output/test_spdx.py +++ b/tests/common/output/test_spdx.py @@ -85,7 +85,7 @@ def test_sca_package_output(): "## Creation Information\n", "Creator: Tool: checkov\n", "Creator: Organization: bridgecrew (meet@bridgecrew.io)\n", - "Created: 2022-12-24T00:00:00+00:00Z\n", + "Created: 2022-12-24T00:00:00Z\n", "\n", "## Package Information\n", "PackageName: django\n", @@ -93,7 +93,7 @@ def test_sca_package_output(): "PackageVersion: 1.2\n", "PackageFileName: /requirements.txt\n", "PackageDownloadLocation: NONE\n", - "FilesAnalyzed: True\n", + "FilesAnalyzed: true\n", "PackageLicenseInfoFromFiles: OSI_BDS\n", "\n", "## Package Information\n", @@ -102,7 +102,7 @@ def test_sca_package_output(): "PackageVersion: 1.1.1\n", "PackageFileName: /requirements.txt\n", "PackageDownloadLocation: NONE\n", - "FilesAnalyzed: True\n", + "FilesAnalyzed: true\n", "PackageLicenseInfoFromFiles: MIT\n", "\n", "\n",