Skip to content

gh-139167: Allow users to hook gen_colors function to pyrepl Reader#141619

Open
gaogaotiantian wants to merge 5 commits intopython:mainfrom
gaogaotiantian:pyrepl-reader-gencolors
Open

gh-139167: Allow users to hook gen_colors function to pyrepl Reader#141619
gaogaotiantian wants to merge 5 commits intopython:mainfrom
gaogaotiantian:pyrepl-reader-gencolors

Conversation

@gaogaotiantian
Copy link
Member

@gaogaotiantian gaogaotiantian commented Nov 16, 2025

I'm working on using pyrepl for pdb (at least most of it). I like the real-time color rendering for user's code, but we need some modification for pdb. The user could type a pdb command or a piece of valid python code. The problem now is we have some pdb commands that are either keywords or builtins (continue, break, list). We probably want to make all pdb commands the same color.

In order to do that, we can create a customized gen_colors function for pdb - use the original gen_colors mostly, but with some extra checks on the first word.

However, there's no way to hook that into pyrepl now. I think this change should be trivial enough without breaking the existing code or making the code base too messy. We already have plenty of code that changes the Reader object at run-time so that won't be an exception either.

@gaogaotiantian
Copy link
Member Author

@ambv could you take a look when you have some time? I believe you implemented the original feature for real-time color in REPL.

@gaogaotiantian
Copy link
Member Author

Friendly ping @ambv if you have some time to check this PR

@gaogaotiantian
Copy link
Member Author

It seems like @ambv is quite busy recently. Maybe @pablogsal or @lysnikolaou could take a look at this PR? Thanks!

Copy link
Member

@lysnikolaou lysnikolaou left a comment

Choose a reason for hiding this comment

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

Left one comment, though the PR looks good to me in general. I'll leave it up to the others to merge this though, since it's been a while since I last looked at pyrepl code unfortunately.

lxy: tuple[int, int] = field(init=False)
scheduled_commands: list[str] = field(default_factory=list)
can_colorize: bool = False
gen_colors: Callable[[str], Iterator[ColorSpan]] = field(default=gen_colors)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the field call here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right we probably don't need that.

@gaogaotiantian
Copy link
Member Author

Thanks @lysnikolaou , this kind of blocks the progress of using pyrepl for pdb - which I think is an important improvement. The feature freeze is in 3 month and I hope I can make it.

For this specific feature, I think it's pretty obvious that it does not impact how the code works for now. It's a relatively small change where an extra internal hook is exposed (and there are already plenty of them). It should be considered relatively safe. The code change itself is also small. I just hope that I can get an approval for this and start working on the actual pdb part.

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.

2 participants