From 47dd7d2e3b62a46f2389b714770e009733aad6fb Mon Sep 17 00:00:00 2001 From: Villon CHEN Date: Tue, 25 Nov 2025 10:29:23 +0100 Subject: [PATCH] perf: move type import to `TYPE_CHECKING` to reduce import time --- codesectools/sasts/tools/Cppcheck/parser.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/codesectools/sasts/tools/Cppcheck/parser.py b/codesectools/sasts/tools/Cppcheck/parser.py index bdb6819..017db8f 100644 --- a/codesectools/sasts/tools/Cppcheck/parser.py +++ b/codesectools/sasts/tools/Cppcheck/parser.py @@ -5,14 +5,19 @@ format used by CodeSecTools. """ +from __future__ import annotations + import json from pathlib import Path -from typing import Self +from typing import TYPE_CHECKING, Self from codesectools.sasts.core.parser import AnalysisResult, Defect from codesectools.shared.cwe import CWE, CWEs from codesectools.utils import MissingFile +if TYPE_CHECKING: + from lxml.etree import ElementTree + class CppcheckError(Defect): """Represent a single error reported by Cppcheck.""" @@ -47,8 +52,6 @@ def __init__( class CppcheckAnalysisResult(AnalysisResult): """Represent the complete result of a Cppcheck analysis.""" - from lxml.etree import ElementTree - def __init__(self, output_dir: Path, xml_tree: ElementTree, cmdout: dict) -> None: """Initialize a CppcheckAnalysisResult instance.