Skip to content

gh-141510: Use frozendict in the _opcode_metadata - #144910

Merged
vstinner merged 2 commits into
python:mainfrom
vstinner:frozendict_opcode_metadata
Mar 5, 2026
Merged

vstinner merged 2 commits into
python:mainfrom
vstinner:frozendict_opcode_metadata

Conversation

@vstinner

@vstinner vstinner commented Feb 17, 2026 •

Copy link
Copy Markdown
Member

Enhance py_metadata_generator.py to skip duplicates.

Enhance py_metadata_generator.py to skip duplicates.

Co-authored-by: Donghee Na <donghee.na@python.org>

@corona10 corona10 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We need agreement from the maintainer according to the SC recommendation.

@vstinner

Copy link
Copy Markdown
Member Author

We need agreement from the maintainer according to the SC recommendation.

opcode has no maintainer according to https://devguide.python.org/core-team/experts/ and .github/CODEOWNERS.

I think that a review from 1 or 2 core devs should be enough here.

@vstinner

vstinner commented Mar 2, 2026

Copy link
Copy Markdown
Member Author
@Fidget-Spinner

Copy link
Copy Markdown
Member

cc @Fidget-Spinner

Hmm I'm not too sure. Semantically making it frozen dict is correct. However, do people use this in the wild or modify it in-place? I know it's read by PyTorch for example, but I don't know if it's modified.

@vstinner

vstinner commented Mar 3, 2026

Copy link
Copy Markdown
Member Author

I know it's read by PyTorch for example, but I don't know if it's modified.

PyTorch uses the C API, include <internal/pycore_opcode_metadata.h> with NEED_OPCODE_METADATA macro defined: https://github.com/search?q=repo%3Apytorch%2Fpytorch%20_opcode_metadata&type=code

This internal header file declares data as read-only. Example: const struct opcode_metadata _PyOpcode_opcode_metadata[267], notice the const in the type.

However, do people use this in the wild or modify it in-place?

It sounds weird to me to modify _opcode_metadata dictionaries. Why would someone do that? You can easily create your own copy if you really need changes.

@corona10

corona10 commented Mar 3, 2026 •

Copy link
Copy Markdown
Member

It sounds weird to me to modify _opcode_metadata dictionaries. Why would someone do that? You can easily create your own copy if you really need changes.

I think that we need to sync with Cinder and PyTorch people at core team Discord.

@corona10 corona10 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@vstinner
vstinner merged commit c8aa8de into python:main Mar 5, 2026
54 checks passed
@vstinner
vstinner deleted the frozendict_opcode_metadata branch March 5, 2026 11:33
@vstinner

vstinner commented Mar 5, 2026

Copy link
Copy Markdown
Member Author

Merged, thanks for the review.

ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
Enhance py_metadata_generator.py to skip duplicates.

Co-authored-by: Donghee Na <donghee.na@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants