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
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: [x] test: cpython/Lib/test/test_str.py (TODO: 14) 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. |
Pushed 008e4c6. I traced the red CI to the old 0852fa6 run: the real reported failure was |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 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 unit tests (beta)
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 |
|
@copilot where the |
Checked and fixed in ae2b62e. The extra identity assertions in |
|
@copilot rebase to upstream/main |
Updated in 7a4ca2f. The branch now has |
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
7a4ca2f to
9a11d44
Compare
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.Lib/test/test_str.pychange aligned with CPythonv3.14.3rather than adding RustPython-only assertions there.extra_tests/snippets/builtin_str_subclass.pyfor the exactstr(...)path preserving astrsubclass returned by__str__and__repr__.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