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:52 +00:00
parent aa7f9ff532
commit 51dbe8c277

View File

@@ -2,7 +2,7 @@
import json import json
from pathlib import Path from pathlib import Path
from typing import Any, Dict from typing import Any, Dict, Union
from config_converter.converters.base import BaseConverter, ConversionError from config_converter.converters.base import BaseConverter, ConversionError
@@ -13,11 +13,12 @@ class JsonConverter(BaseConverter):
FORMAT_NAME = "json" FORMAT_NAME = "json"
FILE_EXTENSIONS = ["json"] FILE_EXTENSIONS = ["json"]
def read(self, source: str | Path) -> Dict[str, Any]: def read(self, source: Union[str, Path]) -> Dict[str, Any]:
"""Read and parse a JSON configuration file.""" """Read and parse a JSON configuration file."""
try: try:
with open(source, "r", encoding="utf-8") as f: with open(source, "r", encoding="utf-8") as f:
return json.load(f) data = json.load(f)
return data if data is not None else {}
except json.JSONDecodeError as e: except json.JSONDecodeError as e:
raise ConversionError(f"Invalid JSON in {source}: {e}") from e raise ConversionError(f"Invalid JSON in {source}: {e}") from e
except FileNotFoundError as e: except FileNotFoundError as e:
@@ -25,7 +26,7 @@ class JsonConverter(BaseConverter):
except PermissionError as e: except PermissionError as e:
raise ConversionError(f"Permission denied: {source}") from 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 JSON file.""" """Write configuration data to a JSON file."""
try: try:
with open(target, "w", encoding="utf-8") as f: with open(target, "w", encoding="utf-8") as f:
@@ -36,7 +37,8 @@ class JsonConverter(BaseConverter):
def parse(self, content: str) -> Dict[str, Any]: def parse(self, content: str) -> Dict[str, Any]:
"""Parse JSON content from a string.""" """Parse JSON content from a string."""
try: try:
return json.loads(content) data = json.loads(content)
return data if data is not None else {}
except json.JSONDecodeError as e: except json.JSONDecodeError as e:
raise ConversionError(f"Invalid JSON content: {e}") from e raise ConversionError(f"Invalid JSON content: {e}") from e