GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-149026: Add colour to `pickletools` CLI output by hugovk · Pull Request #149027 · python/cpython

Conversation

@hugovk

@hugovk hugovk commented Apr 26, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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
  • Issue: Add colour to pickletools CLI output #149026

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@hugovk
Add colour to pickletools CLI output
799601e
@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
@bedevere-app bedevere-app Bot added the awaiting core review label Apr 26, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Apr 26, 2026
Add colour to pickletools CLI output #149026
Closed
@hugovk

hugovk commented Apr 26, 2026

Copy link
Copy Markdown
Member Author

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!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Apr 27, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk

hugovk commented Apr 27, 2026

Copy link
Copy Markdown
Member Author

Like this?

image

Or I think bold cyan is better?

image
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Apr 27, 2026

Copy link
Copy Markdown
Member

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).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk
Categorise opcodes
35d1088
@hugovk

hugovk commented Apr 27, 2026

Copy link
Copy Markdown
Member Author

Something like this?
image

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Apr 27, 2026

Copy link
Copy Markdown
Member

Much better IMO! I would suggest not having colors for opcodes that have a colored literal (like SHORT_BINUNICODE). WDYT?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk

hugovk commented Apr 27, 2026

Copy link
Copy Markdown
Member Author
image

Or we could stripe it to match the value? But give the mild attempt at alignment, maybe they're a bit too close.

image
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Apr 27, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Or we could stripe it to match the value? But give the mild attempt at alignment, maybe they're a bit too close.

It would require a bit more effort to parse the literal in this case. I think the no-color option is better IMO. FTR, the MARK can be in gray as the PROTO because each MARK is followed by an indent I thnk.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk
MARK in grey
07671f8
@hugovk

hugovk commented Apr 27, 2026

Copy link
Copy Markdown
Member Author

MARK in grey:
image

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Apr 27, 2026

Copy link
Copy Markdown
Member

I like those colors, at least they are more readable to me (and I have very poor eyesight). What about light theme though?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk

hugovk commented Apr 27, 2026

Copy link
Copy Markdown
Member Author
image
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Apr 27, 2026
View reviewed changes

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

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.

I find the colors much readable now! thanks for the work

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/pickletools.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/pickletools.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/pickletools.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

hugovk and others added 3 commits April 27, 2026 14:47
@hugovk @picnixz
Improve readability
9db621e
Co-authored-by: Bénédikt Tran <[email protected]>
@hugovk
Simplify
2d232cd
@hugovk
Fix GH web editor's weird line endings
b720bd0
@hugovk

hugovk commented Apr 29, 2026

Copy link
Copy Markdown
Member Author

@picnixz Any further comments or ready to merge?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Apr 29, 2026
View reviewed changes
Comment thread Lib/pickletools.py Outdated
# Group opcode names into categories for colourised CLI output.
_opcode_categories = frozendict(
op_call=frozenset({
"BUILD", "EXT1", "EXT2", "EXT4", "GLOBAL", "INST", "NEWOBJ",

@picnixz picnixz Apr 29, 2026

Copy link
Copy Markdown
Member

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.

Quick question but can be done in a follow-up:

  • Are those valid for any pickle protocol version?
  • Check that the OP codes are valid using opcodes. It contains all opcodes + their protocol versions. You can use name2i but you need to remove the del name2i above in the file. Or you can build this list closer to name2i (L2200)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@picnixz picnixz Apr 29, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

Alternative: add a "category" to the opcode objects. Thankfully, those objects are not tuples so we can't break things.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@hugovk hugovk Apr 29, 2026

Copy link
Copy Markdown
Member Author

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.

Yes, it covers all protocol versions. Adding a "category" is an interesting idea, but not sure this should be part of the public API. I've gone for the first suggestion.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@picnixz picnixz Apr 29, 2026

Copy link
Copy Markdown
Member

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.

Well, you can always make it a private attribute :) but it's not really important I think. We can revisit this later. It's only a burden when we create the list. But adding new opcodes is usually not common so... it's not really important.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hugovk reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@hugovk
Validate opcodes
5338435
@read-the-docs-community

read-the-docs-community Bot commented Apr 29, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32468999 | 📁 Comparing 5338435 against main (1e7dfbc)

  🔍 Preview build  

5 files changed · ± 5 modified

± Modified

  • contents.html
  • download.html
  • library/pickletools.html
  • whatsnew/3.15.html
  • whatsnew/changelog.html
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz approved these changes Apr 29, 2026
View reviewed changes
@hugovk
hugovk merged commit 8851a06 into python:main Apr 29, 2026
60 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@hugovk
hugovk deleted the 3.15-pickletools-colour branch April 29, 2026 15:33
@bedevere-app bedevere-app Bot removed the awaiting core review label Apr 29, 2026
@hugovk

hugovk commented Apr 29, 2026

Copy link
Copy Markdown
Member Author

Thanks for the review!

picnixz reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@picnixz picnixz picnixz approved these changes
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

stdlib Standard Library Python modules in the Lib/ directory

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@hugovk @picnixz
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.