Skip to content

Conversation

StanFromIreland
Copy link
Member

@StanFromIreland StanFromIreland commented Oct 19, 2025

@StanFromIreland
Copy link
Member Author

StanFromIreland commented Oct 19, 2025

@terryjreedy What do you think about this approach in general? It is a cut/paste job with some minor fixup's to get tests passing, so it needs some cleaning up. We could also consider importing duplicated logic. This will also fix the reported issue, and probably a few more.

@StanFromIreland
Copy link
Member Author

cc @ambv you may find this use of your code interesting :-)

@StanFromIreland
Copy link
Member Author

I need to work on this a bit more, I ran the tests without gui. From manual testing it looks promising.

@StanFromIreland
Copy link
Member Author

Down to four errors, three are because the old colorizer would continue on errornous syntax, whereas tokenizing is much stricter. I added a line-by-line fallback to cover some test cases, but I think in general more complex fallbacks (maybe trying a few lines at a time?) are worth it, and so we would need to accept some differences with the old implementation.

I will leave this till I hear more from Terry.

@terryjreedy terryjreedy changed the title gh-140334: Use pyrepl's colorizer in IDLE gh-140347: Use pyrepl's colorizer in IDLE Oct 20, 2025


def gen_colors(buffer: str) -> Iterator[ColorSpan]:
"""Returns a list of index spans to color using the given color tag.
Copy link
Member

Choose a reason for hiding this comment

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

This is a generator function, which returns a generator-iterator that yields ColorSpans. The class name need not be repeated.

Suggested change
"""Returns a list of index spans to color using the given color tag.
"""Yield spans within buffer to be colored.

@terryjreedy
Copy link
Member

General comments belong on the new issue. See questions there.

@StanFromIreland
Copy link
Member Author

Manually testing some long files (_pydatetime.py), I could spot no issues on a general inspection.

recovered = True
maxpos = max(maxpos, recovered_color.span.end)

# fall back to trying each line seperetly
Copy link
Member Author

Choose a reason for hiding this comment

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

Apart from this section and a few minor modifications above, it is the same logic as in Lib/_pyrepl/utils.py.

@StanFromIreland StanFromIreland marked this pull request as ready for review October 20, 2025 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants