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 |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Summary by CodeRabbit