Coverage for lintro / enums / tool_type.py: 75%
20 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Tool type definitions."""
3from __future__ import annotations
5from enum import Flag, auto
8class ToolType(Flag):
9 """Tool type definitions.
11 This enum defines the different types of tools that can be used in Lintro.
12 Tools can be of multiple types (e.g., a core can be both a linter and a formatter),
13 which is why this is a Flag enum rather than a regular Enum.
14 """
16 #: Tool that checks code for issues
17 LINTER = auto()
18 #: Tool that formats code
19 FORMATTER = auto()
20 #: Tool that checks types
21 TYPE_CHECKER = auto()
22 #: Tool that checks documentation
23 DOCUMENTATION = auto()
24 #: Tool that checks for security issues
25 SECURITY = auto()
26 #: Tool that checks infrastructure code
27 INFRASTRUCTURE = auto()
28 #: Tool that runs tests
29 TEST_RUNNER = auto()
32def normalize_tool_type(value: str | ToolType) -> ToolType:
33 """Normalize a raw value to a ToolType enum.
35 For enum instances, combined Flag values
36 (e.g., ToolType.LINTER | ToolType.FORMATTER) are preserved.
37 For string inputs, attempts to match a single enum name
38 (case-insensitive, e.g., "LINTER"). String inputs do not support
39 combination syntax like "LINTER|FORMATTER".
41 Args:
42 value: str or ToolType to normalize.
44 Returns:
45 ToolType: Normalized enum value.
47 Raises:
48 ValueError: If the value is not a valid tool type.
49 """
50 if isinstance(value, ToolType):
51 return value
52 if isinstance(value, str):
53 try:
54 return ToolType[value.upper()]
55 except KeyError as err:
56 supported = f"Supported types: {list(ToolType)}"
57 raise ValueError(
58 f"Unknown tool type: {value!r}. {supported}",
59 ) from err
60 raise ValueError(f"Invalid tool type: {value!r}. Expected str or ToolType.")