bazelbuild / bazelbuild/bazel

feature request: `values` parameter for attr.string_list

Open
#6,638 5 comments 1 reaction 0 assignees View on GitHub
not stale P4 team-Loading-API type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the problem / feature request:

`attr.string()` currently supports a `values` parameter giving the valid values for the attribute. I believe that `attr.string_list()` should have a similar option, to define which values are legal in the given list of strings.

e.g.

```
foo = rule(
impl = _foo_impl,
attrs = {
'my_list': attr.string_list(values=["a", "b", "c"]),
}
)

# in a BUILD file
foo(
my_list = ["d", "a", "b"], # error - d isn't a valid value, but a and b are fine
)
```

### Feature requests: what underlying problem are you trying to solve with this feature?

easier validation of rule inputs. I can hardcode the list of acceptable values into my rule but then it's a little more code and some work to generate a useful error message.

Contributor guide

Open the contributing guide

Research direction

The issue names the attr.string and attr.string_list entry points but no source files or tests. Locate their implementations and existing validation tests first; done means string_list accepts a values parameter and reports invalid list elements while allowing valid ones.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.