PngImageFile text is a property by radarhere · Pull Request #8648 · python-pillow/Pillow

This is part of #8362 - I'm hoping to break down that PR into easier-to-review chunks.

# Raises a UnicodeDecodeError in load_end
with Image.open("Tests/images/truncated_image.png") as im:
# The file is truncated
with pytest.raises(OSError):
im.text()

is testing

@property
def text(self) -> dict[str, str | iTXt]:

Since this is a @property, it can be accessed with just im.text