You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
f(**d) rejects str keys containing lone surrogates: TypeError: keywords must be strings #8228
Unpacking a dict whose keys contain lone surrogates via ** raises TypeError: keywords must be strings, but the keys arestr instances. CPython accepts any str key through the ** call path.
defcollect(**kw):
returnkwcollect(**{'\udc81': 2}) # TypeError: keywords must be stringsdict(**{'\udc81': 1}) # TypeError: keywords must be strings
CPython 3.14.2:
>>> collect(**{'\udc81': 2})
{'\udc81': 2}
'\udc81' is a real str (e.g. produced by os.fsdecode of undecodable bytes, surrogateescape-decoded data, etc.), so this rejects valid programs. Verified on main @ 7044fdc.
Cause
ExecutingFrame::collect_ex_args (crates/vm/src/frame.rs:6539) validates kwargs keys with
key.downcast_ref::<PyUtf8Str>().ok_or_else(|| vm.new_type_error("keywords must be strings"))?;
A str containing a lone surrogate is a PyStr whose payload is Wtf8, not PyUtf8Str, so the downcast fails even though the key is a str. The same pattern exists at frame.rs:6521, crates/vm/src/stdlib/_functools.rs (partial), and crates/capi/src/abstract_.rs.
The deeper constraint is that KwArgs/FuncArgs keyword names are Rust String (UTF-8), so a surrogate-carrying key currently has no representation in the calling convention; fixing this properly means keyword names need to be Wtf8Buf (or PyStrRef) end-to-end. The error message check should be downcast_ref::<PyStr>() (matching CPython, which only rejects non-str keys) once the storage can hold it.
Found while running synthetic benchmark/compat suites; researched and reported by Claude on behalf of @youknowone.
Activity
HyoJongPark commentedon Jul 22, 2026
take
Allow lone-surrogate keyword keys in f(**d)
Allow lone-surrogate keyword keys in f(**d) (RustPython#8409)
Allow lone-surrogate keyword keys in f(**d) (#8409)