[ty] Filter overloads based on Any / Unknown by dhruvmanila · Pull Request #18607 · astral-sh/ruff (original) (raw)

@dhruvmanila added the ty

Multi-file analysis & type inference

label

Jun 10, 2025

dhruvmanila added a commit that referenced this pull request

Jun 12, 2025

@dhruvmanila

Summary

This is to support #18607.

This PR adds support for generating the top materialization (or upper bound materialization) and the bottom materialization (or lower bound materialization) of a type. This is the most general and the most specific form of the type which is fully static, respectively.

More concretely, T', the top materialization of T, is the type T with all occurrences of dynamic type (Any, Unknown, @Todo) replaced as follows:

(For an invariant position, it should actually be replaced with an existential type, but this is not currently representable in our type system, so we use an unresolved type variable for now instead.)

The bottom materialization is implemented in the same way, except we start out in "contravariant" position.

Test Plan

Add test cases for various types.

Base automatically changed from dhruv/top-materialization to main

June 12, 2025 06:36

@dhruvmanila dhruvmanila changed the title[WIP] [ty] Filter overloads based on Any / Unknown [ty] Filter overloads based on Any / Unknown

Jun 13, 2025

@dhruvmanila

@dhruvmanila

KotlinIsland pushed a commit to KotlinIsland/basedpython that referenced this pull request

May 1, 2026

@dhruvmanila

Summary

This is to support astral-sh/ruff#18607.

This PR adds support for generating the top materialization (or upper bound materialization) and the bottom materialization (or lower bound materialization) of a type. This is the most general and the most specific form of the type which is fully static, respectively.

More concretely, T', the top materialization of T, is the type T with all occurrences of dynamic type (Any, Unknown, @Todo) replaced as follows:

(For an invariant position, it should actually be replaced with an existential type, but this is not currently representable in our type system, so we use an unresolved type variable for now instead.)

The bottom materialization is implemented in the same way, except we start out in "contravariant" position.

Test Plan

Add test cases for various types.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})