| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] test: cpython/Lib/test/test_str.py (TODO: 15) dependencies: dependent tests: (no tests depend on str) Legend:
|
Sorry, something went wrong.
| assert ascii(chr(0x9999)) == "'\\u9999'" | ||
| assert ascii(chr(0x0A)) == "'\\n'" | ||
|
|
||
| class MyStr(str): |
There was a problem hiding this comment.
[auto-format] reported by reviewdog 🐶
| class MyStr(str): | |
| class MyStr(str): |
Sorry, something went wrong.
| class MyStr(str): | ||
| pass | ||
|
|
||
| class Foo: |
There was a problem hiding this comment.
[auto-format] reported by reviewdog 🐶
| class Foo: | |
| class Foo: |
Sorry, something went wrong.
| def __repr__(self): | ||
| return MyStr("hello") | ||
|
|
||
| class Bar: |
There was a problem hiding this comment.
[auto-format] reported by reviewdog 🐶
| class Bar: | |
| class Bar: |
Sorry, something went wrong.
| def __repr__(self): | ||
| return MyStr("héllo") | ||
|
|
||
| assert type(ascii(Foo())) is MyStr |
There was a problem hiding this comment.
[auto-format] reported by reviewdog 🐶
| assert type(ascii(Foo())) is MyStr | |
| assert type(ascii(Foo())) is MyStr |
Sorry, something went wrong.
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Fixed in 6803cee. The CI failures were caused by ruff format --check flagging missing PEP 8 blank lines (two blank lines before top-level class definitions) in extra_tests/snippets/builtin_ascii.py. Applied ruff format to fix the formatting. |
Sorry, something went wrong.
|
✅ Actions performed
Review triggered.
|
Sorry, something went wrong.
📝 Walkthrough
WalkthroughThis PR modifies the ascii() function and related conversion paths to preserve str subclass types when the repr is already ASCII. Instead of always creating a new plain string, the function now returns the repr object directly if it's already ASCII, aligning with CPython's behavior. Changes
Sequence DiagramsequenceDiagram
actor User
participant ascii as ascii() Function
participant repr as repr() Protocol
participant check as ASCII Check
participant return_direct as Return Repr<br/>(subclass preserved)
participant escape as Escape Non-ASCII
participant return_new as Return New PyStr
User->>ascii: ascii(obj)
ascii->>repr: Get __repr__(obj)
repr-->>ascii: repr_result (PyRef<PyStr>)
ascii->>check: Is repr already ASCII?
alt Already ASCII
check->>return_direct: Yes
return_direct-->>ascii: repr_result unchanged
ascii-->>User: PyRef<PyStr> (subclass preserved)
else Non-ASCII
check->>escape: No, escape non-ASCII chars
escape->>return_new: Create new plain PyStr
return_new-->>ascii: new PyStr
ascii-->>User: PyRef<PyStr> (plain str)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Poem🚥 Pre-merge checks | ✅ 4 | ❌ 1 ❌ Failed checks (1 warning)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches 📝 Generate docstrings
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. ❤️ ShareComment @coderabbitai help to get the list of available commands and usage tips. |
Sorry, something went wrong.
There was a problem hiding this comment.
crates/vm/src/stdlib/builtins.rs (1)🤖 Prompt for all review comments with AI agents67-74: Code duplication with PyObject::ascii() in object.rs.
The implementation here is identical to PyObject::ascii() at lines 373-379 in crates/vm/src/protocol/object.rs. Consider having one delegate to the other to avoid maintaining the same logic in two places.
♻️ Option: Delegate to PyObject::ascii()🤖 Prompt for AI Agents#[pyfunction] pub fn ascii(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyStrRef> { - let repr = obj.repr(vm)?; - if repr.as_wtf8().is_ascii() { - Ok(repr) - } else { - Ok(vm.ctx.new_str(to_ascii(repr.as_wtf8()))) - } + obj.ascii(vm) }Verify each finding against the current code and only fix it if needed. In `@crates/vm/src/stdlib/builtins.rs` around lines 67 - 74, Replace the duplicated logic in builtins::ascii (the function pub fn ascii in builtins.rs) by delegating to the existing PyObject::ascii() implementation on the object (call the object's ascii method with the same vm) and return its PyResult<PyStrRef>; remove the manual repr/as_wtf8/is_ascii/to_ascii flow so the builtin just forwards to obj.ascii(vm) (adjust imports/signature if needed to match the method call).
Verify each finding against the current code and only fix it if needed. Nitpick comments: In `@crates/vm/src/stdlib/builtins.rs`: - Around line 67-74: Replace the duplicated logic in builtins::ascii (the function pub fn ascii in builtins.rs) by delegating to the existing PyObject::ascii() implementation on the object (call the object's ascii method with the same vm) and return its PyResult<PyStrRef>; remove the manual repr/as_wtf8/is_ascii/to_ascii flow so the builtin just forwards to obj.ascii(vm) (adjust imports/signature if needed to match the method call).
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 5fb0f8c6-cca6-48d9-a5fc-c96d61bd3787
📥 CommitsReviewing files that changed from the base of the PR and between 2a61237 and 6803cee.
⛔ Files ignored due to path filters (1)
Sorry, something went wrong.
|
@copilot check review #7455 (review) |
Sorry, something went wrong.
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Done in 77767fc. builtin_ascii() now delegates to obj.ascii(vm) and the to_ascii import was removed from builtins.rs. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
ascii() was always materializing a new plain str, which discarded str subclass types even when __repr__ had already returned an ASCII-only string. This diverged from CPython, which returns the original repr object unchanged in that case.
Behavior change
Call site updates
Regression coverage
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.
Summary by CodeRabbit
Bug Fixes
Tests