Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Forward class keyword arguments in mypyc - #1

Merged
MarthalaJagruthiReddy merged 4 commits into
masterfrom
fix/mypyc-class-keyword-forwarding
Sep 9, 2026
Merged

Forward class keyword arguments in mypyc#1
MarthalaJagruthiReddy merged 4 commits into
masterfrom
fix/mypyc-class-keyword-forwarding

Conversation

@MarthalaJagruthiReddy

Copy link
Copy Markdown
Owner

Fixes python#21938

Class-definition keyword arguments were preserved in mypy's AST but silently dropped by mypyc. This change:

  • forwards keywords to init_subclass for native extension classes
  • forwards keywords to the metaclass constructor for non-native classes
  • excludes metaclass= because Python consumes it for metaclass selection
  • evaluates keyword expressions before prepare and the class body

Tests:

  • added native and non-native runtime regression coverage
  • updated IR expectations for the expanded runtime operation
  • mypyc class runtime suite: 125 passed
  • mypyc class IR suite: 64 passed
  • mypyc self-check: passed
  • pre-commit hooks: passed

I used an AI coding assistant to help investigate the issue and draft the implementation; I reviewed the resulting code and test behavior locally.

Fixes python#21938 by forwarding class-definition keywords to __init_subclass__ for native classes and to the metaclass for non-native classes. Adds regression coverage for both compiler paths.
Update the runtime declaration and C implementation so native classes can forward keyword arguments to __init_subclass__.
Expose the kwargs dictionary as an argument to the native __init_subclass__ operation.
Cover native and non-native class keyword forwarding and update the corresponding IR expectations.
@MarthalaJagruthiReddy
MarthalaJagruthiReddy merged commit 7743f5c into master Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mypyc silently drops class keyword arguments

1 participant