Skip to content

[red-knot] Fixes to Type::to_meta_type#14942

Merged
AlexWaygood merged 1 commit intomainfrom
alex/any-meta-type
Dec 12, 2024
Merged

[red-knot] Fixes to Type::to_meta_type#14942
AlexWaygood merged 1 commit intomainfrom
alex/any-meta-type

Conversation

@AlexWaygood
Copy link
Member

Summary

If a symbol x has type Any, x.__class__ should still be a dynamic, unknown type. However, that doesn't mean that it has to be Any exactly. We know that for any object x, x.__class__ will be an instance of type; if x has type Any, this still holds true, we just don't know which exact instance of type we have for x.__class__. This can be expressed using the type type[Any].

To implement these semantics, this PR modifies Type::to_meta_type so that the meta-type of Any is type[Any], the meta-type of Unknown is type[Unknown] and the meta-type of Todo is type[Todo].

Test Plan

New mdtests added

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Dec 12, 2024
@github-actions
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

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