Skip to content

Accept bytearray as text in ImageFont - #10446

Open
radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:bytearray
Open

radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:bytearray

Conversation

@radarhere

@radarhere radarhere commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Currently, ImageFont, FreeTypeFont and TransposedFont have type hints saying that getbbox() accepts bytearray, and ImageFont does as well for getlength(). However, if you try and use them, FreeTypeFont raises errors, and ImageFont returns zero width.

#9908 suggests removing the bytearray type hints.
This PR is the alternative, to start supporting that functionality instead.

I don't have a strong preference for which way we go. #9908 does have to adjust one of our tests when removing the type hints. That test was added in #3907.

@radarhere radarhere added the Fonts label Nov 7, 2026

@akx akx left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this hadn't actually ever worked, I'm not sure there's demand for it 😄

@codspeed

codspeed Bot commented Nov 11, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 26.18%

3 warnings

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 5 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 5 benchmarks with a significant change ran in a different software environment

Their base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the changes might come from this difference rather than from the code. Open an affected benchmark to see what changed.

See affected benchmarks

❌ 5 regressed benchmarks
✅ 663 untouched benchmarks
⏩ 352 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_point_transform[1237x811-I] 8 ms 15.7 ms -49.29%
❌ test_point_lut[1237x811-L] 7.5 ms 11.9 ms -36.64%
❌ test_point_transform[1237x811-F] 8 ms 9.4 ms -14.82%
❌ test_point_lut[1237x811-RGBA] 28.3 ms 31.6 ms -10.57%
❌ test_point_transform[1237x811-RGBA] 28.8 ms 32.2 ms -10.44%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing radarhere:bytearray (fe7963b) with main (9f8a597)2

Open in CodSpeed

Footnotes

  1. 352 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (e188fea) during the generation of this report, so 9f8a597 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants