[ty] Filter overloads based on Any / Unknown by dhruvmanila · Pull Request #18607 · astral-sh/ruff (original) (raw)
added the ty
Multi-file analysis & type inference
label
dhruvmanila added a commit that referenced this pull request
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:
- In covariant position, it's replaced with
object - In contravariant position, it's replaced with
Never - In invariant position, it's replaced with an unresolved type variable
(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
dhruvmanila changed the title
[WIP] [ty] Filter overloads based on [ty] Filter overloads based on Any / UnknownAny / Unknown
KotlinIsland pushed a commit to KotlinIsland/basedpython that referenced this pull request
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:
- In covariant position, it's replaced with
object - In contravariant position, it's replaced with
Never - In invariant position, it's replaced with an unresolved type variable
(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 }})