Skip to content

Conversation

@JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jan 15, 2026

It can be used to build a string from code points (via append method) and strings (via write). It's similar to BytesWriter, but it has to keep track of the kind of string being created (1/2/4 bytes per code point).

I've optimized append but there are no mypyc primitives yet, so performance is still bad. I'll add mypyc primitives in a follow-up PR and do further optimizations as needed.

There is no truncate or __setitem__, unlike BytesWriter, since these could require the recomputation of kind, and this would be inefficient. My current thinking is that we won't support these.

I used LLM assist, especially for tests, but manually reviewed all changes.

@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JukkaL JukkaL changed the title [librt] Add minimal librt.strings.StringWriter class [librt] Add minimal librt.strings.StringWriter class (experimental) Jan 15, 2026
@JukkaL JukkaL merged commit d0129f6 into master Jan 15, 2026
23 checks passed
@JukkaL JukkaL deleted the string-writer branch January 15, 2026 15:14
michaelm-openai pushed a commit to michaelm-openai/mypy that referenced this pull request Jan 16, 2026
…ython#20588)

It can be used to build a string from code points (via `append` method)
and strings (via `write`). It's similar to `BytesWriter`, but it has to
keep track of the kind of string being created (1/2/4 bytes per code
point).

I've optimized `append` but there are no mypyc primitives yet, so
performance is still bad. I'll add mypyc primitives in a follow-up PR
and do further optimizations as needed.

There is no `truncate` or `__setitem__`, unlike `BytesWriter`, since
these could require the recomputation of kind, and this would be
inefficient. My current thinking is that we won't support these.

I used LLM assist, especially for tests, but manually reviewed all
changes.
michaelm-openai pushed a commit to michaelm-openai/mypy that referenced this pull request Jan 16, 2026
…ython#20588)

It can be used to build a string from code points (via `append` method)
and strings (via `write`). It's similar to `BytesWriter`, but it has to
keep track of the kind of string being created (1/2/4 bytes per code
point).

I've optimized `append` but there are no mypyc primitives yet, so
performance is still bad. I'll add mypyc primitives in a follow-up PR
and do further optimizations as needed.

There is no `truncate` or `__setitem__`, unlike `BytesWriter`, since
these could require the recomputation of kind, and this would be
inefficient. My current thinking is that we won't support these.

I used LLM assist, especially for tests, but manually reviewed all
changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants