Repository navigation
gh-77371: Clarify that types.new_class() kwds are class keywords - #161890
aribaskagan wants to merge 1 commit into
Conversation
kwds corresponds to keywords in the class statement, such as metaclass, rather than the namespace dictionary accepted by type(). The class body is filled in by exec_body. Note the same distinction on prepare_class(). Co-authored-by: Kağan Arıbaş <aribaskagan@gmail.com>
|
The following commit authors need to sign the Contributor License Agreement: |
|
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 |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: adf39919c7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| class Test(A, B, metaclass=Meta, foo=42): | ||
| pass | ||
|
|
||
| To populate the namespace, pass *exec_body*, a callable that takes |
There was a problem hiding this comment.
Describe exec_body's argument as a namespace mapping
With a metaclass whose __prepare__ returns a valid non-dict mapping, prepare_class() returns that object and new_class() passes it to exec_body; a mapping need not implement dictionary methods such as .update(), so calling it a “dictionary” can mislead callbacks that use dict-only methods, and the example immediately below uses .update(). Please use “prepared namespace” or “mapping,” as Doc/library/types.rst does.
AGENTS.md reference: AGENTS.md:L14-L14
Useful? React with 👍 / 👎.
Fixes #77371.
help(types.new_class)only said "Create a class object dynamically using the appropriate metaclass." Callers coming fromtype(name, bases, dict)were treatingkwdsas that namespace. As discussed on the issue,kwdsis the keywords of the class statement, and the body is filled in byexec_body.Doc/library/types.rstalready says this, so it is unchanged.prepare_class()gets the same one-sentence note.Before:
After:
AI assistance was used in preparing this change; I reviewed and tested it.