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

Code before:
                            .iter()
                            .any(|intersection_member_ty| {
                                matches!(intersection_member_ty, Type::TypedDict(_))
                            })
                    }
                    _ => false,
                })
        }
        _ => false,
    }
}

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>| {
        if let Some(field) = typeddict.items(db).get(field_name) {
            matches!(
                field.declared_ty,
                Type::StringLiteral(_) | Type::IntLiteral(_),
            )
        } else {
            true // no matching field to check
        }
    };

    match ty {
        Type::TypedDict(td) => matching_field_is_literal(&td),
        Type::Union(union) => {
            union
                .elements(db)
                .iter()
                .all(|union_member_ty| match union_member_ty {
                    Type::TypedDict(td) => matching_field_is_literal(td),
                    Type::Intersection(intersection) => {
                        intersection
                            .positive(db)
                            .iter()
                            .all(|intersection_member_ty| match intersection_member_ty {
                                Type::TypedDict(td) => matching_field_is_literal(td),
                                _ => true,
                            })
                    }
                    _ => true,
                })
        }
        _ => true,
    }
}

Review comment (suggestion):
```suggestion
        // no matching field to check if the `.get()` call returns `None`
        typeddict.items(db).get(field_name).is_none_or(|field| {
            matches!(
                field.declared_ty,
                Type::StringLiteral(_) | Type::IntLiteral(_),
            )
        })
```

Code after:
// 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
            .items(db)
            .get(field_name)
            .is_none_or(|field| is_supported_typeddict_tag_literal(field.declared_ty))
    };

    match ty {
        Type::TypedDict(td) => matching_field_is_literal(&td),
        Type::Union(union) => {
            union
                .elements(db)
                .iter()
                .all(|union_member_ty| match union_member_ty {
                    Type::TypedDict(td) => matching_field_is_literal(td),
                    Type::Intersection(intersection) => {
                        intersection
                            .positive(db)
                            .iter()
                            .all(|intersection_member_ty| match intersection_member_ty {
                                Type::TypedDict(td) => matching_field_is_literal(td),
                                _ => true,
                            })
                    }
                    _ => true,
                })
        }
        _ => true,
    }
}