Skip to content

Fix normalize_string_prefix not lowercasing uppercase T t-string prefix#5185

Open
JSap0914 wants to merge 5 commits into
psf:mainfrom
JSap0914:fix-uppercase-T-string-prefix-normalization
Open

Fix normalize_string_prefix not lowercasing uppercase T t-string prefix#5185
JSap0914 wants to merge 5 commits into
psf:mainfrom
JSap0914:fix-uppercase-T-string-prefix-normalization

Conversation

@JSap0914

Copy link
Copy Markdown

Description

normalize_string_prefix is documented to "make all string prefixes lowercase", and it already normalises Ff and Bb. However, when t-string support was added in #4805 the Tt normalisation was accidentally omitted.

Bug: Black leaves T"..." unchanged instead of normalising it to t"...":

# Before (Black ≥ 26.5 with --target-version py314)
T"hello"T"hello"   # wrong — should be t"hello"
RT"hello"RT"hello"  # wrong — should be Rt"hello"
rT"hello"rT"hello"  # wrong — should be rt"hello"

Fix: Add a single .replace("T", "t") step to the existing chain in normalize_string_prefix.

Verification:

$ pytest tests/test_format.py -k pep_750 -v
PASSED  tests/test_format.py::test_simple_format[pep_750]

AI-assisted: this PR was prepared with the help of an AI coding tool.

Checklist - did you ...

  • Implement any code style changes under the --preview style, following the stability policy?
  • Add an entry in CHANGES.md if necessary?
  • Add / update tests if necessary?
  • Add new / update outdated documentation?

…efix

T"..." t-strings added in Python 3.14 (PEP 750) were not normalized
to t"..." by normalize_string_prefix. The function normalized F→f,
B→b, and removed U/u, but omitted T→t when t-string support was
introduced in psf#4805.

This caused T"..." to pass through unchanged instead of being
downcased like all other normalizable string prefixes.
Copilot AI review requested due to automatic review settings June 17, 2026 08:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment thread src/black/strings.py Outdated
new_prefix = (
orig_prefix.replace("F", "f")
.replace("B", "b")
.replace("T", "t")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This needs to go into the preview style.

@JSap0914

Copy link
Copy Markdown
Author

T→t prefix normalization is now gated behind Preview.normalize_tstring_prefix, so it only applies in --preview mode as requested.

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.

3 participants