[red-knot] remove wrong typevar attribute implementations #14540
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
In #14182 I added "precise" per-TypeVar type inference for attributes of a typevar (
__bound__
,__constraints__
,__default__
). This wasn't motivated so much by the real-world need for this precise inference, as it was by wanting to test the correctness of our internal representation of the typevar, via an mdtest.The implementation I added was unfortunately just wrong. The problem is that our internal representation cares about the bound/constraints/default inferred as a type expression, while the runtime attributes of the
TypeVar
object will return it as a value expression.In the simplest case, this means that for a typevar
[T: A]
, while we might store the bound as the Instance typeA
, the value of the__bound__
attribute should be typed astype[A]
.Beguiled by the simple case, I slapped on a
.to_meta_type()
and called it a day. But this is just wrong in more complex cases; the meta-type is not always the same thing as the "type form" type. For example, the meta-type ofA | B
istype[A] | type[B]
, but the type-form type in this case would be an instance oftypes.UnionType
.In a future world with PEP 747 (
TypeForm
), where we have a typevar with a bound ofA | B
it would be correct for us to infer its__bound__
attribute asTypeForm[A | B]
, offering a nicer solution to this problem.In the meantime, I think we should just follow the lead of other type checkers in falling back to the general typeshed types for these attributes, and I should bite the bullet and write a Rust test instead of an mdtest when I want to test internal representations of types that don't (yet, since we haven't implemented generics) have a visible effect in the type system.
Test Plan
Re-wrote an mdtest as a Rust test.