Skip to content

[red-knot] Use type[Unknown] rather than Unknown as the fallback metaclass for invalid classes#14961

Merged
AlexWaygood merged 1 commit intomainfrom
alex/type-unknown
Dec 13, 2024
Merged

[red-knot] Use type[Unknown] rather than Unknown as the fallback metaclass for invalid classes#14961
AlexWaygood merged 1 commit intomainfrom
alex/type-unknown

Conversation

@AlexWaygood
Copy link
Member

Summary

This PR changes things so that we now infer type[Unknown] rather than Unknown as the fallback metaclass for an invalid class (either one that has a cyclic definition, or one where the metaclasses of the bases conflict). This better reflects the invariant that a class's metaclass must always be an instance of type. It follows the same principles established in #14942.

Test Plan

Assertions in existing mdtests updated. No new mdtests added, since the existing ones are reasonably comprehensive.

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Dec 13, 2024
@AlexWaygood AlexWaygood enabled auto-merge (squash) December 13, 2024 19:48
@AlexWaygood AlexWaygood merged commit 90a5439 into main Dec 13, 2024
@AlexWaygood AlexWaygood deleted the alex/type-unknown branch December 13, 2024 19:48
@github-actions
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

dcreager added a commit that referenced this pull request Dec 13, 2024
* main:
  [red-knot] Use `type[Unknown]` rather than `Unknown` as the fallback metaclass for invalid classes (#14961)
  [red-knot] Make `is_subtype_of` exhaustive (#14924)
  [red-knot] Alphabetize rules (#14960)
  [red-knot] Understand `Annotated` (#14950)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants