fix: resolve CI linting and type checking issues
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-02-04 22:07:54 +00:00
parent 7c56701331
commit 9fa78968d3

View File

@@ -1,9 +1,10 @@
"""TOML format converter."""
from pathlib import Path
from typing import Any, Dict
from typing import Any, Dict, Union
import tomlkit
import tomlkit.exceptions
from tomlkit import TOMLDocument
from config_converter.converters.base import BaseConverter, ConversionError
@@ -15,7 +16,7 @@ class TomlConverter(BaseConverter):
FORMAT_NAME = "toml"
FILE_EXTENSIONS = ["toml"]
def read(self, source: str | Path) -> Dict[str, Any]:
def read(self, source: Union[str, Path]) -> Dict[str, Any]:
"""Read and parse a TOML configuration file."""
try:
with open(source, "r", encoding="utf-8") as f:
@@ -27,7 +28,7 @@ class TomlConverter(BaseConverter):
except PermissionError as e:
raise ConversionError(f"Permission denied: {source}") from e
def write(self, data: Dict[str, Any], target: str | Path) -> None:
def write(self, data: Dict[str, Any], target: Union[str, Path]) -> None:
"""Write configuration data to a TOML file."""
try:
doc: TOMLDocument = tomlkit.document()
@@ -35,7 +36,7 @@ class TomlConverter(BaseConverter):
doc[key] = value
with open(target, "w", encoding="utf-8") as f:
f.write(tomlkit.dumps(doc))
except (OSError, TypeError, tomlkit.exceptions.TypeError) as e:
except (OSError, TypeError) as e:
raise ConversionError(f"Failed to write TOML to {target}: {e}") from e
def parse(self, content: str) -> Dict[str, Any]:
@@ -52,5 +53,5 @@ class TomlConverter(BaseConverter):
for key, value in data.items():
doc[key] = value
return tomlkit.dumps(doc)
except (TypeError, ValueError, tomlkit.exceptions.TypeError) as e:
except (TypeError, ValueError) as e:
raise ConversionError(f"Failed to format data as TOML: {e}") from e