-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Update ISC001
, ISC002
to check in f-strings
#7515
Conversation
_ = f"a {'b' 'c' 'd'} e" | ||
_ = f"""abc {"def" "ghi"} jkl""" | ||
_ = f"""abc { | ||
"def" | ||
"ghi" | ||
} jkl""" |
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.
We didn't detect this in earlier version but with the granularity of the tokens, we can detect this as well.
CodSpeed Performance ReportMerging #7515 will not alter performanceComparing Summary
|
db4992a
to
101f9be
Compare
d559b0a
to
fe3eced
Compare
(Tok::String { .. }, Tok::String { .. }) => (*a_range, *b_range), | ||
(Tok::String { .. }, Tok::FStringStart) => ( | ||
*a_range, | ||
indexer.fstring_ranges().innermost(b_range.start()).unwrap(), |
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 find the use of fstring_ranges
here a bit unfortunate because:
- Looking up the range is at least:
O(log(n))
- So many unwraps
But I guess it's fine, considering that implicit concatenated strings are somewhat rare
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.
Yes, I agree. This could be solved with the introduction of a new StringList
node though as the AST would contain the range, so no lookups and no unwraps 😉
## Summary This PR updates the implicit string concatenation rules, specifically `ISC001` and `ISC002` to account for the new f-string tokens. `ISC003` checks for explicit string concatenation and is not affected by PEP 701 because it is based on AST. ### Implementation The implementation is based on the boundary tokens of the f-string which are `FStringStart` and `FStringEnd`. There are 4 cases to look for: 1. `String` followed by `FStringStart` 2. `FStringEnd` followed by `String` 3. `FStringEnd` followed by `FStringStart` 4. `String` followed by `String` For f-string tokens, we use the `Indexer` to get the entire range of the f-string. This is the range of the innermost f-string. ## Test Plan Add new test cases for nested f-strings.
## Summary This PR updates the implicit string concatenation rules, specifically `ISC001` and `ISC002` to account for the new f-string tokens. `ISC003` checks for explicit string concatenation and is not affected by PEP 701 because it is based on AST. ### Implementation The implementation is based on the boundary tokens of the f-string which are `FStringStart` and `FStringEnd`. There are 4 cases to look for: 1. `String` followed by `FStringStart` 2. `FStringEnd` followed by `String` 3. `FStringEnd` followed by `FStringStart` 4. `String` followed by `String` For f-string tokens, we use the `Indexer` to get the entire range of the f-string. This is the range of the innermost f-string. ## Test Plan Add new test cases for nested f-strings.
## Summary This PR updates the implicit string concatenation rules, specifically `ISC001` and `ISC002` to account for the new f-string tokens. `ISC003` checks for explicit string concatenation and is not affected by PEP 701 because it is based on AST. ### Implementation The implementation is based on the boundary tokens of the f-string which are `FStringStart` and `FStringEnd`. There are 4 cases to look for: 1. `String` followed by `FStringStart` 2. `FStringEnd` followed by `String` 3. `FStringEnd` followed by `FStringStart` 4. `String` followed by `String` For f-string tokens, we use the `Indexer` to get the entire range of the f-string. This is the range of the innermost f-string. ## Test Plan Add new test cases for nested f-strings.
## Summary This PR updates the implicit string concatenation rules, specifically `ISC001` and `ISC002` to account for the new f-string tokens. `ISC003` checks for explicit string concatenation and is not affected by PEP 701 because it is based on AST. ### Implementation The implementation is based on the boundary tokens of the f-string which are `FStringStart` and `FStringEnd`. There are 4 cases to look for: 1. `String` followed by `FStringStart` 2. `FStringEnd` followed by `String` 3. `FStringEnd` followed by `FStringStart` 4. `String` followed by `String` For f-string tokens, we use the `Indexer` to get the entire range of the f-string. This is the range of the innermost f-string. ## Test Plan Add new test cases for nested f-strings.
## Summary This PR updates the implicit string concatenation rules, specifically `ISC001` and `ISC002` to account for the new f-string tokens. `ISC003` checks for explicit string concatenation and is not affected by PEP 701 because it is based on AST. ### Implementation The implementation is based on the boundary tokens of the f-string which are `FStringStart` and `FStringEnd`. There are 4 cases to look for: 1. `String` followed by `FStringStart` 2. `FStringEnd` followed by `String` 3. `FStringEnd` followed by `FStringStart` 4. `String` followed by `String` For f-string tokens, we use the `Indexer` to get the entire range of the f-string. This is the range of the innermost f-string. ## Test Plan Add new test cases for nested f-strings.
## Summary This PR updates the implicit string concatenation rules, specifically `ISC001` and `ISC002` to account for the new f-string tokens. `ISC003` checks for explicit string concatenation and is not affected by PEP 701 because it is based on AST. ### Implementation The implementation is based on the boundary tokens of the f-string which are `FStringStart` and `FStringEnd`. There are 4 cases to look for: 1. `String` followed by `FStringStart` 2. `FStringEnd` followed by `String` 3. `FStringEnd` followed by `FStringStart` 4. `String` followed by `String` For f-string tokens, we use the `Indexer` to get the entire range of the f-string. This is the range of the innermost f-string. ## Test Plan Add new test cases for nested f-strings.
## Summary This PR updates the implicit string concatenation rules, specifically `ISC001` and `ISC002` to account for the new f-string tokens. `ISC003` checks for explicit string concatenation and is not affected by PEP 701 because it is based on AST. ### Implementation The implementation is based on the boundary tokens of the f-string which are `FStringStart` and `FStringEnd`. There are 4 cases to look for: 1. `String` followed by `FStringStart` 2. `FStringEnd` followed by `String` 3. `FStringEnd` followed by `FStringStart` 4. `String` followed by `String` For f-string tokens, we use the `Indexer` to get the entire range of the f-string. This is the range of the innermost f-string. ## Test Plan Add new test cases for nested f-strings.
## Summary This PR updates the implicit string concatenation rules, specifically `ISC001` and `ISC002` to account for the new f-string tokens. `ISC003` checks for explicit string concatenation and is not affected by PEP 701 because it is based on AST. ### Implementation The implementation is based on the boundary tokens of the f-string which are `FStringStart` and `FStringEnd`. There are 4 cases to look for: 1. `String` followed by `FStringStart` 2. `FStringEnd` followed by `String` 3. `FStringEnd` followed by `FStringStart` 4. `String` followed by `String` For f-string tokens, we use the `Indexer` to get the entire range of the f-string. This is the range of the innermost f-string. ## Test Plan Add new test cases for nested f-strings.
## Summary This PR updates the implicit string concatenation rules, specifically `ISC001` and `ISC002` to account for the new f-string tokens. `ISC003` checks for explicit string concatenation and is not affected by PEP 701 because it is based on AST. ### Implementation The implementation is based on the boundary tokens of the f-string which are `FStringStart` and `FStringEnd`. There are 4 cases to look for: 1. `String` followed by `FStringStart` 2. `FStringEnd` followed by `String` 3. `FStringEnd` followed by `FStringStart` 4. `String` followed by `String` For f-string tokens, we use the `Indexer` to get the entire range of the f-string. This is the range of the innermost f-string. ## Test Plan Add new test cases for nested f-strings.
## Summary This PR updates the implicit string concatenation rules, specifically `ISC001` and `ISC002` to account for the new f-string tokens. `ISC003` checks for explicit string concatenation and is not affected by PEP 701 because it is based on AST. ### Implementation The implementation is based on the boundary tokens of the f-string which are `FStringStart` and `FStringEnd`. There are 4 cases to look for: 1. `String` followed by `FStringStart` 2. `FStringEnd` followed by `String` 3. `FStringEnd` followed by `FStringStart` 4. `String` followed by `String` For f-string tokens, we use the `Indexer` to get the entire range of the f-string. This is the range of the innermost f-string. ## Test Plan Add new test cases for nested f-strings.
Summary
This PR updates the implicit string concatenation rules, specifically
ISC001
and
ISC002
to account for the new f-string tokens.ISC003
checks forexplicit string concatenation and is not affected by PEP 701 because it is based
on AST.
Implementation
The implementation is based on the boundary tokens of the f-string which are
FStringStart
andFStringEnd
. There are 4 cases to look for:String
followed byFStringStart
FStringEnd
followed byString
FStringEnd
followed byFStringStart
String
followed byString
For f-string tokens, we use the
Indexer
to get the entire range of the f-string.This is the range of the innermost f-string.
Test Plan
Add new test cases for nested f-strings.