Skip to content

gh-149026: Add colour to pickletools CLI output#149027

Open
hugovk wants to merge 1 commit intopython:mainfrom
hugovk:3.15-pickletools-colour
Open

gh-149026: Add colour to pickletools CLI output#149027
hugovk wants to merge 1 commit intopython:mainfrom
hugovk:3.15-pickletools-colour

Conversation

@hugovk
Copy link
Copy Markdown
Member

@hugovk hugovk commented Apr 26, 2026

Create a pickle file, for example:

import pickle

data = {
    "a": [1, 2.0, 3 + 4j],
    "b": ("character string", b"byte string"),
    "c": {None, True, False},
}

with open("data.pickle", "wb") as f:
    pickle.dump(data, f, protocol=5)

Then ./python.exe -m pickletools data.pickle:

image

📚 Documentation preview 📚: https://cpython-previews--149027.org.readthedocs.build/

@hugovk hugovk requested a review from AA-Turner as a code owner April 26, 2026 20:06
@hugovk hugovk added the stdlib Standard Library Python modules in the Lib/ directory label Apr 26, 2026
@hugovk
Copy link
Copy Markdown
Member Author

hugovk commented Apr 26, 2026

Aside: the alignment is the same in main without colour, and the code says:

            # make a mild effort to align arguments
            ...
            # make a mild effort to align annotations
            ...

If someone's up for making a bit less mild effort in another PR, go for it!

@picnixz
Copy link
Copy Markdown
Member

picnixz commented Apr 27, 2026

Can we have the instruction names in white (no color)? I find it less readable with colors as all instructions have the same color.

@hugovk
Copy link
Copy Markdown
Member Author

hugovk commented Apr 27, 2026

Like this?

image

Or I think bold cyan is better?

image

@picnixz
Copy link
Copy Markdown
Member

picnixz commented Apr 27, 2026

IMO, too many colors hurt more than they help. White is not that good either actually... I do like the colors for literals and the first column but I feel that colors for instruction names are always too much because it's just adding colors to words that will anyway be classified identically.

Alternatively, how about some "dead" words such as MARK/NONE etc and add categorize the opcodes themselves into colorized categories. This could help a bit more visually (e.g., I want to locate all MARK, whether I use colors or not now I won't be able to find it easily without a CTRL+F).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review stdlib Standard Library Python modules in the Lib/ directory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants