unicodedata: Removed unneeded UnicodeVersion struct - #8131
Conversation
📝 WalkthroughWalkthrough
ChangesUnicode version flag refactor
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/stdlib/build.rs`:
- Around line 659-664: The escaped quotes in the println! macro's format string
are causing literal quote characters to be embedded in the RUST_UNICODE_VERSION
environment variable value. Remove the `\"` escape sequences from the format
string so that the version string contains only the numeric value without
literal quotes. The format string should output the version directly as `15.1.0`
rather than `"15.1.0"`.
In `@crates/stdlib/src/unicodedata.rs`:
- Line 486: The digit() method at line 486 is hardcoding true as the modern flag
in the lookup_numeric_val(ch, true) call, while the decimal() and numeric()
methods both use lookup_numeric_val(ch, self.modern). This inconsistency means
digit() will always use modern tables regardless of the Unicode version. Change
the hardcoded true to self.modern in the digit() method's lookup_numeric_val()
call to match the consistent behavior used in decimal() and numeric().
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: fca68cc1-521d-46c8-961b-917baeb34e36
📒 Files selected for processing (2)
crates/stdlib/build.rscrates/stdlib/src/unicodedata.rs
5a42103 to
6315476
Compare
|
I'm not sure the Windows test failed on something completely unrelated to this patch. 🤔 |
I've restarted it |
ShaharNaveh
left a comment
There was a problem hiding this comment.
I like this cleanup!
tysm:)
youknowone
left a comment
There was a problem hiding this comment.
Thank you! reverting the build system part will make it perfect
6315476 to
3930c0a
Compare
|
Reverted. I renamed the PR to match the change as well. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/stdlib/src/unicodedata.rs (1)
533-558: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDeduplicate the version-string formatting.
The
X.Y.Zformatting is repeated three times: themodernbranch here, the module-levelunidata_version(Line 552), and they share identical logic differing only in the version tuple. Extract the differing tuple, then format once.♻️ Proposed refactor
Add a small helper:
fn unicode_version_string(modern: bool) -> String { let (major, minor, patch) = if modern { char::UNICODE_VERSION } else { (3, 2, 0) }; format!("{major}.{minor}.{patch}") }Then collapse both call sites:
#[pygetset] fn unidata_version(&self) -> String { - if self.modern { - format!( - "{}.{}.{}", - char::UNICODE_VERSION.0, - char::UNICODE_VERSION.1, - char::UNICODE_VERSION.2 - ) - } else { - "3.2.0".into() - } + unicode_version_string(self.modern) }#[pyattr] fn unidata_version(_vm: &VirtualMachine) -> String { - format!( - "{}.{}.{}", - char::UNICODE_VERSION.0, - char::UNICODE_VERSION.1, - char::UNICODE_VERSION.2 - ) + unicode_version_string(true) }As per coding guidelines: "When branches differ only in a value but share common logic, extract the differing value first, then call the common logic once to avoid duplicate code."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/stdlib/src/unicodedata.rs` around lines 533 - 558, The version string formatting logic in `X.Y.Z` format is duplicated in both the `modern` branch and the `unidata_version` function. Create a helper function that accepts a boolean parameter to determine whether to use modern (char::UNICODE_VERSION) or legacy (3, 2, 0) version tuples, then format the version string once within that helper. Replace both the conditional formatting in the `modern` branch and the formatting in the `unidata_version` function body with calls to this new helper to eliminate the duplication.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/stdlib/src/unicodedata.rs`:
- Around line 533-558: The version string formatting logic in `X.Y.Z` format is
duplicated in both the `modern` branch and the `unidata_version` function.
Create a helper function that accepts a boolean parameter to determine whether
to use modern (char::UNICODE_VERSION) or legacy (3, 2, 0) version tuples, then
format the version string once within that helper. Replace both the conditional
formatting in the `modern` branch and the formatting in the `unidata_version`
function body with calls to this new helper to eliminate the duplication.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 5a03474b-5f3e-4f17-8174-8cf85eb8471d
📒 Files selected for processing (1)
crates/stdlib/src/unicodedata.rs
Summary
unicodedata's version can be const evaluated and doesn't need to allocate.Summary by CodeRabbit