Skip to content

gh-136924: Suspend REPL colorizing when in a REPL interactive command #136926

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

olgarithms
Copy link
Contributor

@olgarithms olgarithms commented Jul 21, 2025

The proposed solution fixes the issuedescribed in #136924, following the logic of how history doesn't remember what was inside the interactive commands like help.

BEFORE:

Screenshot 2025-07-21 at 11 55 17

AFTER:

Screenshot 2025-07-21 at 12 09 44

While the fix is small I am having a hard time writing tests for it. Other colorization tests are inside test_reader.py, but unfortunately the suspension logic for colors gets triggered outside the Reader class, so a test like this fails:

def test_syntax_highlighting_suspended_in_help_context(self):
    code = dedent(
        """\
        print("hello")
        help
        int
        quit
        print("bye")
        """
    )
    expected = dedent(
        """\
        {b}print{z}{o}({z}{s}"hello"{z}{o}){z}
        {b}help{z}
        int
        quit
        {b}print{z}{o}({z}{s}"bye"{z}{o}){z}
        """
    ).format(**colors)
    events = code_to_events(code)
    reader, _ = handle_all_events(events)
    self.assert_screen_equal(reader, code, clean=True)
    self.assert_screen_equal(reader, expected)

Since that wouldn't work I tried adding a test inside test_interact, like:

def test_syntax_highlighting_suspended_in_help_context(self):
    console = InteractiveColoredConsole()
    source = dedent(
        """\
        print("hello")
        help
        int
        print("bye")
        p
        """
    )
    result = console.runsource(source)
    ...

but the console doesn't have access to the reader.screen and I couldn't see the colored output. (There is a small hack that we can do, if the test fails and we capture the result in stderr we can see the bytes, but this didn't feel right 😃 ).

I wanted to confirm this is the approach we want to go with, before potentially investing more time in the tests.
Looking forward to your thoughts, @ambv !

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.

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy