-
-
Notifications
You must be signed in to change notification settings - Fork 34k
gh-144207: Syntax highlighting(theming support) for dis module #144208
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
base: main
Are you sure you want to change the base?
Changes from all commits
1e0b1ab
468e561
9b637d1
4067c9b
f3a0d2e
a87f3cf
71c37a1
3e9a547
9310e30
8d389be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -534,6 +534,15 @@ difflib | |||||
| (Contributed by Jiahao Li in :gh:`134580`.) | ||||||
|
|
||||||
|
|
||||||
| dis | ||||||
| --------- | ||||||
|
|
||||||
| .. _whatsnew315-color-dis: | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this for? If it is not used please remove it. |
||||||
|
|
||||||
| * :func:`dis.dis` supports colored output by default which can also be controlled through ``NO_COLOR=1`` environment variable. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please wrap lines to 79 characters. As for controlling color, please link here instead. |
||||||
| (Contributed by Abduaziz Ziyodov in :gh:`144207`) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
|
|
||||||
| functools | ||||||
| --------- | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,6 +200,88 @@ class Difflib(ThemeSection): | |
| reset: str = ANSIColors.RESET | ||
|
|
||
|
|
||
| @dataclass(frozen=True, kw_only=True) | ||
| class Dis(ThemeSection): | ||
| label_bg: str = ANSIColors.BACKGROUND_BLUE | ||
| label_fg: str = ANSIColors.BLACK | ||
| exception_label: str = ANSIColors.CYAN | ||
| argument_detail: str = ANSIColors.GREY | ||
|
|
||
| op_stack: str = ANSIColors.BOLD_YELLOW | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Almost, I first grouped according to |
||
| op_load_store: str = ANSIColors.BOLD_CYAN | ||
| op_call_return: str = ANSIColors.BOLD_MAGENTA | ||
| op_binary_unary: str = ANSIColors.BOLD_BLUE | ||
| op_control_flow: str = ANSIColors.BOLD_GREEN | ||
| op_build: str = ANSIColors.BOLD_WHITE | ||
| op_exceptions: str = ANSIColors.BOLD_RED | ||
| op_other: str = ANSIColors.GREY | ||
|
|
||
| reset: str = ANSIColors.RESET | ||
|
|
||
| def color_by_opname(self, opname: str) -> str: | ||
| if opname in ( | ||
| "POP_TOP", | ||
| "POP_ITER", | ||
| "END_FOR", | ||
| "END_SEND", | ||
| "COPY", | ||
| "SWAP", | ||
| "PUSH_NULL", | ||
| "PUSH_EXC_INFO", | ||
| "NOP", | ||
| "CACHE", | ||
| ): | ||
| return self.op_stack | ||
|
|
||
| if opname.startswith(("LOAD_", "STORE_", "DELETE_", "IMPORT_")): | ||
| return self.op_load_store | ||
|
|
||
| if opname.startswith(("CALL", "RETURN")) or opname in ( | ||
| "YIELD_VALUE", | ||
| "MAKE_FUNCTION", | ||
| "SET_FUNCTION_ATTRIBUTE", | ||
| "RESUME", | ||
| ): | ||
| return self.op_call_return | ||
|
|
||
| if opname.startswith(("BINARY_", "UNARY_")) or opname in ( | ||
| "COMPARE_OP", | ||
| "IS_OP", | ||
| "CONTAINS_OP", | ||
| "GET_ITER", | ||
| "GET_YIELD_FROM_ITER", | ||
| "TO_BOOL", | ||
| "DELETE_SUBSCR", | ||
| ): | ||
| return self.op_binary_unary | ||
|
|
||
| if opname.startswith(("JUMP_", "POP_JUMP_", "FOR_ITER")) or opname in ( | ||
| "SEND", | ||
| "GET_AWAITABLE", | ||
| "GET_AITER", | ||
| "GET_ANEXT", | ||
| "END_ASYNC_FOR", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've read that
and it is specified under "General instructions" section while Almost all opcodes are dealing with stack, but That's my understanding. We might elaborate our discussion on categories in your next comment too. |
||
| "CLEANUP_THROW", | ||
| ): | ||
| return self.op_control_flow | ||
|
|
||
| if opname.startswith( | ||
| ("BUILD_", "LIST_", "DICT_", "UNPACK_") | ||
| ) or opname in ("SET_ADD", "MAP_ADD", "SET_UPDATE"): | ||
| return self.op_build | ||
|
|
||
| if opname.startswith(("SETUP_", "CHECK_")) or opname in ( | ||
| "POP_EXCEPT", | ||
| "RERAISE", | ||
| "WITH_EXCEPT_START", | ||
| "RAISE_VARARGS", | ||
| "POP_BLOCK", | ||
| ): | ||
| return self.op_exceptions | ||
|
|
||
| return self.op_other | ||
|
|
||
|
|
||
| @dataclass(frozen=True, kw_only=True) | ||
| class LiveProfiler(ThemeSection): | ||
| """Theme section for the live profiling TUI (Tachyon profiler). | ||
|
|
@@ -357,6 +439,7 @@ class Theme: | |
| syntax: Syntax = field(default_factory=Syntax) | ||
| traceback: Traceback = field(default_factory=Traceback) | ||
| unittest: Unittest = field(default_factory=Unittest) | ||
| dis: Dis = field(default_factory=Dis) | ||
|
|
||
| def copy_with( | ||
| self, | ||
|
|
@@ -397,6 +480,7 @@ def no_colors(cls) -> Self: | |
| syntax=Syntax.no_colors(), | ||
| traceback=Traceback.no_colors(), | ||
| unittest=Unittest.no_colors(), | ||
| dis=Dis.no_colors(), | ||
| ) | ||
|
|
||
|
|
||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add tests for the colouration. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| :func:`dis.dis` supports colored output by default which can also be | ||
| controlled through ``NO_COLOR=1`` environment variable. Contributed by | ||
| Abduaziz Ziyodov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.