Skip to content

Commit

Permalink
Merge pull request #92 from DanCardin/dc/bad-error-message
Browse files Browse the repository at this point in the history
fix: Incorrect error message when using an invalid base class type.
  • Loading branch information
DanCardin authored Jan 5, 2024
2 parents 19e545c + 3c6e0d7 commit 77682eb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.15.3

- fix: Incorrect error message when using an invalid base class type.

## 0.15.2

- fix: Process `action` inference, taking into account `Optional`/`| None`.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cappa"
version = "0.15.2"
version = "0.15.3"
description = "Declarative CLI argument parser."

repository = "https://github.com/dancardin/cappa"
Expand Down
4 changes: 2 additions & 2 deletions src/cappa/class_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def from_cls(cls, obj: type) -> ClassTypes:
if hasattr(obj, "__attrs_attrs__"):
return cls.attrs

raise ValueError( # pragma: no cover
f"'{cls}' is not a currently supported base class. "
raise ValueError(
f"'{obj.__qualname__}' is not a currently supported kind of class. "
"Must be one of: dataclass, pydantic, or attrs class."
)

Expand Down
14 changes: 14 additions & 0 deletions tests/test_class_inspect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest
from cappa.class_inspect import ClassTypes


def test_invalid_class_base():
class Random:
...

with pytest.raises(ValueError) as e:
ClassTypes.from_cls(Random)
assert (
"'test_invalid_class_base.<locals>.Random' is not a currently supported kind of class."
in str(e.value)
)

0 comments on commit 77682eb

Please sign in to comment.