gh-139167: Allow users to hook gen_colors function to pyrepl Reader#141619
gh-139167: Allow users to hook gen_colors function to pyrepl Reader#141619gaogaotiantian wants to merge 5 commits intopython:mainfrom
Conversation
|
@ambv could you take a look when you have some time? I believe you implemented the original feature for real-time color in REPL. |
|
Friendly ping @ambv if you have some time to check this PR |
|
It seems like @ambv is quite busy recently. Maybe @pablogsal or @lysnikolaou could take a look at this PR? Thanks! |
lysnikolaou
left a comment
There was a problem hiding this comment.
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.
Lib/_pyrepl/reader.py
Outdated
| 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) |
There was a problem hiding this comment.
Do we need the field call here?
There was a problem hiding this comment.
Right we probably don't need that.
|
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. |
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_colorsfunction for pdb - use the originalgen_colorsmostly, 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
Readerobject at run-time so that won't be an exception either.