Skip to content

Commit e72170e

Browse files
dsfacciniDouweM
andauthored
Update has_content method to check content data (#3436)
Co-authored-by: Douwe Maan <[email protected]>
1 parent 230d018 commit e72170e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pydantic_ai_slim/pydantic_ai/messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ class FilePart:
10701070

10711071
def has_content(self) -> bool:
10721072
"""Return `True` if the file content is non-empty."""
1073-
return bool(self.content) # pragma: no cover
1073+
return bool(self.content.data)
10741074

10751075
__repr__ = _utils.dataclasses_no_defaults_repr
10761076

tests/test_messages.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,14 @@ def test_pre_usage_refactor_messages_deserializable():
422422
)
423423

424424

425+
def test_file_part_has_content():
426+
filepart = FilePart(content=BinaryContent(data=b'', media_type='application/pdf'))
427+
assert not filepart.has_content()
428+
429+
filepart.content.data = b'not empty'
430+
assert filepart.has_content()
431+
432+
425433
def test_file_part_serialization_roundtrip():
426434
# Verify that a serialized BinaryImage doesn't come back as a BinaryContent.
427435
messages: list[ModelMessage] = [

0 commit comments

Comments
 (0)