question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`attr.string_list_dict` doesn't resolve `select()` calls to values before type checking.

See original GitHub issue

Given 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:closed
  • Created 6 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jmillikin-stripecommented, Oct 16, 2017

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-case select() when used as a key or value of those containers? For example, string_list_dict attrs must be of type Dict<String, List String>> so there’s only so many ways a select could get in there.

0reactions
gregestrencommented, May 11, 2020

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!).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found