def METHOD_NAME(typ: typing.Type, fields: typing.Set[str]):
    # In Rust, a type will not inherit fields from parent types.
    # This means that we need to omit some ancestor of this type, which
    # would include all fields of the type.
    # We lose a bit of type checking strictness here.
    for parent in typ.__mro__:
        if not hasattr(parent, '_direct_fields'):
            continue
        fields = fields.difference((f.name for f in parent._direct_fields))
        if len(fields) == 0:
            return parent
    raise AssertionError('unreachable')