Preserve str subclass results from __repr__ in plain str()#7454
Preserve str subclass results from __repr__ in plain str()#7454
str subclass results from __repr__ in plain str()#7454Conversation
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
str subclass results from __repr__ in plain str()
crates/vm/src/builtins/str.rs
Outdated
| if cls.is(vm.ctx.types.str_type) | ||
| && func_args.args.len() == 1 | ||
| && func_args.kwargs.is_empty() |
There was a problem hiding this comment.
[auto-format] reported by reviewdog 🐶
| if cls.is(vm.ctx.types.str_type) | |
| && func_args.args.len() == 1 | |
| && func_args.kwargs.is_empty() | |
| if cls.is(vm.ctx.types.str_type) && func_args.args.len() == 1 && func_args.kwargs.is_empty() |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [ ] test: cpython/Lib/test/test_str.py (TODO: 15) dependencies: dependent tests: (no tests depend on str) Legend:
|
|
@copilot fix CI failure |
Fixed by a555ce4. The only failing CI job was the old |
|
@copilot Fix still failng ci. |
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Pushed 008e4c6. I traced the red CI to the old 0852fa6 run: the real reported failure was |
str(obj)was flattening astrsubclass returned by__repr__into an exactstr, diverging from CPython. This only affected the plainstr(...)constructor path; subtype construction should still normalize to the requested subtype.Constructor behavior
str(...)fast path inPyStr::slot_newto returnPyObject::str(vm)directly for the single-argument, no-kwargs case.__str__/__repr__returns astrsubclass, instead of rebuilding a new exactstrfrom the underlying data.Regression coverage
Lib/test/test_str.py::StrTest.test_conversion, which already coversWithRepr(StrSubclass(...))and related conversion cases.Example:
Original prompt
str()discards str subclass type returned by__repr__#7450💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.