Skip to content

Commit

Permalink
chore(ruff): Fix tryceratops issues
Browse files Browse the repository at this point in the history
src/cihai/_internal/config_reader.py:49:19: TRY003 Avoid specifying long messages outside the exception class
src/cihai/_internal/config_reader.py:112:19: TRY003 Avoid specifying long messages outside the exception class
src/cihai/_internal/config_reader.py:187:19: TRY003 Avoid specifying long messages outside the exception class
src/cihai/core.py:104:19: TRY003 Avoid specifying long messages outside the exception class
Found 4 errors.
  • Loading branch information
tony committed Jul 1, 2023
1 parent 59d20a3 commit fbde364
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/cihai/_internal/config_reader.py
Expand Up @@ -12,6 +12,16 @@
FormatLiteral = t.Literal["json", "yaml"]


class ConfigFormatNotImplementedError(NotImplementedError):
def __init__(self, format: str):
return super().__init__(f"{format} not supported in configuration")


class ConfigExtensionNotImplementedError(NotImplementedError):
def __init__(self, ext: str, path: str | pathlib.Path):
return super().__init__(f"{ext} not supported in {path}")


class ConfigReader:
r"""Parse string data (YAML and JSON) into a dictionary.
Expand Down Expand Up @@ -46,7 +56,7 @@ def _load(format: "FormatLiteral", content: str) -> dict[str, t.Any]:
elif format == "json":
return t.cast(dict[str, t.Any], json.loads(content))
else:
raise NotImplementedError(f"{format} not supported in configuration")
raise NotImplementedError(format=format)

@classmethod
def load(cls, format: "FormatLiteral", content: str) -> "ConfigReader":
Expand Down Expand Up @@ -109,7 +119,7 @@ def _from_file(cls, path: pathlib.Path) -> dict[str, t.Any]:
elif path.suffix == ".json":
format = "json"
else:
raise NotImplementedError(f"{path.suffix} not supported in {path}")
raise ConfigExtensionNotImplementedError(ext=path.suffix, path=path)

return cls._load(
format=format,
Expand Down Expand Up @@ -184,7 +194,7 @@ def _dump(
indent=2,
)
else:
raise NotImplementedError(f"{format} not supported in config")
raise ConfigFormatNotImplementedError(format=format)

def dump(self, format: "FormatLiteral", indent: int = 2, **kwargs: t.Any) -> str:
r"""Dump via ConfigReader instance.
Expand Down
7 changes: 6 additions & 1 deletion src/cihai/core.py
Expand Up @@ -25,6 +25,11 @@
log = logging.getLogger(__name__)


class CihaiConfigError(exc.CihaiException):
def __init__(self):
return super().__init__("Invalid exception with configuration")


def is_valid_config(config: "UntypedDict") -> "TypeGuard[ConfigDict]":
return True

Expand Down Expand Up @@ -101,7 +106,7 @@ def __init__(
expand_config(_config, app_dirs)

if not is_valid_config(config=_config):
raise exc.CihaiException("Invalid exception with configuration")
raise CihaiConfigError()

self.config = _config

Expand Down

0 comments on commit fbde364

Please sign in to comment.