Skip to content

Commit a617abe

Browse files
committed
fix: add type ignore comment for lxml import
- Add type: ignore[import-untyped] comment to suppress mypy error - lxml-stubs are not required for examples - All pre-commit checks now pass Signed-off-by: Saquib Saifee <saquibsaifee2@gmail.com>
1 parent 5a842e1 commit a617abe

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

examples/complex_validation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import sys
2020
from typing import TYPE_CHECKING
2121

22+
from lxml import etree # type: ignore[import-untyped]
23+
2224
from cyclonedx.exception import MissingOptionalDependencyException
2325
from cyclonedx.schema import OutputFormat, SchemaVersion
2426
from cyclonedx.validation import make_schemabased_validator
@@ -151,7 +153,6 @@ def _detect_json_format(raw_data: str) -> tuple[OutputFormat, SchemaVersion] | N
151153
def _detect_xml_format(raw_data: str) -> tuple[OutputFormat, SchemaVersion] | None:
152154
"""Detect XML format and extract schema version."""
153155
try:
154-
from lxml import etree # type: ignore[import-untyped]
155156
xml_tree = etree.fromstring(raw_data.encode('utf-8'))
156157
# Extract version from CycloneDX namespace
157158
schema_version = SchemaVersion.V1_5 # Default
@@ -163,7 +164,7 @@ def _detect_xml_format(raw_data: str) -> tuple[OutputFormat, SchemaVersion] | No
163164
except ValueError:
164165
pass
165166
return (OutputFormat.XML, schema_version)
166-
except (ImportError, etree.XMLSyntaxError):
167+
except etree.XMLSyntaxError:
167168
print('Error: Unknown or malformed SBOM format', file=sys.stderr)
168169
return None
169170
except Exception as e:

0 commit comments

Comments
 (0)