Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pyiceberg/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def _(_: PrimitiveType, value_str: str) -> bytes:

@singledispatch
def to_bytes(
primitive_type: PrimitiveType, _: bool | bytes | Decimal | date | datetime | float | int | str | time | uuid.UUID
primitive_type: PrimitiveType, value: bool | bytes | Decimal | date | datetime | float | int | str | time | uuid.UUID
) -> bytes:
"""Convert a built-in python value to bytes.

Expand All @@ -208,10 +208,10 @@ def to_bytes(

Args:
primitive_type (PrimitiveType): An implementation of the PrimitiveType base class.
_: The value to convert to bytes (The type of this value depends on which dispatched function is
value: The value to convert to bytes (The type of this value depends on which dispatched function is
used--check dispatchable functions for type hints).
"""
raise TypeError(f"scale does not match {primitive_type}")
raise TypeError(f"Cannot serialize to bytes, type {primitive_type} not supported: {value!r}")


@to_bytes.register(BooleanType)
Expand Down Expand Up @@ -408,7 +408,7 @@ def to_json(primitive_type: PrimitiveType, val: Any) -> L: # type: ignore
primitive_type (PrimitiveType): An implementation of the PrimitiveType base class.
val (Any): The arbitrary built-in value to convert into the right form
"""
raise TypeError(f"Cannot deserialize bytes, type {primitive_type} not supported: {val}")
raise TypeError(f"Cannot serialize to JSON, type {primitive_type} not supported: {val}")


@to_json.register(BooleanType)
Expand Down Expand Up @@ -547,7 +547,7 @@ def from_json(primitive_type: PrimitiveType, val: Any) -> L: # type: ignore
primitive_type (PrimitiveType): An implementation of the PrimitiveType base class.
val (Any): The arbitrary JSON value to convert into the right form
"""
raise TypeError(f"Cannot deserialize bytes, type {primitive_type} not supported: {str(val)}")
raise TypeError(f"Cannot deserialize JSON, type {primitive_type} not supported: {val}")


@from_json.register(BooleanType)
Expand Down
10 changes: 9 additions & 1 deletion tests/test_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,20 @@ def __repr__(self) -> str:

with pytest.raises(TypeError) as exc_info:
conversions.to_bytes(FooUnknownType(), "foo") # type: ignore
assert "scale does not match FooUnknownType()" in str(exc_info.value)
assert "Cannot serialize to bytes, type FooUnknownType() not supported: 'foo'" in str(exc_info.value)

with pytest.raises(TypeError) as exc_info:
conversions.from_bytes(FooUnknownType(), b"foo") # type: ignore
assert "Cannot deserialize bytes, type FooUnknownType() not supported: b'foo'" in str(exc_info.value)

with pytest.raises(TypeError) as exc_info:
conversions.to_json(FooUnknownType(), "foo") # type: ignore
assert "Cannot serialize to JSON, type FooUnknownType() not supported: foo" in str(exc_info.value)

with pytest.raises(TypeError) as exc_info:
conversions.from_json(FooUnknownType(), "foo") # type: ignore
assert "Cannot deserialize JSON, type FooUnknownType() not supported: foo" in str(exc_info.value)


@pytest.mark.parametrize(
"primitive_type, value, expected_error_message",
Expand Down
Loading