`attr.string_list_dict` doesn't resolve `select()` calls to values before type checking.
See original GitHub issueGiven a rule with an attribute defined by attr.string_list_dict()
, I’d expect the following two stanzas to be equivalent:
foo(my_attr = {"hello": ["world"]})
foo(
my_attr = {"hello": select({
"//conditions:default": ["world"],
})},
)
However, Bazel rejects the second with a type error:
expected value of type 'list(string)' for dict value element, but got select({"//conditions:default": []}) (select)
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
jQuery Cannot set "selected"="selected" via attr() on <option ...
reset() is called (or a type="reset" button is clicked) on the form. The current selectedness state can be accessed using the DOM property ......
Read more >Building Linux System Appliances with KIWI Next Generation ...
The image creation process with KIWI NG is automated and does not require any user ... #!/bin/bash # called by dracut check() {...
Read more >Using Select by Attributes for large list of values in ArcPy
The issue is the field in my feature class's data type is text. I've converted meter_list to have string values but the issue...
Read more >Starlark in Go: Language definition
Application-defined types determine their own truth value. Any value may be explicitly converted to a Boolean using the built-in bool function.
Read more >Actions — StackStorm 3.8.0 documentation
Prior to 3.6 release this API was only de-registering actions from database. ... The return value from the action run() method is either...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The workaround is to copy-paste the non-selected part of the dict into multiple select cases. It’s not pretty, but is tolerable at our config sizes.
Given that the
attr
module has a fixed set of allowed container types, is it practical to special-caseselect()
when used as a key or value of those containers? For example,string_list_dict
attrs must be of typeDict<String, List String>>
so there’s only so many ways a select could get in there.I think the most practical solution remains https://github.com/bazelbuild/bazel-skylib/blob/master/lib/selects.bzl, since it doesn’t deeply mess with Starlark’s type system.
Also see https://docs.bazel.build/versions/master/configurable-attributes.html#or-chaining and the following section.
Going forward, I suggest criteria for opening new bugs includes demonstrating how the skylib approach is insufficient and really evaluating what kind of organization with existing mechanisms is possible before considering enhancements. We really want to lean away from direct support for syntax like described here, even though I get the intuition from the user side (enough that I even prototyped it!).