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

Ignore quote escapes in expression part of f-string #7597

Merged
merged 3 commits into from
Sep 25, 2023

Conversation

dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Sep 22, 2023

Summary

This PR fixes the following issues w.r.t. the PEP 701 changes:

  1. Mark all unformatted comments inside f-strings as formatted only after the
    f-string has been formatted.
  2. Do not escape or remove the quote escape when normalizing the expression
    part of a f-string.

This PR also updates the --files-with-errors number to be 1 less. This is
because we can now parse the test_fstring.py
file in the CPython repository which contains the new f-string syntax. This is
also the file which updates the similarity index for CPython compared to main.

Test Plan

cargo test -p ruff_python_formatter

Ecosystem checks

dhruv/formatter-fstring-quote

project similarity index total files changed files
cpython 0.76051 1789 1632
django 0.99983 2760 36
transformers 0.99963 2587 323
twine 1.00000 33 0
typeshed 0.99979 3496 22
warehouse 0.99967 648 15
zulip 0.99972 1437 21

main

project similarity index total files changed files
cpython 0.76083 1789 1631
django 0.99983 2760 36
transformers 0.99963 2587 323
twine 1.00000 33 0
typeshed 0.99979 3496 22
warehouse 0.99967 648 15
zulip 0.99972 1437 21

@dhruvmanila dhruvmanila added formatter Related to the formatter python312 Related to Python 3.12 labels Sep 22, 2023
@dhruvmanila dhruvmanila merged commit f5cd461 into dhruv/pep-701 Sep 25, 2023
14 of 16 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/formatter-fstring-quote branch September 25, 2023 07:36
@dhruvmanila dhruvmanila linked an issue Sep 25, 2023 that may be closed by this pull request
dhruvmanila added a commit that referenced this pull request Sep 26, 2023
## Summary

This PR fixes the following issues w.r.t. the PEP 701 changes:
1. Mark all unformatted comments inside f-strings as formatted only _after_ the
   f-string has been formatted.
2. Do not escape or remove the quote escape when normalizing the expression
   part of a f-string.

This PR also updates the `--files-with-errors` number to be 1 less. This is
because we can now parse the
[`test_fstring.py`](https://discord.com/channels/1039017663004942429/1082324263199064206/1154633274887516254)
file in the CPython repository which contains the new f-string syntax. This is
also the file which updates the similarity index for CPython compared to main.

## Test Plan

`cargo test -p ruff_python_formatter`

### Ecosystem checks

#### `dhruv/formatter-fstring-quote`

| project | similarity index | total files | changed files |

|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76051 | 1789 | 1632 |
| django | 0.99983 | 2760 | 36 |
| transformers | 0.99963 | 2587 | 323 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99979 | 3496 | 22 |
| warehouse | 0.99967 | 648 | 15 |
| zulip | 0.99972 | 1437 | 21 |

#### `main`

| project | similarity index | total files | changed files |

|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1631 |
| django | 0.99983 | 2760 | 36 |
| transformers | 0.99963 | 2587 | 323 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99979 | 3496 | 22 |
| warehouse | 0.99967 | 648 | 15 |
| zulip | 0.99972 | 1437 | 21 |
dhruvmanila added a commit that referenced this pull request Sep 27, 2023
## Summary

This PR fixes the following issues w.r.t. the PEP 701 changes:
1. Mark all unformatted comments inside f-strings as formatted only _after_ the
   f-string has been formatted.
2. Do not escape or remove the quote escape when normalizing the expression
   part of a f-string.

This PR also updates the `--files-with-errors` number to be 1 less. This is
because we can now parse the
[`test_fstring.py`](https://discord.com/channels/1039017663004942429/1082324263199064206/1154633274887516254)
file in the CPython repository which contains the new f-string syntax. This is
also the file which updates the similarity index for CPython compared to main.

## Test Plan

`cargo test -p ruff_python_formatter`

### Ecosystem checks

#### `dhruv/formatter-fstring-quote`

| project | similarity index | total files | changed files |

|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76051 | 1789 | 1632 |
| django | 0.99983 | 2760 | 36 |
| transformers | 0.99963 | 2587 | 323 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99979 | 3496 | 22 |
| warehouse | 0.99967 | 648 | 15 |
| zulip | 0.99972 | 1437 | 21 |

#### `main`

| project | similarity index | total files | changed files |

|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1631 |
| django | 0.99983 | 2760 | 36 |
| transformers | 0.99963 | 2587 | 323 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99979 | 3496 | 22 |
| warehouse | 0.99967 | 648 | 15 |
| zulip | 0.99972 | 1437 | 21 |
dhruvmanila added a commit that referenced this pull request Sep 28, 2023
## Summary

This PR fixes the following issues w.r.t. the PEP 701 changes:
1. Mark all unformatted comments inside f-strings as formatted only _after_ the
   f-string has been formatted.
2. Do not escape or remove the quote escape when normalizing the expression
   part of a f-string.

This PR also updates the `--files-with-errors` number to be 1 less. This is
because we can now parse the
[`test_fstring.py`](https://discord.com/channels/1039017663004942429/1082324263199064206/1154633274887516254)
file in the CPython repository which contains the new f-string syntax. This is
also the file which updates the similarity index for CPython compared to main.

## Test Plan

`cargo test -p ruff_python_formatter`

### Ecosystem checks

#### `dhruv/formatter-fstring-quote`

| project | similarity index | total files | changed files |

|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76051 | 1789 | 1632 |
| django | 0.99983 | 2760 | 36 |
| transformers | 0.99963 | 2587 | 323 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99979 | 3496 | 22 |
| warehouse | 0.99967 | 648 | 15 |
| zulip | 0.99972 | 1437 | 21 |

#### `main`

| project | similarity index | total files | changed files |

|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1631 |
| django | 0.99983 | 2760 | 36 |
| transformers | 0.99963 | 2587 | 323 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99979 | 3496 | 22 |
| warehouse | 0.99967 | 648 | 15 |
| zulip | 0.99972 | 1437 | 21 |
dhruvmanila added a commit that referenced this pull request Sep 29, 2023
This PR fixes the following issues w.r.t. the PEP 701 changes:
1. Mark all unformatted comments inside f-strings as formatted only _after_ the
   f-string has been formatted.
2. Do not escape or remove the quote escape when normalizing the expression
   part of a f-string.

This PR also updates the `--files-with-errors` number to be 1 less. This is
because we can now parse the
[`test_fstring.py`](https://discord.com/channels/1039017663004942429/1082324263199064206/1154633274887516254)
file in the CPython repository which contains the new f-string syntax. This is
also the file which updates the similarity index for CPython compared to main.

`cargo test -p ruff_python_formatter`

| project | similarity index | total files | changed files |

|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76051 | 1789 | 1632 |
| django | 0.99983 | 2760 | 36 |
| transformers | 0.99963 | 2587 | 323 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99979 | 3496 | 22 |
| warehouse | 0.99967 | 648 | 15 |
| zulip | 0.99972 | 1437 | 21 |

| project | similarity index | total files | changed files |

|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1631 |
| django | 0.99983 | 2760 | 36 |
| transformers | 0.99963 | 2587 | 323 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99979 | 3496 | 22 |
| warehouse | 0.99967 | 648 | 15 |
| zulip | 0.99972 | 1437 | 21 |
dhruvmanila added a commit that referenced this pull request Sep 29, 2023
This PR fixes the following issues w.r.t. the PEP 701 changes:
1. Mark all unformatted comments inside f-strings as formatted only _after_ the
   f-string has been formatted.
2. Do not escape or remove the quote escape when normalizing the expression
   part of a f-string.

This PR also updates the `--files-with-errors` number to be 1 less. This is
because we can now parse the
[`test_fstring.py`](https://discord.com/channels/1039017663004942429/1082324263199064206/1154633274887516254)
file in the CPython repository which contains the new f-string syntax. This is
also the file which updates the similarity index for CPython compared to main.

`cargo test -p ruff_python_formatter`

| project | similarity index | total files | changed files |

|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76051 | 1789 | 1632 |
| django | 0.99983 | 2760 | 36 |
| transformers | 0.99963 | 2587 | 323 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99979 | 3496 | 22 |
| warehouse | 0.99967 | 648 | 15 |
| zulip | 0.99972 | 1437 | 21 |

| project | similarity index | total files | changed files |

|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1631 |
| django | 0.99983 | 2760 | 36 |
| transformers | 0.99963 | 2587 | 323 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99979 | 3496 | 22 |
| warehouse | 0.99967 | 648 | 15 |
| zulip | 0.99972 | 1437 | 21 |
dhruvmanila added a commit that referenced this pull request Sep 29, 2023
## Summary

This PR adds support for PEP 701 in Ruff. This is a rollup PR of all the
other individual PRs. The separate PRs were created for logic separation
and code reviews. Refer to each pull request for a detail description on
the change.

Refer to the PR description for the list of pull requests within this PR.

## Test Plan

### Formatter ecosystem checks

Explanation for the change in ecosystem check:
#7597 (comment)

#### `main`

```
| project      | similarity index  | total files       | changed files     |
|--------------|------------------:|------------------:|------------------:|
| cpython      |           0.76083 |              1789 |              1631 |
| django       |           0.99983 |              2760 |                36 |
| transformers |           0.99963 |              2587 |               319 |
| twine        |           1.00000 |                33 |                 0 |
| typeshed     |           0.99983 |              3496 |                18 |
| warehouse    |           0.99967 |               648 |                15 |
| zulip        |           0.99972 |              1437 |                21 |
```

#### `dhruv/pep-701`

```
| project      | similarity index  | total files       | changed files     |
|--------------|------------------:|------------------:|------------------:|
| cpython      |           0.76051 |              1789 |              1632 |
| django       |           0.99983 |              2760 |                36 |
| transformers |           0.99963 |              2587 |               319 |
| twine        |           1.00000 |                33 |                 0 |
| typeshed     |           0.99983 |              3496 |                18 |
| warehouse    |           0.99967 |               648 |                15 |
| zulip        |           0.99972 |              1437 |                21 |
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter python312 Related to Python 3.12
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update FormatStringContinuation to use the new f-string tokens
3 participants