Skip to content
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

Merged
merged 1 commit into from Sep 20, 2023

Conversation

dhruvmanila
Copy link
Member

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.

@dhruvmanila dhruvmanila linked an issue Sep 19, 2023 that may be closed by this pull request
@dhruvmanila dhruvmanila added rule Implementing or modifying a lint rule python312 Related to Python 3.12 labels Sep 19, 2023
Comment on lines +64 to +69
_ = f"a {'b' 'c' 'd'} e"
_ = f"""abc {"def" "ghi"} jkl"""
_ = f"""abc {
"def"
"ghi"
} jkl"""
Copy link
Member Author

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-hq
Copy link

codspeed-hq bot commented Sep 19, 2023

CodSpeed Performance Report

Merging #7515 will not alter performance

Comparing dhruv/issue-7298 (fe3eced) with dhruv/pep-701 (db4992a)

Summary

✅ 25 untouched benchmarks

(Tok::String { .. }, Tok::String { .. }) => (*a_range, *b_range),
(Tok::String { .. }, Tok::FStringStart) => (
*a_range,
indexer.fstring_ranges().innermost(b_range.start()).unwrap(),
Copy link
Member

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

Copy link
Member Author

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 😉

@dhruvmanila dhruvmanila merged commit b2cbb1a into dhruv/pep-701 Sep 20, 2023
13 of 16 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/issue-7298 branch September 20, 2023 11:58
dhruvmanila added a commit that referenced this pull request Sep 20, 2023
## 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.
dhruvmanila added a commit that referenced this pull request Sep 21, 2023
## 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.
dhruvmanila added a commit that referenced this pull request Sep 22, 2023
## 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.
dhruvmanila added a commit that referenced this pull request Sep 22, 2023
## 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.
dhruvmanila added a commit that referenced this pull request Sep 22, 2023
## 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.
dhruvmanila added a commit that referenced this pull request Sep 26, 2023
## 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.
dhruvmanila added a commit that referenced this pull request Sep 27, 2023
## 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.
dhruvmanila added a commit that referenced this pull request Sep 28, 2023
## 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.
dhruvmanila added a commit that referenced this pull request Sep 29, 2023
## 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.
dhruvmanila added a commit that referenced this pull request Sep 29, 2023
## 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python312 Related to Python 3.12 rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update ISC001, ISC002 to check in f-strings
2 participants