Repository: astral-sh/ruff
File: crates/ty_python_semantic/src/types/narrow.rs (Rust)

Code before:
            (BoolOp::And, true) | (BoolOp::Or, false) => {
                let mut aggregation: Option<NarrowingConstraints> = None;
                for sub_constraint in sub_constraints.into_iter().flatten() {
                    if let Some(ref mut some_aggregation) = aggregation {
                        merge_constraints_and(some_aggregation, &sub_constraint, self.db);
                    } else {
                        aggregation = Some(sub_constraint);
                    }
                }
                aggregation
            }
            (BoolOp::Or, true) | (BoolOp::And, false) => {
                let (first, rest) = sub_constraints.split_first_mut()?;
                if let Some(first) = first {
                    for rest_constraint in rest {
                        if let Some(rest_constraint) = rest_constraint {
                            merge_constraints_or(first, rest_constraint, self.db);
                        } else {
                            return None;
                        }
                    }
                }
                first.clone()
            }
        }
    }
}

// Return true if the given type is a `TypedDict`, or if it's a union that includes at least one
// `TypedDict` (even if other types are present).
fn is_typeddict_or_union_with_typeddicts<'db>(db: &'db dyn Db, ty: Type<'db>) -> bool {
    match ty {
        Type::TypedDict(_) => true,
        Type::Union(union) => {
            union
                .elements(db)
                .iter()
                .any(|union_member_ty| match union_member_ty {
                    Type::TypedDict(_) => true,
                    Type::Intersection(intersection) => {
                        intersection
                            .positive(db)
                            .iter()
                            .any(|intersection_member_ty| {
                                matches!(intersection_member_ty, Type::TypedDict(_))
                            })
                    }
                    _ => false,
                })
        }
        _ => false,

Review comment (suggestion):
```suggestion
                    Type::Intersection(intersection) => {
                        intersection.positive(db).iter().any(Type::is_typed_dict)
                    }
```

Code after:
                            merge_constraints_or(first, rest_constraint, self.db);
                        } else {
                            return None;
                        }
                    }
                }
                first.clone()
            }
        }
    }
}

// Return true if the given type is a `TypedDict`, or if it's a union that includes at least one
// `TypedDict` (even if other types are present).
fn is_typeddict_or_union_with_typeddicts<'db>(db: &'db dyn Db, ty: Type<'db>) -> bool {
    match ty {
        Type::TypedDict(_) => true,
        Type::Union(union) => {
            union
                .elements(db)
                .iter()
                .any(|union_member_ty| match union_member_ty {
                    Type::TypedDict(_) => true,
                    Type::Intersection(intersection) => {
                        intersection.positive(db).iter().any(Type::is_typed_dict)
                    }
                    _ => false,
                })
        }
        _ => false,
    }
}

fn is_supported_typeddict_tag_literal(ty: Type) -> bool {
    matches!(
        ty,
        // TODO: We'd like to support `EnumLiteral` also, but we have to be careful with types like
        // `IntEnum` and `StrEnum` that have custom `__eq__` methods.
        Type::StringLiteral(_) | Type::BytesLiteral(_) | Type::IntLiteral(_)
    )
}

// See the comment above the call to this function.
fn all_matching_typeddict_fields_have_literal_types<'db>(
    db: &'db dyn Db,
    ty: Type<'db>,
    field_name: &str,
) -> bool {
    let matching_field_is_literal = |typeddict: &TypedDictType<'db>| {
        // There's no matching field to check if `.get()` returns `None`.
        typeddict