Skip to content

Conversation

@MeGaGiGaGon
Copy link
Collaborator

@MeGaGiGaGon MeGaGiGaGon commented Jun 3, 2025

Description

Fixes #4677

My assumption on how the issue started is from a documentation issue on iter_fexpr_spans - the docs said "Spans are half-open ranges (left inclusive, right exclusive)", but it actually returns closed ranges. I assume the author of _get_illegal_split_indices then saw that, and added one to the range, making the ranges include the char after the f-string expr.

Update: Wrong, the spans are actually half-open, and I also got confused by it like the original author.

To fix this, I just removed that +1 on the ranges.

I looked at the other usages of iter_fexpr_spans, but all of them seem to properly use the ranges as closed as half-open.

I updated the tests that were changed by this, it was a small subsection that looks fine, and since no other code tests were effected that supports that everything else uses the spans as closed as half-open. I also fixed the docs for iter_fexpr_spans to prevent this in the future.

Checklist - did you ...

  • Add an entry in CHANGES.md if necessary?
  • Add / update tests if necessary?
  • Add new / update outdated documentation?

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the fix is right, but the change to the comment is wrong

"""
Yields spans corresponding to expressions in a given f-string.
Spans are half-open ranges (left inclusive, right exclusive).
Spans are closed ranges (left and right inclusive).
Copy link
Collaborator

@hauntsaninja hauntsaninja Jun 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't right, the spans are half-open ranges. See e.g.

check("""text {var} text""", [(5, 10)], ["{var}"])

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>>> """text {var} text"""[5]
'{'
>>> """text {var} text"""[10]
' '
>>> """text {var} text"""[5:10]
'{var}'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I also got confused by the ranges 😓 fixed

@cobaltt7 cobaltt7 merged commit 262ad62 into psf:main Jun 30, 2025
45 of 46 checks passed
@ToTorTH

This comment was marked as spam.

luketainton pushed a commit to luketainton/roboluke-tasks that referenced this pull request Sep 19, 2025
This PR contains the following updates:

| Package | Change | Age | Confidence |
|---|---|---|---|
| [black](https://github.com/psf/black) ([changelog](https://github.com/psf/black/blob/main/CHANGES.md)) | `<25.2.0,>=25.1.0` -> `<25.9.1,>=25.9.0` | [![age](https://developer.mend.io/api/mc/badges/age/pypi/black/25.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/black/25.1.0/25.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>psf/black (black)</summary>

### [`v25.9.0`](https://github.com/psf/black/blob/HEAD/CHANGES.md#2590)

[Compare Source](psf/black@25.1.0...25.9.0)

##### Highlights

- Remove support for pre-python 3.7 `await/async` as soft keywords/variable names
  ([#&#8203;4676](psf/black#4676))

##### Stable style

- Fix crash while formatting a long `del` statement containing tuples ([#&#8203;4628](psf/black#4628))
- Fix crash while formatting expressions using the walrus operator in complex `with`
  statements ([#&#8203;4630](psf/black#4630))
- Handle `# fmt: skip` followed by a comment at the end of file ([#&#8203;4635](psf/black#4635))
- Fix crash when a tuple appears in the `as` clause of a `with` statement ([#&#8203;4634](psf/black#4634))
- Fix crash when tuple is used as a context manager inside a `with` statement ([#&#8203;4646](psf/black#4646))
- Fix crash when formatting a `\` followed by a `\r` followed by a comment ([#&#8203;4663](psf/black#4663))
- Fix crash on a `\\r\n` ([#&#8203;4673](psf/black#4673))
- Fix crash on `await ...` (where `...` is a literal `Ellipsis`) ([#&#8203;4676](psf/black#4676))
- Fix crash on parenthesized expression inside a type parameter bound ([#&#8203;4684](psf/black#4684))
- Fix crash when using line ranges excluding indented single line decorated items
  ([#&#8203;4670](psf/black#4670))

##### Preview style

- Fix a bug where one-liner functions/conditionals marked with `# fmt: skip` would still
  be formatted ([#&#8203;4552](psf/black#4552))
- Improve `multiline_string_handling` with ternaries and dictionaries ([#&#8203;4657](psf/black#4657))
- Fix a bug where `string_processing` would not split f-strings directly after
  expressions ([#&#8203;4680](psf/black#4680))
- Wrap the `in` clause of comprehensions across lines if necessary ([#&#8203;4699](psf/black#4699))
- Remove parentheses around multiple exception types in `except` and `except*` without
  `as`. ([#&#8203;4720](psf/black#4720))
- Add `\r` style newlines to the potential newlines to normalize file newlines both from
  and to ([#&#8203;4710](psf/black#4710))

##### Parser

- Rewrite tokenizer to improve performance and compliance ([#&#8203;4536](psf/black#4536))
- Fix bug where certain unusual expressions (e.g., lambdas) were not accepted in type
  parameter bounds and defaults. ([#&#8203;4602](psf/black#4602))

##### Performance

- Avoid using an extra process when running with only one worker ([#&#8203;4734](psf/black#4734))

##### Integrations

- Fix the version check in the vim file to reject Python 3.8 ([#&#8203;4567](psf/black#4567))
- Enhance GitHub Action `psf/black` to read Black version from an additional section in
  pyproject.toml: `[project.dependency-groups]` ([#&#8203;4606](psf/black#4606))
- Build gallery docker image with python3-slim and reduce image size ([#&#8203;4686](psf/black#4686))

##### Documentation

- Add FAQ entry for windows emoji not displaying ([#&#8203;4714](psf/black#4714))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xMTYuMTAiLCJ1cGRhdGVkSW5WZXIiOiI0MS4xMTYuMTAiLCJ0YXJnZXRCcmFuY2giOiJtYWluIiwibGFiZWxzIjpbInR5cGUvZGVwZW5kZW5jaWVzIl19-->

Reviewed-on: https://git.tainton.uk/repos/roboluke/pulls/376
Co-authored-by: Renovate [BOT] <[email protected]>
Co-committed-by: Renovate [BOT] <[email protected]>
luketainton pushed a commit to luketainton/epage that referenced this pull request Oct 7, 2025
This PR contains the following updates:

| Package | Change | Age | Confidence |
|---|---|---|---|
| [black](https://github.com/psf/black) ([changelog](https://github.com/psf/black/blob/main/CHANGES.md)) | `<25.2.0,>=25.1.0` -> `<25.9.1,>=25.9.0` | [![age](https://developer.mend.io/api/mc/badges/age/pypi/black/25.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/black/25.1.0/25.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>psf/black (black)</summary>

### [`v25.9.0`](https://github.com/psf/black/blob/HEAD/CHANGES.md#2590)

[Compare Source](psf/black@25.1.0...25.9.0)

##### Highlights

- Remove support for pre-python 3.7 `await/async` as soft keywords/variable names
  ([#&#8203;4676](psf/black#4676))

##### Stable style

- Fix crash while formatting a long `del` statement containing tuples ([#&#8203;4628](psf/black#4628))
- Fix crash while formatting expressions using the walrus operator in complex `with`
  statements ([#&#8203;4630](psf/black#4630))
- Handle `# fmt: skip` followed by a comment at the end of file ([#&#8203;4635](psf/black#4635))
- Fix crash when a tuple appears in the `as` clause of a `with` statement ([#&#8203;4634](psf/black#4634))
- Fix crash when tuple is used as a context manager inside a `with` statement ([#&#8203;4646](psf/black#4646))
- Fix crash when formatting a `\` followed by a `\r` followed by a comment ([#&#8203;4663](psf/black#4663))
- Fix crash on a `\\r\n` ([#&#8203;4673](psf/black#4673))
- Fix crash on `await ...` (where `...` is a literal `Ellipsis`) ([#&#8203;4676](psf/black#4676))
- Fix crash on parenthesized expression inside a type parameter bound ([#&#8203;4684](psf/black#4684))
- Fix crash when using line ranges excluding indented single line decorated items
  ([#&#8203;4670](psf/black#4670))

##### Preview style

- Fix a bug where one-liner functions/conditionals marked with `# fmt: skip` would still
  be formatted ([#&#8203;4552](psf/black#4552))
- Improve `multiline_string_handling` with ternaries and dictionaries ([#&#8203;4657](psf/black#4657))
- Fix a bug where `string_processing` would not split f-strings directly after
  expressions ([#&#8203;4680](psf/black#4680))
- Wrap the `in` clause of comprehensions across lines if necessary ([#&#8203;4699](psf/black#4699))
- Remove parentheses around multiple exception types in `except` and `except*` without
  `as`. ([#&#8203;4720](psf/black#4720))
- Add `\r` style newlines to the potential newlines to normalize file newlines both from
  and to ([#&#8203;4710](psf/black#4710))

##### Parser

- Rewrite tokenizer to improve performance and compliance ([#&#8203;4536](psf/black#4536))
- Fix bug where certain unusual expressions (e.g., lambdas) were not accepted in type
  parameter bounds and defaults. ([#&#8203;4602](psf/black#4602))

##### Performance

- Avoid using an extra process when running with only one worker ([#&#8203;4734](psf/black#4734))

##### Integrations

- Fix the version check in the vim file to reject Python 3.8 ([#&#8203;4567](psf/black#4567))
- Enhance GitHub Action `psf/black` to read Black version from an additional section in
  pyproject.toml: `[project.dependency-groups]` ([#&#8203;4606](psf/black#4606))
- Build gallery docker image with python3-slim and reduce image size ([#&#8203;4686](psf/black#4686))

##### Documentation

- Add FAQ entry for windows emoji not displaying ([#&#8203;4714](psf/black#4714))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xMTYuMTAiLCJ1cGRhdGVkSW5WZXIiOiI0MS4xMTYuMTAiLCJ0YXJnZXRCcmFuY2giOiJtYWluIiwibGFiZWxzIjpbInR5cGUvZGVwZW5kZW5jaWVzIl19-->

Reviewed-on: https://git.tainton.uk/repos/epage/pulls/158
Co-authored-by: Renovate [BOT] <[email protected]>
Co-committed-by: Renovate [BOT] <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

string_processing: Substitutions are never put at the end of wrapped f-strings

5 participants