ruff
d3800844 - [ty] Use correct top type for default declared upper bound (#28325)

Commit
4 days ago
[ty] Use correct top type for default declared upper bound (#28325) There is quite a lot of code that assumes that an unbounded typevar has an implicit upper bound of `object`. But this is only true for regular `TypeVar`s. `ParamSpec`s, for instance, have the top `paramspec_value` callable as their implicit upper bound. This patch adds a new `TypeVarDomain` type (also needed for #28249) that describes what kind of values the typevar takes on in a specialization, and a method that returns the correct top type for each domain. Most callers should use `require_bound_or_constraints` to get the upper bound or constraints of a typevar, without having to worry about whether the upper bound is implicit or declared. It now returns the correct implicit upper bound for the particular kind of typevar. There were many places that were calling `bound_or_constraints`, trying to add a fast-path for `object` where possible. But since this is only valid for plain `TypeVar`s, I've updated most of those callers to just call `require_bound_or_constraints` and not over-think the optimization. (Most of the time there's a recursive call that will return quickly for `object` anyway.)
Author
Parents
Loading