Skip to content

Forward class keyword arguments in mypyc - #21962

Open
MarthalaJagruthiReddy wants to merge 4 commits into
python:masterfrom
MarthalaJagruthiReddy:fix/mypyc-class-keyword-forwarding
Open

Forward class keyword arguments in mypyc#21962
MarthalaJagruthiReddy wants to merge 4 commits into
python:masterfrom
MarthalaJagruthiReddy:fix/mypyc-class-keyword-forwarding

Conversation

@MarthalaJagruthiReddy

Copy link
Copy Markdown

Fixes #21938

Class-definition keyword arguments were preserved in mypy's AST but silently dropped by mypyc. This change forwards them through the native and non-native class-generation paths.

Specifically:

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