Skip to content

Conversation

@AbduazizZiyodov
Copy link

@AbduazizZiyodov AbduazizZiyodov commented Jan 24, 2026

About

Implemented in similar fashion (e.g unittest, difflib etc.) by defining ThemeSection and registered theme on Theme class.

Basic highlighting shown in forum(green for all opcodes), but in this PR: one color maps to group of opcodes (e.g. blue for binary opcodes) -- gives better context and it is determined via color_by_opname method.

I have trouble with tests, now dis is defaulting to colored output and 2 tests were failing. I had to set environment variable: NO_COLOR=1... I think, there might be better ways of doing this, one is to define force_no_color flag(keyword only) to dis.dis function which I'm not certain. So, I would like to elaborate with you on that.

EDIT: Any ideas/additions on color mapping is encouraged :)

Sample screenshots

In dark mode dark_01 dark_02
In light mode light_01 light_02
No color no_color_01

Thanks.

Highlights opcode's name, arguments, exception table labels.
…ecause dis is not defaulting to syntax highligthing. Of course it needs better handling which I'm not sure now.
@bedevere-app
Copy link

bedevere-app bot commented Jan 24, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app
Copy link

bedevere-app bot commented Jan 24, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@python-cla-bot
Copy link

python-cla-bot bot commented Jan 24, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

Copy link
Member

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

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

Please add a NEWS entry and update What's New.

Copy link
Member

Choose a reason for hiding this comment

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

Please add tests for the colouration.

@bedevere-app
Copy link

bedevere-app bot commented Jan 24, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

False)

def print_instruction_line(self, instr, mark_as_current):
def print_instruction_line(self, instr, mark_as_current) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Please revert adding types.

fail_info: str = ANSIColors.BOLD_RED
reset: str = ANSIColors.RESET


Copy link
Member

Choose a reason for hiding this comment

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

Please re-add this line that was accidentally removed.

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

Please add a What's News entry and tests. I personally do not like this by default since I use grep/cut on the dis output so I would prefer a CLI option to enable colors. EDIT: not a concern anymore

"GET_AWAITABLE",
"GET_AITER",
"GET_ANEXT",
"END_ASYNC_FOR",
Copy link
Member

Choose a reason for hiding this comment

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

I am a bit confused with END_FOR and END_ASYNC_FOR being colored differently but I do not remember the exact effect of the latter.

exception_label: str = ANSIColors.CYAN
argument_detail: str = ANSIColors.GREY

op_stack: str = ANSIColors.BOLD_YELLOW
Copy link
Member

Choose a reason for hiding this comment

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

How were those categories determined? are they determined already like that in dis.rst?

end = entry.end_label
target = entry.target_label
print(f" L{start} to L{end} -> L{target} [{entry.depth}]{lasti}", file=file)
print(f" {theme.exception_label}L{start}{theme.reset} to {theme.exception_label}L{end}{theme.reset} -> {theme.exception_label}L{target}{theme.reset} [{entry.depth}]{lasti}", file=file)
Copy link
Member

Choose a reason for hiding this comment

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

Please wrap long lines under 80 chars. Ideally you put the newlines just after defining the color.

Or make temporary variables.

@bedevere-app
Copy link

bedevere-app bot commented Jan 24, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@hugovk
Copy link
Member

hugovk commented Jan 24, 2026

I personally do not like this by default since I use grep/cut on the dis output

Not to worry, it can stay on by default because colour is automatically disabled in pipes:

image

@picnixz
Copy link
Member

picnixz commented Jan 24, 2026

Oh! great then. I was worried about this. Do we plan to have colors for JSON? (or maybe we already do?) or for symtable? (the symtable cli is very rudimentary and I sometimes want a better one).

There are few modules who output formatted code (AFAIR, dis, symtable, json or even ast) so I wondered whether those would also be colorized. And if we eventually plan to add colors wherever we can (it should be a separate DPO thread/gh issue)

@hugovk
Copy link
Member

hugovk commented Jan 24, 2026

json, yes: https://docs.python.org/3/whatsnew/3.14.html#json. symtable, no[t yet].

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