Skip to content

[mypyc] Reject unknown bases for native classes - #22204

Merged
JukkaL merged 7 commits into
masterfrom
mypyc-bulkfix-1200-any-base
Oct 14, 2026
Merged

JukkaL merged 7 commits into
masterfrom
mypyc-bulkfix-1200-any-base

Conversation

@JukkaL

@JukkaL JukkaL commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Fixes mypyc/mypyc#1200.

Reject native classes with an Any base, since their instance layout is
not known during compilation. Suggest using @mypyc_attr(native_class=False)
instead.

Preserve the original base expressions for non-native classes with unknown
bases so Python determines their inheritance and instance layout at runtime.

Fixes mypyc/mypyc#1200.

Reject native classes with an `Any` base, since their instance layout is
not known during compilation. Suggest using `@mypyc_attr(native_class=False)`
instead.

Preserve the original base expressions for non-native classes with unknown
bases so Python determines their inheritance and instance layout at runtime.
Extract the unknown-base check into a helper and include the relevant base
name in the diagnostic. Resolve known type aliases before selecting the
unknown base to report.

Extend the existing runtime and error cases with known and unknown bases in
both orders, two unknown bases, and an alias of a known base. Explicitly
check inherited attributes, methods, and initializers on direct and transitive
subclasses.
The base class handling is shared with other generic non-native classes:
Any bases now use the same path that evaluates base expressions as
written, resolves __mro_entries__ and sets __orig_bases__.

Extend the unknown-base test with Generic[T] in both base orders and
generic metadata checks. Also cover a subscripted compiled generic base
(KnownGeneric[int]) next to an Any base, which used to fail at import with
"type 'KnownGeneric' is not subscriptable".

Also narrow the unknown-base diagnostic guard to expression types that
declare a name.
@JukkaL
JukkaL merged commit efff7e4 into master Oct 14, 2026
19 checks passed
@JukkaL
JukkaL deleted the mypyc-bulkfix-1200-any-base branch October 14, 2026 14:34
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 emits unsafe native layout for subclass of unresolved external base

2 participants