Skip to content

Commit

Permalink
Unify type representation in error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
hukkin committed Oct 9, 2024
1 parent ac553e1 commit ce2a466
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/tomli_w/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ def format_literal(obj: object, ctx: Context, *, nest_level: int = 0) -> str:
return format_inline_array(obj, ctx, nest_level)
if isinstance(obj, Mapping):
return format_inline_table(obj, ctx)
raise TypeError(f"Object of type {type(obj)} is not TOML serializable")
raise TypeError(
f"Object of type '{type(obj).__qualname__}' is not TOML serializable"
)


def format_decimal(obj: Decimal) -> str:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@


def test_invalid_type_nested():
with pytest.raises(TypeError):
with pytest.raises(TypeError) as exc_info:
tomli_w.dumps({"bytearr": bytearray()})
assert str(exc_info.value) == "Object of type 'bytearray' is not TOML serializable"


def test_invalid_time():
Expand Down

0 comments on commit ce2a466

Please sign in to comment.