Centralize string access and name conversions
Extract the string-handling refactoring from #994 so it can be reviewed and merged before inline storage.
Add optional Value::as_str / as_str_heap accessors, retain generic TypeError conversion as try_to_str / try_to_str_heap, and migrate callers to these accessors or PyValue views. Move attribute-name conversion to EitherStr::as_value, share existing name helpers, and remove duplicated string dispatch and impossible conversion errors.
String storage, identity, JSON cache policy, and the dump format remain unchanged. Inline storage follows in #994.
Validation: full Monty Rust tests and all 718 Monty fixtures pass with memory-model-checks and ref-count-return; all prek hooks pass.
Summary by cubic
Centralizes how Monty reads string values and converts attribute names, so the upcoming inline-storage change (#994) touches one place instead of scattered match arms.
- Adds
Value::as_str/as_str_heap, which returnOption<&str>without allocating, and renames the fallibleto_str/to_str_heaptotry_to_str/try_to_str_heap. - Migrates callers that already know their value is a string to the new accessors, replacing
is_str+to_strpairs and hand-written dispatch in module finder, JSON, bytes, andstr.joinpaths. - Moves attribute-name conversion into
EitherStr::as_value, replacing theattribute_name_valuehelper, and refactorsopen/ path handling to borrow instead of copy.
Behavior changes
- Computed (non-interned) attribute names now resolve on all modules,
GenericAlias, and builtin types instead of always failing withAttributeError. Type::call_class_methodnow takesEitherStrdirectly.- Error messages for non-string arguments now come from one shared path in
try_to_str, and impossible conversion errors (e.g. non-str kwargs keys) were removed.
String storage, identity, JSON cache policy, and dump format are unchanged. New tests cover string argument errors, module attribute names, inline read/print behavior, and refcount retention.