Vendor CPython's textwrap
Stacked on #1298: that PR's branch lives in a fork, so the base here is `main` and the diff also shows its commits. Only the last two commits are new:
- `Add str.translate, str.maketrans and re.VERBOSE`
- `Vendor CPython's textwrap`
What
`import textwrap` runs CPython 3.14's own `Lib/textwrap.py`.
- `str.translate` / `str.maketrans` (new `types/str_translate.rs`), matching CPython's behaviour and error messages. The table is looked up with generic subscription, and the result is built with `StringBuilder`.
- `re.VERBOSE` / `re.X` exposed, and included in the pattern repr.
- Patch `0003-textwrap-no-del`: Monty does not parse `del` yet (#1032), and cannot read a builtin method without calling it (`patsearch = pattern.search`).
- Registered in the type checker, JS sandbox module list and typeshed; docs and `limitations/` updated.
Divergences (documented)
- `TextWrapper.word_punct`, `letter`, `nowhitespace` and `whitespace` stay as class attributes.
- A `translate` mapping to a surrogate raises `ValueError`, since Monty strings cannot hold lone surrogates.
- `bytes.translate` / `bytes.maketrans` are not implemented.
Tests
New `str__translate` and `textwrap__module` cases and `re.VERBOSE` asserts in `re__basic`, run on Monty and CPython. `cargo nextest -p monty -p monty-type-checking -p monty-types`, `make lint-rs`, `make check-stdlib`, `make check-typeshed` and `branch_diff.py --check` pass.
Summary by cubic
Vendors CPython's own pure-Python textwrap.py and its upstream test suite, so import textwrap works without a Rust port, and adds the str.translate/str.maketrans methods and re.VERBOSE/re.X that they need. The module is embedded in the binary and runs like a file module: compiled per session, cached by name, with no OS call.
Infrastructure
crates/monty/stdlib/vendor.tomlpins CPython v3.14.10;make vendor-stdlibdownloads the files and LICENSE, appliespatches/*.patch, and generates the embedded source table.make check-stdlibruns in CI and fails if vendored files drift from the pinned release.make stdlib-candidatesreports which stdlib modules the current binary can load and the first blocker of each.- The 68 upstream
test_textwrap.pytests run on Monty and CPython; the shared unittest patch dropswith_traceback(), which Monty exceptions lack, and each class lists its test methods since Monty has nodir(). - The vendored CPython test patches are skipped in codespell, since their context lines quote upstream test code.
Divergences
- One patch works around
delnot parsing (#1032) — the class-bodydelis dropped anddel chunks[-1]becomes.pop()— and bound builtin methods not being readable without a call;dedent's error names the type via__name__since Monty types have no__qualname__. str.translatebuilds its output through a single memory-checked path, so both mapped values and unmapped misses stay within the resource limits, and validates its arguments before copying the receiver, so an invalid call on a string too large to copy raisesTypeErrorrather thanMemoryError.- A translate mapping to a surrogate code point raises
ValueError, since Monty strings cannot hold lone surrogates;bytes.translate/bytes.maketransare not implemented.