mirror of https://github.com/astral-sh/ruff
parent
7bdce29a8f
commit
99655b54c3
|
|
@ -1796,7 +1796,8 @@ impl<'db> TupleSpecBuilder<'db> {
|
||||||
/// To keep things simple, we currently only attempt to preserve the "fixed-length-ness" of
|
/// To keep things simple, we currently only attempt to preserve the "fixed-length-ness" of
|
||||||
/// a tuple spec if both `self` and `other` have the exact same length. For example,
|
/// a tuple spec if both `self` and `other` have the exact same length. For example,
|
||||||
/// if `self` is a tuple-spec builder for `tuple[int, str]` and `other` is a tuple-spec for
|
/// if `self` is a tuple-spec builder for `tuple[int, str]` and `other` is a tuple-spec for
|
||||||
/// `tuple[bytes]`, the result will be a tuple-spec builder for `tuple[(int | str) & bytes, ...]`.
|
/// `tuple[int, str, bytes]`, the result will be a tuple-spec builder for
|
||||||
|
/// `tuple[int & str & bytes, ...]`.
|
||||||
pub(crate) fn intersect(mut self, db: &'db dyn Db, other: &TupleSpec<'db>) -> Self {
|
pub(crate) fn intersect(mut self, db: &'db dyn Db, other: &TupleSpec<'db>) -> Self {
|
||||||
match (&mut self, other) {
|
match (&mut self, other) {
|
||||||
(TupleSpecBuilder::Fixed(our_elements), TupleSpec::Fixed(new_elements))
|
(TupleSpecBuilder::Fixed(our_elements), TupleSpec::Fixed(new_elements))
|
||||||
|
|
@ -1809,13 +1810,10 @@ impl<'db> TupleSpecBuilder<'db> {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
// Each tuple yields the union of its elements when iterated.
|
let intersected = IntersectionType::from_elements(
|
||||||
// The intersection of two iterables yields elements that are
|
db,
|
||||||
// in both, so we intersect their homogeneous element types.
|
self.all_elements().chain(other.all_elements()),
|
||||||
let self_elements = UnionType::from_elements(db, self.all_elements());
|
);
|
||||||
let other_elements = UnionType::from_elements(db, other.all_elements());
|
|
||||||
let intersected =
|
|
||||||
IntersectionType::from_elements(db, [self_elements, other_elements]);
|
|
||||||
TupleSpecBuilder::Variable {
|
TupleSpecBuilder::Variable {
|
||||||
prefix: vec![],
|
prefix: vec![],
|
||||||
variable: intersected,
|
variable: intersected,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue