Skip to content

gh-134158: Fix PyREPL coloring of double braces in f/t-strings #134159

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

Merged

Conversation

loic-simon
Copy link
Contributor

@loic-simon loic-simon commented May 17, 2025

This PR add a special-case in _pyrepl.utils.Span.from_token to correctly color double braces in f-strings or t-strings.

Before:

image

After:

image

@bedevere-app
Copy link

bedevere-app bot commented May 17, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@StanFromIreland
Copy link
Contributor

Looking at the after it still does not seem correct, the fifth and sixth example should both have a white pair of braces.

@loic-simon
Copy link
Contributor Author

Looking at the after it still does not seem correct, the fifth and sixth example should both have a white pair of braces.

Why do you think so? They only contain literal braces, no interpolation delimiters.

We could add a specific color for double-braces, to convey the meaning they are "special", like eg. VSCode default theme does:

image

but it should be a different color from interpolation delimiters, and I'm not sure we have this level of detail in PyREPL (for example "\u1234" isn't colored differently that other strings literals, whereas it is in VSCode)

@ZeroIntensity ZeroIntensity added topic-repl Related to the interactive shell needs backport to 3.14 bugs and security fixes labels May 17, 2025
Co-authored-by: Peter Bierma <[email protected]>
@python-cla-bot
Copy link

python-cla-bot bot commented May 17, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@ambv ambv merged commit 71ea6a6 into python:main May 19, 2025
47 checks passed
@miss-islington-app
Copy link

Thanks @loic-simon for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 19, 2025
…ythongh-134159)

(cherry picked from commit 71ea6a6)

Co-authored-by: Loïc Simon <[email protected]>
Co-authored-by: Loïc Simon <[email protected]>
Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Łukasz Langa <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented May 19, 2025

GH-134227 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label May 19, 2025
hugovk pushed a commit that referenced this pull request May 19, 2025
…gh-134159) (#134227)

Co-authored-by: Loïc Simon <[email protected]>
Co-authored-by: Loïc Simon <[email protected]>
Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Łukasz Langa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-repl Related to the interactive shell
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants