GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add more granularity to _pyrepl syntax theming for "keywords" · Issue #134953 · python/cpython

Add more granularity to _pyrepl syntax theming for "keywords" #134953

New issue
Copy link
New issue
Copy link
Closed
Closed
Add more granularity to _pyrepl syntax theming for "keywords"#134953
Copy link
Labels
3.14bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shellRelated to the interactive shelltriagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.type-featureA feature request or enhancementA feature request or enhancement

Description

@treyhunner
treyhunner
opened on May 30, 2025
Issue body actions

Feature or enhancement

Proposal:

I made a custom _colorize theme to try making my REPL syntax highlighting look similar to my text editor's.

This is the theme I used:

theme_with_dim_operators = default_theme.copy_with(
    syntax=Syntax(
        keyword=ANSIColors.GREEN,
        builtin=ANSIColors.BLUE,
        comment=ANSIColors.INTENSE_YELLOW,
        string=ANSIColors.CYAN,
        number=ANSIColors.CYAN,
        definition=ANSIColors.BLUE,
        soft_keyword=ANSIColors.BOLD_GREEN,
    ),
)

I then used this example code to check the highlighting between the two:

from math import pi
print(f"Welcome to Python {pi:.2f}")
name = None
if name is None:
    print("It's", True)

Pasting that code in my text editor (vim), looks like this:

Image

Pasting the same code in the REPL, looks like this:

Image

The granularity with syntax highlighting needs to stop somewhere, but I feel it would be nice to add a bit more granularity than is currently supported by _colorize.

In particular, it would be nice to distinguish between:

  1. Syntax keywords in general (if, is, def, for, with, etc.)
  2. Keywords that are variables (True, False, None)
  3. Imports in particular (from, import)

I feel that distinguishing between 1 and 2 is more important than between 1 and 3. While None is a keyword, seeing it appear in the same color as is and other keywords feels odd.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

  • gh-134953: Expand theming for True/False/None #135000
  • [3.14] gh-134953: Expand theming for True/False/None (GH-135000) #138928
  • gh-134953: Make the True/False/None check more efficient #138931
  • [3.14] gh-134953: Make the True/False/None check more efficient (GH-138931) #138939
Reacted by Tomas R., sobolevn, Stan Ulbrych and Daniel Hollas

Activity

  1. treyhunner
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on May 30, 2025
  2. picnixz
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    topic-replRelated to the interactive shellRelated to the interactive shell
    on May 30, 2025
  3. treyhunner commented on May 31, 2025

    @treyhunner
    treyhunner
    on May 31, 2025
    MemberAuthor
    More actions

    I looked into how Pygments highlights and how MagicPython (used by VS Code) highlights. Both have much more granularity than I expect _colorize will ever support, but I do think it's worth giving _colorize slightly more granularity in syntax highlighting.

    Pygments uses:

    • Keyword.Constant for True, False, and None
    • Keyword.Namespace for import and from
    • Keyword for if and most other keywords
    • Operator.Word for is, and, or, and not

    It seems like MagicPython uses:

    • constant.language.python for True, False, and None
    • keyword.control.import.python for import and from
    • keyword.control.import.python for if and most other keywords
    • keyword.operator.logical.python for is, and, or, and not

    Both of these syntax highlighters also seem to support a hierarchy (if custom highlighting is not defined for and/or/is then the same highlighting used for if and other keywords will be used.

  4. ambv
    added a commit that references this issue on Sep 15, 2025

    gh-134953: Expand theming for `True`/`False`/`None` (#135000)

    a5b9d0b
  5. miss-islington
    added a commit that references this issue on Sep 15, 2025

    pythongh-134953: Expand theming for `True`/`False`/`None` (pythonGH-1…

    a007a2e
  6. ambv commented on Sep 15, 2025

    @ambv
    ambv
    on Sep 15, 2025
    Contributor
    More actions

    The way we syntax color currently only tokenizes the code, it doesn't parse the code (modulo soft keywords). Therefore, differentiating "as" and "from" in imports is currently impossible. I would leave it out.

    I did land True/False/None differentiation, that makes sense since those keywords are values.

    Reacted by Trey Hunner
  7. ambv
    closed this as completedon Sep 15, 2025
  8. ambv
    added 2 commits that reference this issue on Sep 15, 2025

    pythongh-134953: Make the True/False/None check more efficient

    04f98d4

    pythongh-134953: Make the True/False/None check more efficient

    8e85d33
  9. hugovk
    added a commit that references this issue on Sep 15, 2025

    [3.14] gh-134953: Expand theming for `True`/`False`/`None` (GH-135000) (

    dc4d016
  10. ambv
    added a commit that references this issue on Sep 15, 2025

    gh-134953: Make the True/False/None check more efficient (GH-138931)

    811acc8
  11. miss-islington
    added a commit that references this issue on Sep 15, 2025

    pythongh-134953: Make the True/False/None check more efficient (pytho…

    569db03
  12. python
    deleted a comment from breindt4 on Sep 24, 2025
  13. python
    deleted a comment from breindt4 on Sep 24, 2025
  14. picnixz commented on Sep 24, 2025

    @picnixz
    picnixz
    on Sep 24, 2025
    Member
    More actions

    Re-opening until the 3.14 backport is approved.

  15. picnixz
    reopened this on Sep 24, 2025
  16. StanFromIreland
    added
    3.14bugs and security fixesbugs and security fixes
    on Sep 29, 2025
  17. picnixz
    added
    triagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.
    on Sep 29, 2025
  18. pablogsal
    added a commit that references this issue on Sep 29, 2025

    [3.14] gh-134953: Make the True/False/None check more efficient (GH-1…

    4372a05
  19. StanFromIreland
    closed this as completedon Sep 29, 2025
  20. pablogsal commented on Sep 29, 2025

    @pablogsal
    pablogsal
    on Sep 29, 2025
    Member
    More actions

    Therefore, differentiating "as" and "from" in imports is currently impossible.

    👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shellRelated to the interactive shelltriagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.type-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.