-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[refurb] Count codepoints not bytes for slice-to-remove-prefix-or-suffix (FURB188)
#13631
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d98ed4e
update test fixture
dylwil3 8f41c68
count chars not bytes
dylwil3 98dd23e
update snapshot
dylwil3 53969f9
update test fixture
dylwil3 ff622e2
fix indentation
dylwil3 0500602
update snapshot
dylwil3 70fc5ed
add as_usize method to Int
dylwil3 f90da17
use as_usize
dylwil3 e19c17a
unnecessary to_str
dylwil3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,7 +4,7 @@ use ruff_macros::{derive_message_formats, violation}; | |||||
use ruff_python_ast as ast; | ||||||
use ruff_python_semantic::SemanticModel; | ||||||
use ruff_source_file::Locator; | ||||||
use ruff_text_size::{Ranged, TextLen}; | ||||||
use ruff_text_size::Ranged; | ||||||
|
||||||
/// ## What it does | ||||||
/// Checks for the removal of a prefix or suffix from a string by assigning | ||||||
|
@@ -334,8 +334,10 @@ fn affix_matches_slice_bound(data: &RemoveAffixData, semantic: &SemanticModel) - | |||||
}), | ||||||
) => num | ||||||
.as_int() | ||||||
.and_then(ast::Int::as_u32) // Only support prefix removal for size at most `u32::MAX` | ||||||
.is_some_and(|x| x == string_val.to_str().text_len().to_u32()), | ||||||
// Only support prefix removal for size at most `u32::MAX` | ||||||
.and_then(ast::Int::as_u32) | ||||||
.and_then(|x| usize::try_from(x).ok()) | ||||||
.is_some_and(|x| x == string_val.to_str().chars().count()), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
( | ||||||
AffixKind::StartsWith, | ||||||
ast::Expr::Call(ast::ExprCall { | ||||||
|
@@ -370,7 +372,8 @@ fn affix_matches_slice_bound(data: &RemoveAffixData, semantic: &SemanticModel) - | |||||
value | ||||||
.as_int() | ||||||
.and_then(ast::Int::as_u32) | ||||||
.is_some_and(|x| x == string_val.to_str().text_len().to_u32()) | ||||||
.and_then(|x| usize::try_from(x).ok()) | ||||||
.is_some_and(|x| x == string_val.to_str().chars().count()) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}, | ||||||
), | ||||||
( | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest converting to a
u64
considering that you have to useusize::try_from
anyways (for 32 bit platforms)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you could consider adding a
as_usize
method toast::Int
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
went with the latter