mypy
f3e2a977 - [mypyc] Fix `__init_subclass__` running before `ClassVar` instantiations (#20916)

Commit
115 days ago
[mypyc] Fix `__init_subclass__` running before `ClassVar` instantiations (#20916) Fixes https://github.com/mypyc/mypyc/issues/1086 We also ran into this in SQLGlot; To compile our AST we swapped any metaclasses for `__init_subclass__` in which we dynamically set some attributes in it like so: ```Python3 class Expression: arg_types: ClassVar[...] = {} def __init_subclass__(cls, **kwargs: object) -> None: cls.required_args = {k for k, v in cls.arg_types.items() if v} class Select(Expression): arg_types: ClassVar[...] = {...} ``` I introduced the `InitSubclass` primitive to allow for fine-grained control of when this gets called and moved it from `ExtClassBuilder::__init__` (i.e `allocate_class > CPyType_FromTemplate`) to `ExtClassBuilder::finalize`
Author
Parents
Loading