Skip to content

Update W605 to check in f-strings#7329

Merged
dhruvmanila merged 2 commits intodhruv/pep-701from
dhruv/issue-7295
Sep 19, 2023
Merged

Update W605 to check in f-strings#7329
dhruvmanila merged 2 commits intodhruv/pep-701from
dhruv/issue-7295

Conversation

@dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Sep 13, 2023

Summary

This PR updates the W605 (invalid-escape-sequence) to check inside f-strings. It also adds support to report violation on invalid escape sequence within f-strings w.r.t. the curly braces. So, the following cases will be identified:

f"\{1}"
f"\{{1}}"
f"{1:\}"

The new CPython parser also gives out a syntax warning for such cases:

fstring.py:1: SyntaxWarning: invalid escape sequence '\{'
  f"\{1}"
fstring.py:2: SyntaxWarning: invalid escape sequence '\{'
  f"\{{1}}"
fstring.py:3: SyntaxWarning: invalid escape sequence '\}'
  f"{1:\}"

Nested f-strings are supported here, so the generated fix is aware of that and will create an edit for the proper f-string.

Test Plan

Add new test cases for f-strings.

fixes: #7295

@dhruvmanila dhruvmanila added rule Implementing or modifying a lint rule python312 Related to Python 3.12 labels Sep 13, 2023
@dhruvmanila dhruvmanila linked an issue Sep 13, 2023 that may be closed by this pull request
@dhruvmanila dhruvmanila force-pushed the dhruv/issue-7295 branch 2 times, most recently from 3b1328f to a0496ef Compare September 14, 2023 02:40
@dhruvmanila dhruvmanila changed the base branch from dhruv/issue-7293 to dhruv/pep-701 September 14, 2023 02:40
@dhruvmanila dhruvmanila changed the base branch from dhruv/pep-701 to dhruv/issue-7290 September 14, 2023 02:50
@dhruvmanila dhruvmanila force-pushed the dhruv/issue-7295 branch 2 times, most recently from b00eb68 to 59bebae Compare September 14, 2023 06:06
@dhruvmanila dhruvmanila changed the base branch from dhruv/issue-7290 to dhruv/issue-7291 September 14, 2023 06:06
@dhruvmanila dhruvmanila marked this pull request as ready for review September 14, 2023 06:24
@codspeed-hq
Copy link

codspeed-hq bot commented Sep 18, 2023

CodSpeed Performance Report

Merging #7329 will improve performances by 2.38%

⚠️ No base runs were found

Falling back to comparing dhruv/issue-7295 (b88d5a0) with dhruv/pep-701 (c496d9c)

Summary

⚡ 1 improvements
✅ 24 untouched benchmarks

Benchmarks breakdown

Benchmark dhruv/pep-701 dhruv/issue-7295 Change
linter/all-rules[unicode/pypinyin.py] 16.1 ms 15.7 ms +2.38%

@dhruvmanila dhruvmanila changed the base branch from dhruv/issue-7291 to dhruv/pep-701 September 19, 2023 06:32
@dhruvmanila dhruvmanila merged commit db4992a into dhruv/pep-701 Sep 19, 2023
@dhruvmanila dhruvmanila deleted the dhruv/issue-7295 branch September 19, 2023 06:38
dhruvmanila added a commit that referenced this pull request Sep 20, 2023
This PR updates the `W605` (invalid-escape-sequence) to check inside
f-strings. It also adds support to report violation on invalid escape
sequence within f-strings w.r.t. the curly braces. So, the following
cases will be identified:

```python
f"\{1}"
f"\{{1}}"
f"{1:\}"
```

The new CPython parser also gives out a syntax warning for such cases:

```
fstring.py:1: SyntaxWarning: invalid escape sequence '\{'
  f"\{1}"
fstring.py:2: SyntaxWarning: invalid escape sequence '\{'
  f"\{{1}}"
fstring.py:3: SyntaxWarning: invalid escape sequence '\}'
  f"{1:\}"
```

Nested f-strings are supported here, so the generated fix is aware of that
and will create an edit for the proper f-string.

Add new test cases for f-strings.

fixes: #7295
dhruvmanila added a commit that referenced this pull request Sep 21, 2023
This PR updates the `W605` (invalid-escape-sequence) to check inside
f-strings. It also adds support to report violation on invalid escape
sequence within f-strings w.r.t. the curly braces. So, the following
cases will be identified:

```python
f"\{1}"
f"\{{1}}"
f"{1:\}"
```

The new CPython parser also gives out a syntax warning for such cases:

```
fstring.py:1: SyntaxWarning: invalid escape sequence '\{'
  f"\{1}"
fstring.py:2: SyntaxWarning: invalid escape sequence '\{'
  f"\{{1}}"
fstring.py:3: SyntaxWarning: invalid escape sequence '\}'
  f"{1:\}"
```

Nested f-strings are supported here, so the generated fix is aware of that
and will create an edit for the proper f-string.

Add new test cases for f-strings.

fixes: #7295
dhruvmanila added a commit that referenced this pull request Sep 22, 2023
This PR updates the `W605` (invalid-escape-sequence) to check inside
f-strings. It also adds support to report violation on invalid escape
sequence within f-strings w.r.t. the curly braces. So, the following
cases will be identified:

```python
f"\{1}"
f"\{{1}}"
f"{1:\}"
```

The new CPython parser also gives out a syntax warning for such cases:

```
fstring.py:1: SyntaxWarning: invalid escape sequence '\{'
  f"\{1}"
fstring.py:2: SyntaxWarning: invalid escape sequence '\{'
  f"\{{1}}"
fstring.py:3: SyntaxWarning: invalid escape sequence '\}'
  f"{1:\}"
```

Nested f-strings are supported here, so the generated fix is aware of that
and will create an edit for the proper f-string.

Add new test cases for f-strings.

fixes: #7295
dhruvmanila added a commit that referenced this pull request Sep 22, 2023
This PR updates the `W605` (invalid-escape-sequence) to check inside
f-strings. It also adds support to report violation on invalid escape
sequence within f-strings w.r.t. the curly braces. So, the following
cases will be identified:

```python
f"\{1}"
f"\{{1}}"
f"{1:\}"
```

The new CPython parser also gives out a syntax warning for such cases:

```
fstring.py:1: SyntaxWarning: invalid escape sequence '\{'
  f"\{1}"
fstring.py:2: SyntaxWarning: invalid escape sequence '\{'
  f"\{{1}}"
fstring.py:3: SyntaxWarning: invalid escape sequence '\}'
  f"{1:\}"
```

Nested f-strings are supported here, so the generated fix is aware of that
and will create an edit for the proper f-string.

Add new test cases for f-strings.

fixes: #7295
dhruvmanila added a commit that referenced this pull request Sep 22, 2023
This PR updates the `W605` (invalid-escape-sequence) to check inside
f-strings. It also adds support to report violation on invalid escape
sequence within f-strings w.r.t. the curly braces. So, the following
cases will be identified:

```python
f"\{1}"
f"\{{1}}"
f"{1:\}"
```

The new CPython parser also gives out a syntax warning for such cases:

```
fstring.py:1: SyntaxWarning: invalid escape sequence '\{'
  f"\{1}"
fstring.py:2: SyntaxWarning: invalid escape sequence '\{'
  f"\{{1}}"
fstring.py:3: SyntaxWarning: invalid escape sequence '\}'
  f"{1:\}"
```

Nested f-strings are supported here, so the generated fix is aware of that
and will create an edit for the proper f-string.

Add new test cases for f-strings.

fixes: #7295
dhruvmanila added a commit that referenced this pull request Sep 26, 2023
This PR updates the `W605` (invalid-escape-sequence) to check inside
f-strings. It also adds support to report violation on invalid escape
sequence within f-strings w.r.t. the curly braces. So, the following
cases will be identified:

```python
f"\{1}"
f"\{{1}}"
f"{1:\}"
```

The new CPython parser also gives out a syntax warning for such cases:

```
fstring.py:1: SyntaxWarning: invalid escape sequence '\{'
  f"\{1}"
fstring.py:2: SyntaxWarning: invalid escape sequence '\{'
  f"\{{1}}"
fstring.py:3: SyntaxWarning: invalid escape sequence '\}'
  f"{1:\}"
```

Nested f-strings are supported here, so the generated fix is aware of that
and will create an edit for the proper f-string.

Add new test cases for f-strings.

fixes: #7295
dhruvmanila added a commit that referenced this pull request Sep 27, 2023
This PR updates the `W605` (invalid-escape-sequence) to check inside
f-strings. It also adds support to report violation on invalid escape
sequence within f-strings w.r.t. the curly braces. So, the following
cases will be identified:

```python
f"\{1}"
f"\{{1}}"
f"{1:\}"
```

The new CPython parser also gives out a syntax warning for such cases:

```
fstring.py:1: SyntaxWarning: invalid escape sequence '\{'
  f"\{1}"
fstring.py:2: SyntaxWarning: invalid escape sequence '\{'
  f"\{{1}}"
fstring.py:3: SyntaxWarning: invalid escape sequence '\}'
  f"{1:\}"
```

Nested f-strings are supported here, so the generated fix is aware of that
and will create an edit for the proper f-string.

Add new test cases for f-strings.

fixes: #7295
dhruvmanila added a commit that referenced this pull request Sep 28, 2023
This PR updates the `W605` (invalid-escape-sequence) to check inside
f-strings. It also adds support to report violation on invalid escape
sequence within f-strings w.r.t. the curly braces. So, the following
cases will be identified:

```python
f"\{1}"
f"\{{1}}"
f"{1:\}"
```

The new CPython parser also gives out a syntax warning for such cases:

```
fstring.py:1: SyntaxWarning: invalid escape sequence '\{'
  f"\{1}"
fstring.py:2: SyntaxWarning: invalid escape sequence '\{'
  f"\{{1}}"
fstring.py:3: SyntaxWarning: invalid escape sequence '\}'
  f"{1:\}"
```

Nested f-strings are supported here, so the generated fix is aware of that
and will create an edit for the proper f-string.

Add new test cases for f-strings.

fixes: #7295
dhruvmanila added a commit that referenced this pull request Sep 29, 2023
This PR updates the `W605` (invalid-escape-sequence) to check inside
f-strings. It also adds support to report violation on invalid escape
sequence within f-strings w.r.t. the curly braces. So, the following
cases will be identified:

```python
f"\{1}"
f"\{{1}}"
f"{1:\}"
```

The new CPython parser also gives out a syntax warning for such cases:

```
fstring.py:1: SyntaxWarning: invalid escape sequence '\{'
  f"\{1}"
fstring.py:2: SyntaxWarning: invalid escape sequence '\{'
  f"\{{1}}"
fstring.py:3: SyntaxWarning: invalid escape sequence '\}'
  f"{1:\}"
```

Nested f-strings are supported here, so the generated fix is aware of that
and will create an edit for the proper f-string.

Add new test cases for f-strings.

fixes: #7295
dhruvmanila added a commit that referenced this pull request Sep 29, 2023
This PR updates the `W605` (invalid-escape-sequence) to check inside
f-strings. It also adds support to report violation on invalid escape
sequence within f-strings w.r.t. the curly braces. So, the following
cases will be identified:

```python
f"\{1}"
f"\{{1}}"
f"{1:\}"
```

The new CPython parser also gives out a syntax warning for such cases:

```
fstring.py:1: SyntaxWarning: invalid escape sequence '\{'
  f"\{1}"
fstring.py:2: SyntaxWarning: invalid escape sequence '\{'
  f"\{{1}}"
fstring.py:3: SyntaxWarning: invalid escape sequence '\}'
  f"{1:\}"
```

Nested f-strings are supported here, so the generated fix is aware of that
and will create an edit for the proper f-string.

Add new test cases for f-strings.

fixes: #7295
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 W605 to check in f-strings

2 participants