mirror of https://github.com/astral-sh/ruff
don't create T ≤ T constraints
This commit is contained in:
parent
93e71be357
commit
312c4ce5c8
|
|
@ -2715,17 +2715,36 @@ impl<'db> SequentMap<'db> {
|
|||
let left_upper = left_constraint.upper(db);
|
||||
let right_lower = right_constraint.lower(db);
|
||||
let right_upper = right_constraint.upper(db);
|
||||
let new_constraint = |bound_typevar: BoundTypeVarInstance<'db>,
|
||||
right_lower: Type<'db>,
|
||||
right_upper: Type<'db>| {
|
||||
let right_lower = if let Type::TypeVar(other_bound_typevar) = right_lower
|
||||
&& bound_typevar.is_same_typevar_as(db, other_bound_typevar)
|
||||
{
|
||||
Type::Never
|
||||
} else {
|
||||
right_lower
|
||||
};
|
||||
let right_upper = if let Type::TypeVar(other_bound_typevar) = right_upper
|
||||
&& bound_typevar.is_same_typevar_as(db, other_bound_typevar)
|
||||
{
|
||||
Type::object()
|
||||
} else {
|
||||
right_upper
|
||||
};
|
||||
ConstrainedTypeVar::new(db, bound_typevar, right_lower, right_upper)
|
||||
};
|
||||
let post_constraint = match (left_lower, left_upper) {
|
||||
(Type::TypeVar(bound_typevar), Type::TypeVar(other_bound_typevar))
|
||||
if bound_typevar.is_same_typevar_as(db, other_bound_typevar) =>
|
||||
{
|
||||
ConstrainedTypeVar::new(db, bound_typevar, right_lower, right_upper)
|
||||
new_constraint(bound_typevar, right_lower, right_upper)
|
||||
}
|
||||
(Type::TypeVar(bound_typevar), _) => {
|
||||
ConstrainedTypeVar::new(db, bound_typevar, Type::Never, right_upper)
|
||||
new_constraint(bound_typevar, Type::Never, right_upper)
|
||||
}
|
||||
(_, Type::TypeVar(bound_typevar)) => {
|
||||
ConstrainedTypeVar::new(db, bound_typevar, right_lower, Type::object())
|
||||
new_constraint(bound_typevar, right_lower, Type::object())
|
||||
}
|
||||
_ => return,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue